Reverse a Linked List - Iterative

preview_player
Показать описание
Problem:
Given a linked list having n nodes. Reverse the list by nodes.

Solution:
Keep 3 pointers – prev (previous node), curr (current node) and nxt (next node).
1: Initialize prev = null, curr = null, nxt = head.
2: Set curr = nxt.
3: Move nxt to next node pointer.
4: Set curr’s next to prev.
5: Set prev to curr
6: Repeat steps 2-5 till next is not null.
7: Set curr as head pointer of the list

Рекомендации по теме
Комментарии
Автор

It is the best video of this topic.
Your way of teaching is very simple and knowledgeable.
Thanks bro!!!

divyamgupta
Автор

Thank you! I 100% understand for the first time!

saiyansrule
Автор

Dear Friends,

If you like our content and would like us to continue making great content for you, please spread the word about IDeserve.
A share/appreciation from you on social network would mean the world to us!


Thanks,
-Team IDeserve.

IDeserve
Автор

Very nice explanation. Can you explain reverse in pair or reverse in k-nodes?

reallifegambits
Автор

Visualization is helpful. But it would be really good if you can explain, why you need three pointers. What initial values to assign. If you can explain these two things, it would be really helpful.

BhargavJhaveri
Автор

Your videos are very helpful. Thank you so much for your time and effort :)

talkpatel
Автор

Visualization is good. But can you make a video of reverse linked list with both data and address of next node. It will more clear to understand

piyushhibare
Автор

Please put the videos creating linked list program explaination

RakeshKumar-enuq
Автор

c ++ function
Node* Reverse(Node *head)
{
Node *prev=NULL;
Node *current=NULL;
Node *nxt=head;
while(nxt!=NULL)
{

current=nxt;
nxt=nxt->next;
current->next=prev;
prev=current;
}
head=current;
return head;
}

rahuljha