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

  Encode and post the picture with a hidden message

Encode and post the picture with a hidden message. That means do not get hung up on one "encoded picture." Try next one. If somebody was not able to decode your message, first make sure at least you can do it.

  Write the sql statements to satisfy the requests

Write the SQL statements to satisfy the requests. Test the statements and show execution results.

  Determining the format of the number to be entered first

Determining the format of the number to be entered first (binary, decimal and hexadecimal). Access to the other two text boxes outside the relevant text box according to the preferred option

  Discuss what it will take to build a web architecture

Discuss what it will take to build a Web architecture, move an existing Website with minimal downtime, and provide a disaster recovery solution to ensure the site is always available.

  Psychological and social characteristics of threat detection

Showing financial troubles by complaining in the work place about bills and asking to borrow money

  Write executive summary about banking industry

Banking industry (Web and data securiyt). You have to write Executive summary, Introduction, Use of data security in banking industry, difeerent types, security framework, conclusin and power point presentation.

  Research one job and company that interests you

Research one job and company that interests you, one that you think might be a good fit for you after graduation.

  How many gas stations are there in the united states

How many gas stations are there in the United States? How many people fly in and out of LaGuardia Airport every day?

  What qualities might jim possess that would make him a

jim watanabe the assistant director of information technology at petries electronics a southern california-based

  Write a valid assignment statement

Thus, both processes are blocked forever, the producer waiting for the mutex to be unlocked and the consumer waiting for a signal from the producer. Is this a resource deadlock or a communication deadlock? Suggest methods for its control.

  What steps can your leadership team take

You all work in or know of people who work in enterprise IT environments Maintaining the enterprise security posture, legal risk, and security is constantly.

  Analyze how does the different type of glass affect security

Analyze how does the different types of glass affect building security and how would you implement the different types of glass into the facility.

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