CSC375 Homework6 George Corser 2009-03-04

CSC375 Homework6 George Corser 2009-03-04 - CSC 375...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC 375 Homework 6 George Corser 2009 March 4 4.5 Function to reverse the order of elements in a list: My answer attempts to follow the general style of the member functions in Figure 4.10 (textbook page 100) while using the declarations in Figure 4.7 (page 97). template <class Elem> // reverse order of linked list elements void LList<Elem>::reverse() { // i.e., reverse directions of pointers Link<Elem>* current; // pointer to current element Link<Elem>* oldnext; // pointer to next (before reversal) Link<Elem>* newnext; // pointer to next (after reversal) Link<Elem>* temp; // pointer for switching head/tail if (head->next == NULL) return; // no action if list has 0 or 1 elements current = head; // set pointer to head of list oldnext = head->next; // set pointer for next (before reversal) newnext = NULL; // set pointer for next (after reversal) while (current != NULL) { // loop through list and reverse pointers current->next = newnext; // reverse current next pointer newnext = current;
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

CSC375 Homework6 George Corser 2009-03-04 - CSC 375...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online