Draw a picture of the linkedlist after the insertion of one

Assignment Help Computer Engineering
Reference no: EM132188697

Worksheet : Linked List Deque

In this lesson we continue looking at variations on the theme of linked lists, this time including double links and sentinels on both the front and the back of the list. This will be the first of several lessons that will develop a very general purposed linked list abstraction. In this lesson we will emphasize the deque aspects of the list. In the following lesson we will add more operations.

A deque, you recall, allows insertions at both the beginning and the end of the container. The conceptual interface is shown at right. (Recall that the actual functions may differ from the conceptual interface in two ways. First, the names are likely differ to accommodate the C restriction that all functions have unique names. Second, the actual functions will pass the underlying data area as an argument).

Our linkedList data structure will have two major variations from the linked list stack and queue you have examined earlier. First, an integer data field will remember the number of elements (that is, the size) in the container. Second, we will use sentinels at both the front and back of the linked list.

Sentinels ensure the list is never completely empty. They also mean that all instructions can be described as special cases of more general routines. The internal method _addBefore will add a link before the given location. The second routine _removeLink, will remove its argument link. Both of these use the underscore convention to indicate they are internal methods. When a value is removed from a list make sure you free the associated link fields. Use an assertion to check that allocations of new links are successful, and that you do not attempt to remove a value from an empty list. The following instructions will help you understand how to implement these operations.

1. Draw a picture of an initially empty LinkedList, including the two sentinels.

2. Draw a picture of the LinkedList after the insertion of one value.

3. Based on the previous two pictures, can you describe what property characterizes an empty collection?

4. Draw a picture of a LinkedList with three or more values (in addition to the sentinels).

5. Draw a picture after a value has been inserted into the front of the collection. Notice that this is between the front sentinel and the following element. Draw a picture showing an insertion into the back. Notice that this is again between the last element and the ending sentinel. Abstracting from these pictures, what would the function addBefore need to do, where the argument is the link that will follow the location in which the value is inserted.

6. Draw a picture of a linkedList with three or more values, then examine what is needed to remove both the first and the last element. Can you see how both of these operations can be implemented as a call on a common operation, called _removeLink?

7. What is the algorithmic complexity of each of the deque operations?

struct dlink {

TYPE value;

struct dlink * next;

struct dlink * prev;

};

struct linkedList {

int size;

struct dlink * frontSentinel;

struct dlink * backSentinel;

};

/* these functions are written for you */

void LinkedListInit (struct linkedList *q) {

q->frontSentinel = malloc(sizeof(struct dlink));

assert(q->frontSentinel != 0);

q->backSentinel = malloc(sizeof(struct dlink));

assert(q->backSentinel);

q->frontSentinel->next = q->backSentinel;

q->backSentinel->prev = q->frontSentinell;

q->size = 0;

}

void linkedListFree (struct linkedList *q) {

while (q->size > 0)

linkedListRemoveFront(q);

free (q->frontSentinel);

free (q->backSentinel);

q->frontSentinel = q->backSentinel = null;

}

void LinkedListAddFront (struct linkedList *q, TYPE e)

{ _addBefore(q, q->frontSentinel_>next, e); }

void LinkedListAddback (struct linkedList *q, TYPE e)

{ _addBefore(q, q->backSentinel, e); }

void linkedListRemoveFront (struct linkedList *q) {

assert(! linkedListIsEmpty(q));

_removeLink (q, q->frontSentinel->next);

}

void LinkedListRemoveBack (struct linkedList *q) {

assert(! linkedListIsEmpty(q));

_removeLink (q, q->backSentinel->prev);

}

int LinkedListIsEmpty (struct linkedList *q) {

return q->size == 0;

}

/* write addLink and removeLink. Make sure they update the size field correctly */

/* _addBefore places a new link BEFORE the provide link, lnk */

void _addBefore (struct linkedList *q, struct dlink *lnk, TYPE e) {

}

void _removeLink (struct linkedList *q, struct dlink *lnk) {

}

TYPE LinkedListFront (struct linkedList *q) {

}

TYPE LinkedListBack (struct linkedList *q) {

}

Reference no: EM132188697

Questions Cloud

The functionality offered by the rsa and diffie-hellman : Explain what the following are: root certificates, self-signed certificates. Describe how they are used.
Configure and stylize hyperlinks in web pages : This is the second phase of the website project. For this phase you will add a 4th page to your site, and this page must contain a table.
Create a web page using a four-column table : Attributes in the table elements allow for styling without the need for CSS. Table headers appear in bold by default, thus emphasizing the text in these cells.
Draw the gantt charts for these processes under the two : Can you also calculate these three metrics at the completion of all processes: average waiting time, average latency, and the system throughput?
Draw a picture of the linkedlist after the insertion of one : Draw a picture of an initially empty LinkedList, including the two sentinels. Draw a picture of the LinkedList after the insertion of one value.
Create a web page that has a form : Survey forms are a way for visitors to interact with a site. There are many types of input elements that can be used to collect the data from the user.
What is the worst-case asymptotic running time : What is the worst-case asymptotic running time of the method mthd, assuming that the parameter n is a positive integer?
When would you choose to use a binary tree over any other : When would you choose to use a Binary Tree over any other data structure?
What are three different areas where policy would differ : What are three different areas where policy would differ between granting a person access (hiring directly or indirectly) to your IT systems.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Analyze the time and space requirements of your function

Design a function that will insert a new entry into a heap, obtaining a new heap. Analyze the time and space requirements of your function.

  Analyze household income survey data within cincinnati area

Create a project for a census bureau to obtain and analyze household income survey data within the Cincinnati area (including Northern Ky).

  Main differences between selection and switch structure

What do you need to analyze when directing flow of information in each case? Give code examples for if/else structure and switch structure that produce the same result.

  Discuss their main applicability as well as their advantages

Autonomous (intelligent) software agents are used in Artificial Intelligence to solve an increasing number of complex problems.

  Modify the app so that it displays welcome to app inventor

Modify the app so that it displays "Welcome To App Inventor, Username!" (with Username replaced by the name the user enters). Ensure that the message is displayed correctly when no name is entered.

  Descibe the isp tiers and classification and purposes

What is the subnet mask of a prefix of 26? How you obtain that subnet mask? Describe a prefix length and its used to identify networks.

  Determine the minimum number of timeslots required

COMP 9020- Assignment. For this problem in particular determine minimum number of timeslots required. Explain how this can formulated as graph-based problem

  Create a program that asks the user for the number of month

Create a program that asks the user for the number of a month, then creates the array F of (n+1) Fibonacci numbers, and prints the sequence.

  Write a program that will collect data from bluetooth device

Using arduino, write a program that will collect data from Bluetooth devices and store the information in a database.

  Disaster-recovery planning for technical communicators

"Managing in a Post-9/11, Post Katrina World: An Introduction to a Disaster-recovery Planning for Technical Communicators", How the attacks of September 11, 2001 affected Barclay's Capital and Putman Investments

  What processes and properties would you include

Visual Basic.NET allows you to create your own classes. Provide an instance of a useful class you could create. What methods and properties would you include? Show an example of a method declaration for your class.

  Describe the evolution and functions of computer hardware

IT DISCUSSIONS- Describe the evolution and functions of computer hardware, computer architecture, and system and application software.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd