Data Str & Algorithm HW Solutions 24

Data Str & Algorithm HW Solutions 24 - tail = curr...

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

View Full Document Right Arrow Icon
24 Chap. 4 Lists, Stacks, and Queues link<Elem>* temp1 = head->next; link<Elem>* temp2 = temp1->next; while (temp2 != NULL) { link<Elem>* temp3 = temp2->next; temp2->next = temp1; temp1 = temp2; temp2 = temp3; } head->next = temp1; } 4.6 (a) The following members are modi f ed. template <class Elem> void LList<Elem>::LList(const int sz) { head = tail = curr = new link; // Create header head->next = head; } template <class Elem> void LList<Elem>::clear() { // Remove Elems while (head->next != NULL) { // Return to free curr = head->next; // (keep header) head->next = curr->next; delete curr;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } tail = curr = head->next = head; // Reinitialize } // Insert Elem at current position template <class Elem> void LList<Elem>::insert(const Elem& item) { assert(curr != NULL); // Must be pointing to Elem curr->next = new link(item, curr->next); if (tail->next != head) tail = tail->next; } template <class Elem> // Put at tail void LList<Elem>::append(const Elem& item) { tail = tail->next = new link(item, head); } // Move curr to next position template <class Elem> void LList<Elem>::next() { curr = curr->next; }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online