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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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