# Data structures algorithms void int newobj dlistnode

This preview shows pages 5–10. Sign up to view the full content.

Data Structures & Algorithms void DoublyLinkedList::insertLast( int newobj) { DListNode * newNode = new DListNode(newobj, trailer.prev, &trailer); trailer.prev->next = newNode; trailer.prev = newNode; } header trailer newNode c circlecopyrt Teresa Leyk Slide 5 Doubly Linked List

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CPSC 221 Data Structures & Algorithms int DoublyLinkedList::removeFirst() throw (EmptyDLinkedListException) { if (isEmpty()) throw EmptyDLinkedListException("Empty Doubly Linked List"); DListNode * node = header.next; node->next->prev = &header; header.next = node->next; int obj = node->obj; delete node; return obj; } trailer header deleted node c circlecopyrt Teresa Leyk Slide 6 Doubly Linked List
CPSC 221 Data Structures & Algorithms int DoublyLinkedList::removeLast() throw (EmptyDLinkedListException) { if (isEmpty()) throw EmptyDLinkedListException("Empty Doubly Linked List"); DListNode * node = trailer.prev; node->prev->next = &trailer; trailer.prev = node->prev; int obj = node->obj; delete node; return obj; } header deleted node trailer c circlecopyrt Teresa Leyk Slide 7 Doubly Linked List

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CPSC 221 Data Structures & Algorithms It removes the whole list, and sets header and trailer to initial values. DoublyLinkedList::~DoublyLinkedList() { DListNode * prev_node, * node = header.next; while (node != &trailer) { prev_node = node; node = node->next; delete prev_node; } header.next = &trailer; trailer.prev = &header; } c circlecopyrt Teresa Leyk Slide 8 Doubly Linked List
CPSC 221

This preview has intentionally blurred sections. Sign up to view the full version.

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

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern