All we have to do is adjust the pointers in all the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 5 Let's now insert 5. (newnode) All we have to do is adjust the pointers in All the usual three nodes. the Applied Programming Head (curr) 1 2 3 6 0 4 0 5 newnode->prev = curr->prev; curr newnode->next = curr; >next curr if (curr->prev == 0) head = newnode; head newnode else curr->prev->next = newnode; >next newnode curr->prev = newnode; newnode 2 3 1 2 3 4 0 6 0 Let's now delete 2. All we have to do is adjust the pointers in All the usual three nodes. the (curr) 1 (curr) (newnode) Applied Programming Head Head 4 0 6 0 if (curr->prev == 0) head = curr->next; head curr else curr->prev->next = curr->next; >next curr if (curr->next != 0) curr->next->prev = curr->prev; curr delete curr; delete curr Applied Programming W e can create a circularly-linked list where We circularly where the tail of the list is connected to the head via their pointers so that via head->prev = tail; tail->next = head; Applied Programming If we have installed a tail pointer in our class, If tail pointer we would have to keep it updated, much in the same manner as head is. head The decision as to whether a doubly-llinked list is inked required is dependent upon whether the improvement in speed is worth the extra memory required. required. The next improvement involves the excessively The needed code to handle the head (and tail) as special cases. special Applied Programming Except head and tail are updated when nodes Except head and tail are ajacent are added/deleted. ajacent Also when the head or tail node itself is deleted. This works even for one-node lists. The code for additions and deletions would The now have no special code requirements. Applied Programming Note that searches have to check that Note unsuccessful searches terminate when the tail is reached (or the head is reached for the second time). time). Applied Programming W e said earlier that the queue is a list in which We first arrivals are first removals. first Stacks only have two operations. push – add ite...
View Full Document

This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online