Reverse a SLL

Here is my pseudocode:

(You will be given a list head and you will have to return another list head that points to the reversed linked list)

curNode = listHead;previousNode = NULL;

if (!curNode) return curNode;

while (curNode != NULL) {

tmpNode = curNode->next;
curNode->next = previousNode;

previousNode = curNode;

curNode = tmp;

}

return previousNode;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s