Reverse a linked list using recursion

  Рет қаралды 611,020

mycodeschool

mycodeschool

Күн бұрын

Пікірлер: 332
@bohotsaaridhop
@bohotsaaridhop 3 жыл бұрын
8 years later, still one of the best video to understand this topic.
@sharcodes
@sharcodes Жыл бұрын
you will shock to know the creator of this channel is no more. I must Say he was Gems ans his content made him eternal.
@dragonking1051
@dragonking1051 Жыл бұрын
@@sharcodesthe guy speaking in the video is alive but the other cofounder passed away. Because of that he stopped making these videos but he works at google now
@durjoydc
@durjoydc 8 ай бұрын
@@sharcodes The creator is alive and well. His friend and cofounder died in an unfortunate accident. He stopped making videos after that.
@congdatt
@congdatt 6 ай бұрын
yes sir
@nguaial8490
@nguaial8490 8 жыл бұрын
Brilliant teaching on tough subject. On 6:50, the memory address of the right most node is 150.
@voxflexx
@voxflexx 3 жыл бұрын
i was so confused
@amruthachitluri4419
@amruthachitluri4419 3 жыл бұрын
yes
@kirankasana2208
@kirankasana2208 Жыл бұрын
me too
@nitinmendiratta17
@nitinmendiratta17 10 жыл бұрын
Best videos on Data Structure. I am a masters student and all these videos seriously helped me for interview preparation. Please do post some more videos on Trees and Graphs and bit manipulation. Really appreciate your way of explanation
@yadneshkhode3091
@yadneshkhode3091 3 жыл бұрын
bhai konsi company me ho ab muje lelo apke company me
@redgamer6105
@redgamer6105 2 жыл бұрын
He is no more so can't post.
@Bouryal.Y
@Bouryal.Y Жыл бұрын
@@redgamer6105 thank you!!
@yashtailor1543
@yashtailor1543 5 жыл бұрын
Come back @mycodeschool❤❤😭😭😭😭😭
@vedsinha9905
@vedsinha9905 5 жыл бұрын
He is dead
@yashtailor1543
@yashtailor1543 5 жыл бұрын
@@vedsinha9905 yeah 😭
@DexTech
@DexTech 5 жыл бұрын
he is dead ????
@gauti_
@gauti_ 5 жыл бұрын
@@DexTech Nope, he is working in google, one of other cofounder(humble fool) is dead.
@DexTech
@DexTech 5 жыл бұрын
@@gauti_ humble fool ??
@SachinVerma-dw3mz
@SachinVerma-dw3mz 5 ай бұрын
11 years later , revising this topic from the videos feels nostalgic
@ArhamShahhacker
@ArhamShahhacker 4 жыл бұрын
If anyone thinking that what if head pointer is not global then here's the code struct node* reverse(struct node* ptr){ struct node* head; if(ptr->next==NULL){ head=ptr; return head; } head=reverse(ptr->next); struct node* temp=ptr->next; temp->next=ptr; ptr->next=NULL; return head; }
@rahulkumar0194
@rahulkumar0194 3 жыл бұрын
Thankyou
@prithvigupta8215
@prithvigupta8215 3 жыл бұрын
Thank you
@manfredoweber3562
@manfredoweber3562 3 жыл бұрын
i checked one further on each call, that way you can get rid of temp node Node* reverse_r(Node * root, Node * out=NULL){ if(root->next->next==NULL){ out=root->next; root->next->next=root; } else{ out = reverse_r(root->next); root->next->next=root; root->next=NULL; } return out; }
@mannyw_
@mannyw_ 2 ай бұрын
@@manfredoweber3562 This fails if the size of the LinkedList is 1
@RealMcDudu
@RealMcDudu 8 жыл бұрын
You rock man! I was a little worried because of the accent that I won't be able to understand well, but you explain extremely well and clear. Kudos!
@saidurgasrividyaupadhyayul4675
@saidurgasrividyaupadhyayul4675 Жыл бұрын
Only video that explains how the call stack executes and reverses the links of the list...thanks for the explanation
@shaiksoofi3741
@shaiksoofi3741 3 жыл бұрын
We are missing your content. You are such a good teacher
@muhammednasir4722
@muhammednasir4722 10 жыл бұрын
Hi, the way u are presenting the things really awesome...! I think this is the most easiest way to reverse a list. explanation: In the last recursive call previous will be last element in the list and that will be turned out to first (header). otherwise just change the next pointer to previous element. void List::reverse(Node* current,Node* previous) { if (current == NULL) { m_header = previous; return; } reverse(current->next,current); current->next=previous; }
@madanmohanpachouly6135
@madanmohanpachouly6135 2 жыл бұрын
After watching so many video , got clarity here -- thank you for such a clean explanation.
@KrittinKalra
@KrittinKalra 7 жыл бұрын
I tried solving this on my own before watching the video and this is what I came up with. The solution in the video is correct and mine works too. Some of you may find it useful. From the main(), I called reverse(head, NULL); void reverse(struct node* p, struct node * prev) { if(head==NULL) { return; } if(p->ptr==NULL) { head=p; return; } rev(p->next,p); p->next=prev; }
@wandererstraining
@wandererstraining 2 жыл бұрын
Amazing series of videos so far. I'm very thankful for its quality, and I hope that its author rests in peace. I had already done linked lists, but I had never used recursion on them. Brilliant. In order to better dive into the topics, I usually try to figure out a solution before watching videos or reading solutions in books. In this case, the solution I came up with did not presuppose a global pointer to the first node, so the function I created is fully self-contained: list * list_reverse(list *lst, list *prev) { list *head = NULL; if(lst != NULL) { head = list_reverse(lst->next, lst); lst->next = prev; } else { head = prev; } return head; } It takes two parameters: the first node (lst), and the previous node's pointer (prev), which would be NULL since the first node would not have any node prior to it. It returns a pointer to the new head of the list, the new first node. It creates a pointer named head that will be used to keep track of the first node. It verifies whether the node it received as a parameter is NULL. If it is not NULL, it calls itself recursively using its next element as the first node, and itself as the previous node, and changes the current node's next to the previous one provided as the prev parameter. (That means that the first node's next will become NULL.) If the lst parameter (current node) is null, the head pointer is changed to the previous node's address, or to NULL if it was the only node. After the if statement, the function returns the head pointer. That return of the head pointer is important, as it will be set when the end of the list is reached, and will be preserved as-is across the recursion. Example of usage: mylist = list_append(mylist, data1); mylist = list_append(mylist, data2); mylist = list_reverse(mylist, NULL); When using the function, the *prev parameter should always be NULL. If it is not, the list's last node's next pointer will point to whatever you chose, and the list will not end properly. Example of mistake: mylist = list_reverse(mylist, mylist); //
@smrutiranjanrout974
@smrutiranjanrout974 2 жыл бұрын
I guess u'r a teacher. Well explained.
@lencywork6853
@lencywork6853 2 жыл бұрын
thanks man i searched many videos on this topic but found yours's the best
@JKA-sf7ll
@JKA-sf7ll 3 жыл бұрын
Jenny and this guy...Best teachers to learn coding..
@dhruvilbhuptani727
@dhruvilbhuptani727 4 жыл бұрын
This guy is a legend.
@rajeshroy2404
@rajeshroy2404 5 жыл бұрын
Before watching the video, I tried to do it on my own and I did it. Guys first try it yourself by using your own logic and implementation. Then you will learn better. Here is my approach - // called reverseListUsingRecursion(NULL,head) in main() void reverseListUsingRecursion(Node* prev,Node* current){ if(current==NULL) return; Node *Current = current; Node *Next = current->next; current->next = prev; head = Current; reverseListUsingRecursion(Current,Next); } BTW this guy is the best teacher :).
@koulicksadhu7679
@koulicksadhu7679 5 жыл бұрын
where are we printing brother?
@KadenCasanave
@KadenCasanave 5 ай бұрын
One of the greatest videos on youtube. Cheers.
@selflearner8895
@selflearner8895 3 жыл бұрын
Thank you so much ..... whenever I have a doubt in dsa I comeback to your channel....thank u again💗
@dariom1171
@dariom1171 6 жыл бұрын
Code for C++: #include using namespace std; struct Node { int data; Node* next; }; Node* Insert(Node *head,int data) { Node *temp1 = new Node; temp1 -> data = data; temp1 -> next = nullptr; if (head == nullptr) head = temp1; else { Node *temp2= head; while(temp2 -> next != nullptr) { temp2 = temp2->next; } temp2 -> next = temp1; } return head; }; Node *RevRecursion(Node *head) { Node *temp1 = new Node; Node *temp2 = new Node; if (head->next == nullptr) { return head; } else { temp1 =RevRecursion(head->next); temp2 =head->next; temp2->next = head; head->next = nullptr; } return temp1; }; void Print(Node *p) { // Node *p is a local variable if (p==nullptr) return; //Exit condition cout data next); // Recursive call }; int main(){ Node *head = nullptr; // local variable head = Insert(head,2); // add node at the end of the list head = Insert(head,4); head = Insert(head,6); head = Insert(head,5);// List 2 Print(head); cout
@latchmanakumar7404
@latchmanakumar7404 4 жыл бұрын
is there any way to avoid creating a new node temp1 in each recursive call(excluding global variables) in c/c++?
@sarthakbhatia7639
@sarthakbhatia7639 4 жыл бұрын
@@latchmanakumar7404 We can pass by reference head and it will update the same: #include using namespace std; struct node { int data; node *next; node(int data) { this->data = data; next = NULL; } }; void reverse(node **head, node *cur) { if (!cur || !cur->next) { *head = cur; return; } reverse(head, cur->next); cur->next->next = cur; cur->next = NULL; } void print_ll(node *head) { while (head) { cout data next; } cout next = new node(2); head->next->next = new node(3); head->next->next->next = new node(4); head->next->next->next->next = new node(5); head->next->next->next->next->next = new node(6); head->next->next->next->next->next->next = new node(7); cout
@rohitjoshi6335
@rohitjoshi6335 4 жыл бұрын
Another approcah:: it will return new head pointer from main call :: Node* head = reverse(head, NULL); where pre is the previous node(which at start postioin is null); Node* reverse(Node* head, Node* pre){ Node* newNode; if(head == NULL){ newNode = pre; return pre; } Node* temp = head->next; head->next = pre; return reverse(temp, head); }
@qindynamic
@qindynamic 9 жыл бұрын
your writing on the last is brilliant
@codingandmathvideos
@codingandmathvideos 10 жыл бұрын
Looking forward to when you will do graph algorithms and dynamic programming algorithms: MST, shortest path, LCS, Edit distance, longest common substring, longest palindromic substring, ...
@amateurbeginner7538
@amateurbeginner7538 7 жыл бұрын
yeah man thats is right :)
@parimal7
@parimal7 4 жыл бұрын
still waiting Q.Q
@avgspacelover
@avgspacelover Жыл бұрын
@@parimal7 he passed away few years back
@aiknowledge-n2s
@aiknowledge-n2s Жыл бұрын
Finally understood the mystery behind recursion of linked List Reversal.
@jabedhasan21
@jabedhasan21 2 жыл бұрын
We can reverse a linked list this way also. void reverseLinkedList(struct Node* prev, struct Node* curr) { if ( curr == NULL) { head = prev; return; } reverseLinkedList(curr, curr->next); curr->next = prev; } CALL -> reverseLinkedList(NULL, head); His explanation is really tremendous, No one can't recover your place. hats off humblefool
@mycodeschool
@mycodeschool 11 жыл бұрын
Thanks Jalaj !
@powerfulwords6459
@powerfulwords6459 4 жыл бұрын
🅸'🅼 🅷🅰🅿🅿🆈
@TheKundan11
@TheKundan11 11 жыл бұрын
Amazing explanation of Reversing Linked List using recursion. Such a nice use of algo. It was like watching TV inside TV inside TV and then coming out of it. Kudos to mycodeschool. Hats off ! Please answer a question of how Stack vs Heap works in Java which pure object oriented and donot uses pointers. Hoping to get your reply soon and eagerly waiting for more such videos.
@aseembaranwal
@aseembaranwal 4 жыл бұрын
He could't reply back :(
@kahaanparikh1013
@kahaanparikh1013 11 ай бұрын
@@aseembaranwal zamn
@MadaraUchiha-c7q
@MadaraUchiha-c7q Жыл бұрын
amazing and flawless explanation
@AmitYadav-og7ep
@AmitYadav-og7ep 2 жыл бұрын
Thank you brother for this simple explanation
@Kartik-yv4cw
@Kartik-yv4cw 8 жыл бұрын
At 6:45, the next of the 4th link should be set to 150, not 100. Minor correction. Otherwise, great video. :)
@gurdyalsingh8228
@gurdyalsingh8228 8 жыл бұрын
Kartik Singh yes..it is 150.
@jayant9151
@jayant9151 6 жыл бұрын
Typo**
@pratikjha2742
@pratikjha2742 3 жыл бұрын
hope u reach 1 million soon
@UECDishaKhattri
@UECDishaKhattri 4 жыл бұрын
No existing explanations are better than yours. It would be great and really helpful if you consider YouTubing a part-time again.
@muntahaislam1332
@muntahaislam1332 5 жыл бұрын
Cool one! Thank you! Saved a lot lines!
@kayveekhatrao2486
@kayveekhatrao2486 5 жыл бұрын
Kuchh log chale jaate hain par aisi chhap chhor jaate hain ki maano aisa lagta hai jaise vo abhi bhi hamaarre biich hain. Stilll guiding me through your video lectures . _/\_ RIP
@bhavananarayan8127
@bhavananarayan8127 10 жыл бұрын
One of the best videos on Data Structures! :)
@ShravaniBhujbal-c7k
@ShravaniBhujbal-c7k 8 ай бұрын
one decade later, thanks for the help
@kmlx19
@kmlx19 4 ай бұрын
My god, this was so insightful haha. Thanks for the explanation
@HeyMr.OO7
@HeyMr.OO7 Жыл бұрын
Legends Never Die ! 💙
@rohithkumarmiryala2083
@rohithkumarmiryala2083 6 жыл бұрын
if head is not global variable, try this void Reverse(ListNode** A, ListNode* p){ if(p->next == NULL){ *A = p; return; } Reverse(A,p->next); p->next->next =p; p->next=NULL; } main(){ if(A==NULL) return A; Reverse(&A,A); return A; }
@jmanaa9969
@jmanaa9969 5 жыл бұрын
You are a god mate, I was having a headache with the pointers but this worked perfectly.
@suyashsrivastava3671
@suyashsrivastava3671 4 жыл бұрын
Well explained sir , recursion is sort of complicated.
@RohitKumar-eo9td
@RohitKumar-eo9td 4 жыл бұрын
You are an amazing teacher!! Hats Off!!
@hardstuck170
@hardstuck170 8 жыл бұрын
smartest thing i have ever seen
@sanskarkumar028
@sanskarkumar028 2 жыл бұрын
very clear explaination thanku so much sir
@CargoPantsDude
@CargoPantsDude 6 жыл бұрын
Your tutorial has helped me a lot, thanks
@ajinkyakale4391
@ajinkyakale4391 Жыл бұрын
Great explanation!
@annie157
@annie157 4 жыл бұрын
You are a life saver Thank you so much for your this tutorials
@bassammansour1361
@bassammansour1361 4 жыл бұрын
if you want to return the pointer Node, and use a local head struct Node* reverse (struct Node* p ){ static struct Node* head ; if( p->next==NULL ){ head = p ; return head ; } reverse ( p->next ); struct Node* Q = p->next; Q->next = p ; p->next = NULL ; return head ; }
@shahirabdullah5438
@shahirabdullah5438 6 жыл бұрын
i wrote this way.......my function returns a node pointer and in main function the head is then assigned to the last node. like this ---- head = reverse_list_recursively(head); /*function code*/ node* reverse_list_recursively(node *cur) { if(cur->next == NULL) { return cur; } else { reverse_list_recursively(cur->next)->next = cur; return cur; } }
@LunaFlahy
@LunaFlahy Жыл бұрын
awesome explanation!!!
@iamsksuthar
@iamsksuthar 11 жыл бұрын
These videos are the best! :) Even a kid would come to know about DS! :)
@kushagragupta8460
@kushagragupta8460 4 жыл бұрын
would love to see mycodeschool do the data structures videos again and in cpp or python!
@hoerbschmidt618
@hoerbschmidt618 3 жыл бұрын
great explanation how recursion works thanks to your drawing of the stack. Thank you very much!
@kyledrewes6552
@kyledrewes6552 4 жыл бұрын
This is a very clever trick. Thank you so much.
@mycodeschool
@mycodeschool 11 жыл бұрын
Thanks a lot Kundan, I have replied to your comment on other video.the idea of stack and heap as design concept for execution of programs is same in java also. We do not have pointer variables, but references pretty much work the same way. Its just that language does not give you freedom to see address in a reference variable and increment or decrement it which anyway is dangerous. The heap is totally managed in java. So, you do not have to bother up freeing up memory on heap.
@arijitssongs7914
@arijitssongs7914 7 жыл бұрын
mycodeschool plz make new videos...your videos are awsome nd it helps a lot
@rishabhhedaoo9926
@rishabhhedaoo9926 2 жыл бұрын
Yet again, Amazing !!
@jimwang4582
@jimwang4582 10 жыл бұрын
Good tutorial,but i can not unstandard why p is 150 and q is 250?when recursion is finished,why p is not equal to 250?
@rathnakaraum
@rathnakaraum 9 жыл бұрын
Python Ruby When exit condition is hit, recursive call Reverse(250) returns and entry of that call will be removed from stack. So, when the actual pointer adjustment starts the top record on stack is for Reverse(150) and hence p was 150
@vishalhasija5910
@vishalhasija5910 7 жыл бұрын
Thanks alott!
@himanshuverma903
@himanshuverma903 7 жыл бұрын
p will be equal to 250 only if (p == NULL) because in this condition the last value will be passed to reverse function will be NULL due to which p=250 will be secured, instead of if(p->next == NULL) where the last value in reverse function is 250 due to which p=250 will not be secured and we get p=150. This all happens because the last call of the reverse function will return first in the if statement.
@thestarinthesky_
@thestarinthesky_ 4 жыл бұрын
Great tutorial. Thank you. @6:46 it SHOULD be 150.
@discoverybyr3605
@discoverybyr3605 4 жыл бұрын
But there is mistake, when first second recursion(150) geting to be finished. There the value should be q=150 and p=0.
@asmereg
@asmereg 4 жыл бұрын
best of all time
@Bigini_
@Bigini_ 6 жыл бұрын
great explanation, keep up the good work
@sidddddddoo7
@sidddddddoo7 5 жыл бұрын
Actually we can achieve the same using fewer variables ( though at the cost of code readability ): struct node* reverse_ll_recursive(struct node *head){ if(head->next==NULL) return head; Node *q=reverse_ll_recursive(head->next); head->next->next=head; head->next=NULL; return q; // q stores value of the new head. }
@alamgirhossien4004
@alamgirhossien4004 2 жыл бұрын
I love this tutorial
@prekshakoirala7379
@prekshakoirala7379 9 жыл бұрын
This is awesome. But I think head moves everytime p->next == NULL holds true, which is kinda not what we want. Mycodeschool is my favorite though. superlike.
@sergeyrar
@sergeyrar 7 жыл бұрын
It doesn't move, since p->next= NULL is set after we return from the function call
@pradeepramola2295
@pradeepramola2295 4 жыл бұрын
Please god come back !!!! Can't believe what you taught exist lol seems impossible better than anything!!!!!
@SanjayThakurMnit
@SanjayThakurMnit 11 жыл бұрын
Thank you for this wonderful lesson
@PiyushSingh-bi9kn
@PiyushSingh-bi9kn 2 жыл бұрын
void reverse(Node* current, Node* prev) { if (current->next == NULL) list = current; else reverse(current->next, current); current->next = prev; } call reverse(head, NULL) I dunno know, it just looks cleaner
@adityaojha2701
@adityaojha2701 4 жыл бұрын
You are amazing.
@kautukraj
@kautukraj 4 жыл бұрын
Very helpful!
@raghureddy3237
@raghureddy3237 8 жыл бұрын
Another solution :: LNode* ReverseList1(LNode* head) { if (head == NULL) return NULL; if (head->next == NULL) { h = head; return head; } ReverseList1(head->next)->next = head; return head; } ReverseList1(head)->next=NULL;
@cheems08213
@cheems08213 4 жыл бұрын
Thank you Animesh!
@shreyasshettigar5395
@shreyasshettigar5395 3 жыл бұрын
Superb thank u
@mycodeschool
@mycodeschool 11 жыл бұрын
contd.. I will try to get some video for Java also. :)
@SatyendraJaiswalsattu
@SatyendraJaiswalsattu 4 жыл бұрын
kzbin.info/www/bejne/a2a4nYywo5ifaac
@purubhatnagar483
@purubhatnagar483 5 жыл бұрын
great video sir
@SHUBHAMGI
@SHUBHAMGI 7 жыл бұрын
Node* Reverse(Node *head) { if(head == NULL) return head; if(head -> next == NULL) return head; Node * hs = Reverse(head -> next); head -> next -> next = head; head -> next = NULL; return hs; }
@amateurbeginner7538
@amateurbeginner7538 7 жыл бұрын
is not working?
@luciferplays9040
@luciferplays9040 7 жыл бұрын
It will work great
@damilareoyebanji2834
@damilareoyebanji2834 4 жыл бұрын
Great. Please at what point does hs gets affected
@jalajkhajotiaiitr
@jalajkhajotiaiitr 11 жыл бұрын
Magnificent work. Thanks a lot for this :)
@Hreeshikesh
@Hreeshikesh 6 жыл бұрын
You guys should upload the exact C/C++ code for better understanding I guess.
@vedsinha9905
@vedsinha9905 5 жыл бұрын
He is dead brother
@koulicksadhu7679
@koulicksadhu7679 5 жыл бұрын
@@vedsinha9905 wtf? How and when
@SatyendraJaiswalsattu
@SatyendraJaiswalsattu 4 жыл бұрын
kzbin.info/www/bejne/a2a4nYywo5ifaac
@manishtripathy1549
@manishtripathy1549 8 жыл бұрын
Thanks... nice one. Made it simple.
@Karthik-yy6up
@Karthik-yy6up 3 жыл бұрын
Wow, very succinct. Thank you so much!
@atharvakulkarni3007
@atharvakulkarni3007 5 жыл бұрын
very informative video thanks
@harshadsindhav
@harshadsindhav 11 жыл бұрын
awesome explanation....thank you.
@fjkldhakljf
@fjkldhakljf 2 жыл бұрын
using double pointers without a global head : void ReverseRec(Node **ptrhead) { if ((*ptrhead)->next == NULL) { return; } Node *temp = *ptrhead; *ptrhead = (*ptrhead)->next; ReverseRec(ptrhead); temp->next->next = temp; temp->next = NULL; }
@GagandeepSingh-tl7zg
@GagandeepSingh-tl7zg 4 жыл бұрын
Java implementation continues: public void printReverseUsingRecursion(Node head) { if(head.next == null) return; printReverseUsingRecursion(head.next); System.out.println(head.next.data); }
@pkj6962
@pkj6962 3 жыл бұрын
I thought why he inserted the statement p->next = NULL; because I thought we can substitute p->next with the next recursion. But the code was needed for the last node - that was first the head node.
@TheGinger852
@TheGinger852 8 жыл бұрын
very clear, good, thanks man!
@jaspreetsingh-cn2mb
@jaspreetsingh-cn2mb 4 жыл бұрын
you do great man
@zachgosteady
@zachgosteady 10 жыл бұрын
Thank you so much for these videos!
@simonzhai7881
@simonzhai7881 8 жыл бұрын
Thanks man! Good instruction!
@vikashtalanki
@vikashtalanki 6 жыл бұрын
I think we can code as below aswell public void recurReverse() { Node prev = null; Node curr = head; if(head==null || head.next==null) return; rReverse(prev,curr); } private void rReverse(Node prev,Node curr) { if(curr==null) { head = prev; return; } rReverse(curr,curr.next); curr.next=prev; }
@mannambhavani4266
@mannambhavani4266 4 жыл бұрын
Thank you, tq, tq...
@AnonymousCoder7
@AnonymousCoder7 Жыл бұрын
Legends Never Die ! 🤍
@sammokkabasi8957
@sammokkabasi8957 8 жыл бұрын
Recursion uses a stack to store calls, so won't this approach take up O(n) memory? As compared to the iterative approach that only takes O(1) memory
@ulneverno
@ulneverno 8 жыл бұрын
+Sammok Kabasi You're right, but its just in interview to check your level of thinking.
@nguaial8490
@nguaial8490 8 жыл бұрын
Iterative is O(n) since it is going through entire loop.
@constructor365
@constructor365 8 жыл бұрын
He was talking about space complexity.Iterative is O(1) in space complexity
@amateurbeginner7538
@amateurbeginner7538 7 жыл бұрын
what is difference space and memory complexity?
@lastofthestars6481
@lastofthestars6481 6 жыл бұрын
The iterative approach does not take o(1) time.
@ashupipalia6046
@ashupipalia6046 2 жыл бұрын
nice bro..
@satyamlal4461
@satyamlal4461 6 жыл бұрын
i think exit condition from recursion in revprint should be if(p->link==NULL) return;
@VijayRajanna
@VijayRajanna 10 жыл бұрын
An initial check to see if "head" is NULL , is missing.
@mycodeschool
@mycodeschool 10 жыл бұрын
Vijay Rajanna - Good catch Vijay ! Thanks for noticing :)
@abhisheksurwariya
@abhisheksurwariya 9 жыл бұрын
mycodeschool yes...and the address was also incorrect but thats minor
@johndoe-eh2ol
@johndoe-eh2ol 7 жыл бұрын
An error is an error, Abhishek. There are many people, who are just beginning to learn, who might not be smart enough to realise that. So stop acting smart!
@gopikrishnans5815
@gopikrishnans5815 7 жыл бұрын
john doe it's good he pointed out. A beginner may be puzzled.
@riyadshauk2432
@riyadshauk2432 7 жыл бұрын
if (!p) return; // this should be the first statement of the function. If using NULL, can equivalently write "if (p == NULL) return;" This will only be true if the first node, also called the "head" is NULL. Otherwise (if the "head" is not NULL), "if (p->next == NULL)" will always be true before "if (p == NULL)" would ever be true.
@sheezansultan1776
@sheezansultan1776 7 жыл бұрын
lines below reverse(p->next); will never be executed!
@HansNiemann762
@HansNiemann762 4 жыл бұрын
What ?
@SatyendraJaiswalsattu
@SatyendraJaiswalsattu 4 жыл бұрын
kzbin.info/www/bejne/a2a4nYywo5ifaac
@thavs
@thavs 8 жыл бұрын
YAS! YEAH YEI, i really need this
@walddrygonzalez6234
@walddrygonzalez6234 8 жыл бұрын
+Maria Lopez baia baia :v
@aswathyjagadeesh
@aswathyjagadeesh 3 жыл бұрын
Thank You Sir!!!
@BCS_AnkurMishra
@BCS_AnkurMishra 2 жыл бұрын
def reverse_recurse(self, itr): if itr.next == None: self.head = itr return self.reverse_recurse(itr.next) itr.next.next = itr itr.next = None python code
@Manikanta-zu9tm
@Manikanta-zu9tm 4 жыл бұрын
The 4th node address part should be 150(because the previous node address is 150)
@saurabhshrivastava224
@saurabhshrivastava224 8 жыл бұрын
Thanks,really.Gud one...
Reverse a linked list - Iterative method
13:50
mycodeschool
Рет қаралды 778 М.
Reverse a string or linked list using stack.
16:25
mycodeschool
Рет қаралды 386 М.
Wait… Maxim, did you just eat 8 BURGERS?!🍔😳| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 9 МЛН
PIZZA or CHICKEN // Left or Right Challenge
00:18
Hungry FAM
Рет қаралды 15 МЛН
When u fight over the armrest
00:41
Adam W
Рет қаралды 25 МЛН
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
L9. Reverse a LinkedList | Iterative and Recursive
32:42
take U forward
Рет қаралды 158 М.
C_104 Recursion in C | Introduction to Recursion
18:51
Jenny's Lectures CS IT
Рет қаралды 437 М.
Introduction to linked list
17:13
mycodeschool
Рет қаралды 1,6 МЛН
Reverse a Linked List Recursively
4:20
IDeserve
Рет қаралды 116 М.
C Pointers   GATE CSE Exam Question
6:47
Parag Tamhankar
Рет қаралды 53
Reverse Linked List Recursively
10:27
CppNuts
Рет қаралды 4,8 М.
Wait… Maxim, did you just eat 8 BURGERS?!🍔😳| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 9 МЛН