Skip to content

Instantly share code, notes, and snippets.

@RSquaredSoftware
Created September 10, 2012 01:05
Show Gist options
  • Save RSquaredSoftware/3688255 to your computer and use it in GitHub Desktop.
Save RSquaredSoftware/3688255 to your computer and use it in GitHub Desktop.
template <typename T>
void LinkedList<T>::reverseList() {
ListNode<T> *nodePtr; //to traverse the front
nodePtr = head->next;
ListNode<T> *previous; //to traverse the end
previous = head;
ListNode<T> *temp = nodePtr;
while(temp != NULL) {
std::cout << temp->value << ", ";
nodePtr->next = previous;
temp = temp->next;
}
head = temp;
temp->next = nodePtr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment