{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern