Reverse a linked list
This code shows the logic behind reversing a linked list in C++ using pointers and looping through the current nodes, changing the order in which the elements are linked to eachother.
|
On Tuesday, November 6th 2007 at 11:20 PM By Andrew Pociu (View Profile)
    (Rated 2.8 with 4 votes) |
Contextual Ads
More C++ Resources
Advertisement
NodePtr revList = NULL
NodePtr currNode = currHead;
while(currNode != NULL)
{
// Set the head to the next node
currHead=currHead->next;
// Link currNode to the reversed list
currNode->next=revList;
revList=currNode;
// Move currNode to next node
currNode=currHead;
currHead=revList;
}
|
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|
Rate this code snippet
Current Comments
|
Related Source Code
There is no related code.
Related Tutorials
There are no related tutorials.
C++ Job Search
|