Print elements of a linked list in forward and reverse order using recursion

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ต.ค. 2024

ความคิดเห็น • 144

  • @leepat9226
    @leepat9226 8 ปีที่แล้ว +86

    I just started to appreciate the art of using recursion to reverse something after watching this video! Genius! Thanks for your explanation!

    • @njnikunjjain1
      @njnikunjjain1 8 ปีที่แล้ว +18

      Exactly! Didn't value recursion much before watching this video (cause I wasn't aware how powerful it is). But that ReversePrint method is pure gold! Wow!

    • @ahmed_raaphat
      @ahmed_raaphat ปีที่แล้ว

      Same here

  • @johncage2411
    @johncage2411 9 ปีที่แล้ว +53

    i login my youtube account just to say you the best... i haved for long trouble to understand the link list data structure until you uploaded your terrific videos actually i lost few days at work just to follow your all courses :) thank you

  • @umajha5287
    @umajha5287 6 ปีที่แล้ว +13

    How can you be so good? No one explains things this well. Without your tutorials, I would have never understood data structures. Can you please make one on heap also?

  • @mycodeschool
    @mycodeschool  11 ปีที่แล้ว +9

    Hi Vikas,
    We are using Microsoft Visual Studio Express edition.

  • @Xarlos123
    @Xarlos123 7 ปีที่แล้ว +7

    I would like to say that, hopefully one day in the near future, I will get a job because of the things I learned in your videos. I am still going through your videos so I am eager to learn more. I want to thank you for all you have done. How easily you explain these concepts shows how intelligent you are! Thank you!

  • @changumangu4660
    @changumangu4660 5 ปีที่แล้ว +25

    All those who are not understanding how the printf function is called , this is what i understood
    we are making making recursive calls to rp(node *p) , actually printf statement will be called only after the recursive function is executed(completed) but till the last rp(null) we never reached there because we always have other function before printf , now in rp(null) we return from the function RP(NULL) not RP(250) .
    therefore returning from rp(null) means we have executed rp(250)(becaues rp(null) was called from rp(250)) and therefore now printf(p->data) will be executed.
    now after printf(p-data) means rp(150) executed((becaues rp(250) was called from rp(150)) , rp(150) execution means we can now call the printf(p->data) and so on...
    I hope this helps

    • @stephaniemichelle4604
      @stephaniemichelle4604 5 ปีที่แล้ว +2

      Thank you! This helps a lot. I wasn't understanding for the reverse why recursion calls, and now this makes sense.

    • @feelthereel9135
      @feelthereel9135 4 ปีที่แล้ว +2

      but when the value of head becomes NULL it should return which means it will terminate from the reverse function without execution of any print statement no?

    • @ShravanKumar-lq7et
      @ShravanKumar-lq7et 4 ปีที่แล้ว

      @@changumangu4660 how does prunt function passes the value of next node??

    • @notaweeboo469
      @notaweeboo469 4 ปีที่แล้ว

      Vishal Chandra Podishetty how?

    • @notaweeboo469
      @notaweeboo469 4 ปีที่แล้ว

      Stepha Nie this doesn’t make sense. Can u explain pls

  • @ravitejabolli3049
    @ravitejabolli3049 8 ปีที่แล้ว +2

    Became fan of yourself, the way you are explaining is AWESOME. No words man,
    You are great.
    Thank you for sharing your knowledge here.

  • @mohamedmostafak
    @mohamedmostafak 3 ปีที่แล้ว +2

    your videos are my all time recommended videos to any one wants to understand coding in C, I really appreciate the quality and the effort of your videos.

  • @saswatapatra5919
    @saswatapatra5919 5 ปีที่แล้ว +6

    I really had some issues understanding the lessons at first and had to take the help of books along with your lessons but now this lesson was one piece of a gem

  • @DennisSkillman
    @DennisSkillman 7 ปีที่แล้ว +3

    Thanks! Your explanation of memory addresses and pointers is excellent. I was able to learn from your example and finish my school project. I also now understand what is happening behind the scenes with my code. Excellent work.

  • @wassimboussebha2561
    @wassimboussebha2561 3 ปีที่แล้ว +1

    This is the best example to understand call stacks and how recursion work

  • @salvadorinio
    @salvadorinio 9 ปีที่แล้ว +9

    Thanks, most clear explanation I've seen so far.

  • @plemyk
    @plemyk 9 ปีที่แล้ว +22

    //CODE FOR C++
    #include
    using namespace std;
    struct Node {
    int data;
    Node* next;
    };
    /* void Print(Node* ptrHead) { //Prints the output
    if(ptrHead == NULL)
    return; //Exit condition
    cout next); //Recursive call
    //printf("%d ",p->data); ->For C
    }*/
    void ReversePrint(Node* ptrHead) { //Reverse the output
    if(ptrHead == NULL)
    return; //Exit condition
    ReversePrint(ptrHead->next); //Recursive call
    //printf("%d ",p->data); ->For C
    cout data = data;
    temp->next = NULL;
    if(head == NULL)
    head = temp;
    else {
    Node* temp1 = head;
    while(temp1->next != NULL)
    temp1 = temp1->next;
    temp1->next = temp;
    }
    return head;
    }
    using namespace std;
    int main() {
    Node* head = NULL; //Local variable
    head = Insert(head, 2);
    head = Insert(head, 4);
    head = Insert(head, 6);
    head = Insert(head, 5);
    //Print(head);
    ReversePrint(head);
    return 0;
    }

  • @nirmaljeffrey5263
    @nirmaljeffrey5263 3 ปีที่แล้ว

    Reverse print using recursion explanation is mindblowing!!!!

  • @surjyaroy1496
    @surjyaroy1496 4 ปีที่แล้ว +1

    No one can teach like you....,thank you so much sir.

  • @mansitiwari4893
    @mansitiwari4893 10 ปีที่แล้ว +14

    i see that you created these videos almost a year and a half back. i hope i am not asking for a lot, but it would be amazing if you could do some tutorials on java also. actually java is alot like c++ and yet nothing like it. personally, i like java even more, because i had the pleasure of learning it from an amazing teacher. the way he explained things, it seemed like even 2+2 if difficult than java. and that is exactly how anybody would feel after watching you videos too. i understand creating these videos is alot more difficult than just sit around and watch them. but your efforts have paid so much to so many. even if the tutorials on java never show up, i should thank you for what you have provided us so far. wishing you the best in all the future endeavors.

    • @abdallahmohamed9783
      @abdallahmohamed9783 10 ปีที่แล้ว +1

      i am also interested in learning java do you have any idea from where a would start , i mean if you have a name of a youtube channel or a website ....

    • @manavsaxena5579
      @manavsaxena5579 7 ปีที่แล้ว +1

      I know I am too late but if you guys are looking for the best Java Tutorials on TH-cam, look no further than Daniel Ross or his website JavacJava.com. I have never seen a course (free/paid) as in-depth as his Java series.

    • @sanjeevakaalex
      @sanjeevakaalex 5 ปีที่แล้ว

      For those looking for java implementation, watch this series
      th-cam.com/video/jc1t0KFsOcs/w-d-xo.html
      After watching How to implement LinkedList in Java from there, you will get the gist of it and be able to co-relate, because the only thing that is significantly different is pointers.

  • @mrbam8
    @mrbam8 8 ปีที่แล้ว +31

    Mind blown!!

  • @dangidelta
    @dangidelta 5 ปีที่แล้ว +3

    I would have never thought of a recursive approach to something so seemingly simple and obvious.

  • @vibinvenu8708
    @vibinvenu8708 4 ปีที่แล้ว +1

    best videos ever seen....please make videos on networking,algorithms,database,computer organistion and operating systems

  • @gayathrisarmishtaamara7815
    @gayathrisarmishtaamara7815 9 ปีที่แล้ว +2

    Very clean and beautiful way of explaining the recursion :)

  • @Nick-lf1en
    @Nick-lf1en 4 ปีที่แล้ว +1

    Very clear and detailed explanation. Job well done!

  • @souravpati2007
    @souravpati2007 10 ปีที่แล้ว +2

    Very good explanation , clear and coherent !

  • @gigachad6844
    @gigachad6844 4 ปีที่แล้ว +4

    6:38 Mind Blown!!!!

  • @pawanrk4818
    @pawanrk4818 4 ปีที่แล้ว +1

    Thank you so much !!!
    Now I understood how recursive functions fire in stack !!

  • @Flash-qr5oh
    @Flash-qr5oh 3 ปีที่แล้ว +1

    he is really a LEGEND!

  • @mycodeschool
    @mycodeschool  11 ปีที่แล้ว +1

    HI Kulamani,
    Right now we are trying to complete playlists on data structure and C fundamentals. Anyway, can you please be more specific. What exactly in C#?

    • @Opacity5
      @Opacity5 6 ปีที่แล้ว

      thanks alot sir

    • @anshuldimri3631
      @anshuldimri3631 5 ปีที่แล้ว

      For printing reversed list - where should we put "endl" so that the line changes after the list is printed ?

  • @kulamanisahoo4785
    @kulamanisahoo4785 11 ปีที่แล้ว +2

    hi Sir
    Can we have some sessions on C# as well on some topics.
    I am really enjoying your tutorials and i have a great time in learning the things.
    Thanks
    Kulamani

  • @rakanshadid1168
    @rakanshadid1168 8 ปีที่แล้ว +2

    YOUR VIDEOS ARE WONDERFUL , Thank you very much , you are helping alot by explaining these things , Keeep it up .

  • @RohitRetnakaran
    @RohitRetnakaran 9 ปีที่แล้ว +3

    Sir, you explained the recursion part really well... :D

  • @ariabanazadeh1016
    @ariabanazadeh1016 5 ปีที่แล้ว +2

    I love you man please make more videos about graphs
    and some questions on code forces

    • @abhinavjain1340
      @abhinavjain1340 5 ปีที่แล้ว

      He is no more !

    • @abhinavjain1340
      @abhinavjain1340 5 ปีที่แล้ว

      We will not be able to get more videos of DS from him..

  • @HansNiemann762
    @HansNiemann762 5 ปีที่แล้ว +3

    How beautifully explained this video is :--)

  • @ArcLove
    @ArcLove 9 ปีที่แล้ว +1

    Thank u very much. i am very gratefully for all your videos on data structure. you outworked my lecture 10\10. your work helped me allot.

  • @AkashKumar-kj1ox
    @AkashKumar-kj1ox 4 ปีที่แล้ว +1

    Your way of explanation deserve appreciation. And I know there is involvement of hard work.
    But I have a doubt in this method of reversing a linked list by recursion becz you have just printed it in reversed way. But there is no any linked list in reverse order. Expect that you will reply soon.

  • @technologydig3394
    @technologydig3394 4 ปีที่แล้ว +1

    Hello sir, from few days i'm watching ur videos. They are superb. how did you developed such great skills? Also another thing is, I wanted to get into companies such as amazon, facebook. So what all other things i must do along with these tutorials to achieve my goal?

  • @RohitDurvasula
    @RohitDurvasula 9 ปีที่แล้ว +3

    Amazing...reallllly nice! crystal clear explanation

  • @lastofthestars6481
    @lastofthestars6481 6 ปีที่แล้ว +1

    Really crystal clear explanation :)

  • @harshitsharma3226
    @harshitsharma3226 8 ปีที่แล้ว +1

    thanks for uploading such quality videos of linked list.you are just awesome man..

  • @shubhamdang4277
    @shubhamdang4277 7 ปีที่แล้ว +1

    which book should I refer after your tutorials.

  • @crisstone9386
    @crisstone9386 2 ปีที่แล้ว

    Thank you and may you rest in peace

  • @swarnjeetsingh7705
    @swarnjeetsingh7705 10 ปีที่แล้ว +1

    hello sir.!
    can u please explain the insert function you are using in the video lecture of reversing link list using iterative function and in this video Print elements of a linked list in forward and reverse order using recursion.
    it will be really helpfull

  • @rasmiranjanbabu
    @rasmiranjanbabu 10 ปีที่แล้ว

    Very good explanation... I have a request, can you please make tutorial on recursion in loop. How recursion works in in a for loop. Few days back I was searching a program as string permutation, I found the program in Internet but unable to understand how it works. If you can make a tutorial similar to that where recursion is happening inside a loop. That will be great.

  • @ShortsAutoAi
    @ShortsAutoAi 3 ปีที่แล้ว +1

    Can Someone please explain how the Insert function works here ?

  • @taruneshrai1828
    @taruneshrai1828 3 ปีที่แล้ว

    amazing explanation....

  • @chilinouillesdepommesdeter819
    @chilinouillesdepommesdeter819 6 ปีที่แล้ว +1

    excellcent diagrams,so kind of you!

  • @onems7281
    @onems7281 7 ปีที่แล้ว

    Create some more content please.Even Ready to pay you,You are an amazing Teacher.

  • @vankaur19
    @vankaur19 8 ปีที่แล้ว +2

    Hi!
    Your videos are saving my life.
    But I have a question:
    Why do we initialize head = NULL in the main in the videos? Doesn't globally defining a pointer take care of that? Since it will be in the data memory segment.

    • @itsmanjutube
      @itsmanjutube 8 ปีที่แล้ว

      ikr.

    • @mishaalijaz8350
      @mishaalijaz8350 8 ปีที่แล้ว

      To ensure there isn't any garbage value because we have to later use the head node a lot in functions

    • @vankaur19
      @vankaur19 8 ปีที่แล้ว

      Yeah but any variable (including a pointer) is initialized to NULL if defined globally. There won't be any garbage value associated with it,

    • @mishaalijaz8350
      @mishaalijaz8350 8 ปีที่แล้ว

      Try doing it without initializing it to null, then see how the program works, and let me know as well, because I'm a beginner in coding.

  • @riteshpatil3690
    @riteshpatil3690 9 ปีที่แล้ว +1

    thank you sir,,, very helpful and easier then my method...!

  • @mikeljonas2256
    @mikeljonas2256 9 ปีที่แล้ว +6

    if p == null
    return;
    so why printf statement even execute

  • @095_shaniabalkhi9
    @095_shaniabalkhi9 3 ปีที่แล้ว

    Great tutorial!

  • @ruthwik8772
    @ruthwik8772 5 ปีที่แล้ว

    Instead of passing an argument ,Can we just use a local pointer variable and static variable?

  • @tomsmith9849
    @tomsmith9849 4 ปีที่แล้ว +1

    i dont get the passing head as a copy. If you want to modify it like you stated wouldn't you pass it by reference?

  • @youyiliu7556
    @youyiliu7556 6 ปีที่แล้ว

    Lectures are good. Is there a website to download these example programs?

  • @freesoul2677
    @freesoul2677 9 ปีที่แล้ว +3

    Thank you !!!!

  • @dungviet7786
    @dungviet7786 2 ปีที่แล้ว +1

    GENIUS

  • @go2bose
    @go2bose 8 ปีที่แล้ว +9

    I can't understand how after calling return when p=null the function is calling printf ! should it not pass the execution to main?

    • @dharaneechandra
      @dharaneechandra 8 ปีที่แล้ว

      same doubt !!

    • @mishaalijaz8350
      @mishaalijaz8350 8 ปีที่แล้ว +3

      No, it's all happening on the stack so that can't happen. When the null condition gets true for p->next, function on top of stack gets returned and it will keep happening until all the functions get removed from stack and the control is passed back to main.

    • @dharaneechandra
      @dharaneechandra 8 ปีที่แล้ว

      Goutam Bose we must refer recursion now I got this clear

    • @AmrendraKumar-ko8yf
      @AmrendraKumar-ko8yf 7 ปีที่แล้ว +3

      Each function call to recursive fn creates a copy of that function and stored in stack here stack of memory also implement the concept of stake of data structure and first copy of each fn call stored in stack . now LIFO gets applied, last in first out, . So rec fn data clearing out from stack by printing value at address since last one null to first.

  • @kavitshah1076
    @kavitshah1076 4 ปีที่แล้ว

    Just Beautiful!

  • @monildand4366
    @monildand4366 6 ปีที่แล้ว +1

    I didn't understood the use of return;. As we usually return to main function.Where will it go for next statement execution? And later how printf will be used continuously?

    • @pragatitanwar3
      @pragatitanwar3 6 ปีที่แล้ว

      monil shah I also got stuck on this, can anyone please answer?

    • @dineshvaraprasad
      @dineshvaraprasad 5 ปีที่แล้ว +2

      @@pragatitanwar3 Idea of return function is to return from the current function to where it was called from. in a recursive case, it goes back to previous instance where it was called from. Then executes the next line of code in that function. Hope this helps.

  • @scxdb9848
    @scxdb9848 4 ปีที่แล้ว

    Now I understood the power of recursion

  • @soumyajitnayak970
    @soumyajitnayak970 10 ปีที่แล้ว

    i dn't hv any words to say,otherwise u vl b bored :) great nd also lv ur voice

  • @technologydig3394
    @technologydig3394 4 ปีที่แล้ว

    As you said in this lecture for reverseprint function that after return; printf statment executes. But how multiple times printf will executes? Does not "return" means exit the function ?

  • @connections2190
    @connections2190 6 ปีที่แล้ว

    very intuitive.

  • @devrajgoswami4357
    @devrajgoswami4357 3 ปีที่แล้ว +9

    Me reading all comments from 4-5 yrs back instead of learning what i came for.
    Anyone else like me?

  • @cychou1845
    @cychou1845 7 ปีที่แล้ว

    Just amazing

  • @nikolamarkovic9906
    @nikolamarkovic9906 5 ปีที่แล้ว

    Thank you for all

  • @dragonryderrlast7014
    @dragonryderrlast7014 5 ปีที่แล้ว

    the insert() function could have taken Node** as an argument. pass &p to Insert(). change the value that the Node** p points to, namely Node* p and ur done

  • @thestarinthesky_
    @thestarinthesky_ 4 ปีที่แล้ว

    @7:26 blows my mind!

  • @joshuakoehler6457
    @joshuakoehler6457 4 ปีที่แล้ว +1

    When you are trying to get a good grasp on recursion, I recommend first getting a good grasp on recursion.

  • @ivandrofly
    @ivandrofly 6 หลายเดือนก่อน

    Thanks :)

  • @abcdeereijgfhd3215
    @abcdeereijgfhd3215 2 ปีที่แล้ว +1

    We better create Node* tail pointer that points to the end node of the list.

  • @ashishashiq3
    @ashishashiq3 9 ปีที่แล้ว

    sir in recursion (at 12:58) after exiting how its fall in the same loop.it should go back to previous loop i think ,please explain

  • @tusharchawla1440
    @tusharchawla1440 2 ปีที่แล้ว

    Sir,I have one doubt
    In the program we made head as local pointer in main function and then we are using recursive approach to print elements in list
    But ,if we made head as global pointer then how can we make algorithm for printing the list by recursion
    Can anyone explain it

  • @rd-tk6js
    @rd-tk6js 6 ปีที่แล้ว

    Great Thanks lot !

  • @dhavaldevildave
    @dhavaldevildave 10 ปีที่แล้ว

    which software u r using to capture screen, i m using camstudio,, but can't create video-audio properly

  • @vishaalgunashekar3913
    @vishaalgunashekar3913 8 ปีที่แล้ว +3

    i dont get the reverse print logic someone help

    • @harshsaxena1999it
      @harshsaxena1999it 6 ปีที่แล้ว +1

      u dont get it because it is seriously wrong

  • @darshanbrahmbhatt932
    @darshanbrahmbhatt932 6 ปีที่แล้ว

    Why nodes are placed in heap section of memory? Even though we did not made node using malloc.

  • @piduruvenkat8619
    @piduruvenkat8619 4 ปีที่แล้ว

    living legend

  • @usama57926
    @usama57926 6 ปีที่แล้ว

    thank u brother

  • @accessdenied9393
    @accessdenied9393 3 ปีที่แล้ว

    The Two Functions
    void print(node *traverse)
    {
    if (!traverse)
    return;
    printf("%d
    ", traverse->data);
    print(traverse->ptr);
    }
    void reverse_print(node *traverse)
    {
    if (!traverse)
    return;
    reverse_print(traverse->ptr);

    printf("%d
    ", traverse->data);
    }

  • @iamsksuthar
    @iamsksuthar 11 ปีที่แล้ว

    Hi sir,
    You are awesome! Keep up! :) :)

  • @matitiudeforever8155
    @matitiudeforever8155 6 ปีที่แล้ว +3

    gr8888 video

  • @obliviondew9268
    @obliviondew9268 7 ปีที่แล้ว

    please answer
    is there a difference in
    head= temp1->next ;
    temp1->next=head; ?

    • @AkashKumar-vt9gb
      @AkashKumar-vt9gb 4 ปีที่แล้ว

      in first you are changing the value of head equals to temp1->next. in second youre changing the value of temp1->next equals to head

  • @kalyand7446
    @kalyand7446 8 ปีที่แล้ว

    please explain me ....why head=insert(head,value);.....why you are assigning it to head ??

    • @collinsedward3156
      @collinsedward3156 8 ปีที่แล้ว

      if the head value is modified, it will be updated this way

  • @manishpoudel4540
    @manishpoudel4540 4 ปีที่แล้ว

    now again if someone having problem with that recursive function then let me explain it .
    what happen is that when 'p' reaches NULL then the 'return' is executed so it return to the previous function print(250) then the printf () in that print(250) is executed and still 'p' is NULL in that function too so again 'return' is executed and so it return to print (150) and printf () function in print(150) is executed. 'p' is NULL in print(150) too so it again returns to print(200) and printf in print(200) is executed and so on.

    • @khanhlongtran3558
      @khanhlongtran3558 2 ปีที่แล้ว +1

      thank you very much. your explantion helps me to understand still now. once again thank you.

  • @ShravanKumar-lq7et
    @ShravanKumar-lq7et 4 ปีที่แล้ว

    how does print function passes the value of nest node

  • @dissonantiacognitiva7438
    @dissonantiacognitiva7438 6 ปีที่แล้ว

    Or better if (p->next) Print(p) it avoids an unnecessary jump

  • @bappola657
    @bappola657 7 ปีที่แล้ว

    but insert function takes pointer as parameter , so why would main send the copy of head ? shouldn't it send the adress?

    • @ManjeetKumar-qm1gr
      @ManjeetKumar-qm1gr 7 ปีที่แล้ว

      head contains nothing but the address of first node only. so yeah, that's a pointer

  • @abhimanyuvashisth1248
    @abhimanyuvashisth1248 7 ปีที่แล้ว

    void rev(head)
    {
    struct node* A,B;
    A=head;
    B->next=NULL;
    while(A!=NULL)
    {
    B=A;
    A=A->next;
    A->next=B;
    }
    head=A;
    }
    whats wrong in this code ....can anyone tell me

  • @korboy94
    @korboy94 11 ปีที่แล้ว

    THANK BRO

  • @bnssapp
    @bnssapp 10 ปีที่แล้ว

    what if i put flushall() after printf("%d", p->data)??

  • @lifesmysteriesofficial
    @lifesmysteriesofficial 5 ปีที่แล้ว +1

    12:00

  • @hewang505
    @hewang505 6 ปีที่แล้ว

    in your recursive to print out the ALL, you just used a recursion to recursively to print out the list, you didnt implement an function which traverse on both the array and the lists recursively.

  • @johnnybatafljeska6368
    @johnnybatafljeska6368 9 ปีที่แล้ว

    Cant we just call standart print implementation in main fuction after we call REVERSE()? ... im referencing on previous lesson

    • @11m0
      @11m0 8 ปีที่แล้ว

      +Johnny Batafljeska We could, but this way, you dont have to call the reverse function

  • @ikaros9727
    @ikaros9727 5 ปีที่แล้ว +1

    If anyone has a problem with struct Node* Insert change the code to this:
    #include
    #include
    typedef struct {
    int data;
    struct Node* next;
    } Node;
    void Print(Node* p)
    {
    if(p == NULL) return;
    printf("%d ", p->data);
    Print(p->next);
    }
    Node* Insert(Node* head, int data){
    Node* temp = (Node*)malloc(sizeof(Node));
    temp->data = data;
    temp->next = NULL;
    if(head == NULL) head = temp;
    else {
    Node* temp1 = head;
    while(temp1->next != NULL) temp1 = temp1->next;
    temp1->next = temp;
    }
    return head;
    }
    int main()
    {
    struct Node* head = NULL;
    head = Insert(head,2);
    head = Insert(head,4);
    head = Insert(head,6);
    head = Insert(head,5);
    Print(head);
    }

  • @GagandeepSingh-tl7zg
    @GagandeepSingh-tl7zg 4 ปีที่แล้ว

    Java implementation continues:
    public void printUsingRecursion(Node head) {
    // Has 2 parts
    // 1. End statement
    // 2. Recursive statement.
    // Base Condition / Exit statement.
    if(head.next == null) return;
    System.out.println(head.next.data);
    // Recursive statement.
    printUsingRecursion(head.next);
    }
    Expose head variable using a function:
    public Node getHead() {
    return head;
    }
    How to call this function:
    @Test
    public void printUsingRecursion() {
    LinkedList list = new LinkedList();
    list.add(9);
    list.add(8);
    list.add(7);
    list.add(6);
    list.add(5);
    list.add(4);
    list.add(3);
    list.add(2);
    list.add(1);
    list.add(0);
    list.printUsingRecursion(list.getHead());
    }

  • @amarnathnayak1145
    @amarnathnayak1145 8 ปีที่แล้ว

    if i write insert(head,2), is the function insert() ( see the vedio at 4:34 for the insert() function) inserting the value 2 at the beginning or at the end ?????

    • @adityapratapsingh658
      @adityapratapsingh658 8 ปีที่แล้ว

      +Amarnath Nayak it is inserting the value at the end of the list

  • @Jhempatuta
    @Jhempatuta 7 ปีที่แล้ว

    #include
    #include
    #include
    this code is not running or compile
    at the 36th line it's showing error
    struct Node{
    int data;
    struct Node* next;
    };
    void Print(struct Node* head)
    {
    if(head=NULL){
    printf("%d",head->data);
    Print(head->next);
    }
    struct Node* Insert(struct Node* head , int data){
    struct Node* temp=(struct Node*)malloc(sizeof(struct Node));
    temp->data=data;
    temp->next=NULL;
    if(head ==NULL) head=temp;
    else{
    struct Node* temp1=head;
    while(temp1->next!=NULL) temp1=temp1->next;
    temp1->next=temp;
    }
    return head;
    }
    int main(){
    struct Node* head=NULL;
    head=Insert(head,2);
    head=Insert(head,6);
    head=Insert(head,4);
    head=Insert(head,5);
    head=Insert(head,8);
    Print(head);
    }

  • @ariabanazadeh1016
    @ariabanazadeh1016 5 ปีที่แล้ว

    I mean some doing not only the basics

  • @devilfrost9491
    @devilfrost9491 3 ปีที่แล้ว

    Perfect 👌 example of keep it simple and stupid

  • @jossboloko
    @jossboloko 5 ปีที่แล้ว +1

    #include
    #include
    struct Node {
    int data;
    struct Node* next;
    };
    void Print(struct Node* p) {
    if (p == NULL) return; //exit condition
    Print(p->next); // Recursive call
    printf("%d", p->data); //First print the value in the node
    }
    struct Node* Insert(Node* head, int data) {
    Node* temp = (struct Node*)malloc(sizeof(struct Node));
    temp->data = data;
    temp->next = NULL;
    if (head == NULL) head = temp;
    else {
    Node* temp1 = head;
    while (temp1->next != NULL) temp1 = temp1->next;
    temp1->next = temp;
    }
    return head;
    }
    int main()
    {
    struct Node* head = NULL;
    head = Insert(head, 2);
    head = Insert(head, 4);
    head = Insert(head, 6);
    head = Insert(head, 5);
    Print(head);
    }

  • @omkarkulkarni3207
    @omkarkulkarni3207 5 ปีที่แล้ว

    JAVA CODE
    public void printReverseRecusrive(Node head) {
    //Forward Order: Print the item in the beginning of the call
    //System.out.print(head.getValue()+"|");
    if(head.getNext()!=null) {
    printReverseRecusrive(head.getNext());
    }
    System.out.print(head.getValue()+"|");

    }