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

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024

Комментарии • 144

  • @leepat9226
    @leepat9226 8 лет назад +87

    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?

  • @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

  • @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!

  • @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.

  • @mycodeschool
    @mycodeschool  11 лет назад +9

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

  • @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

  • @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.

  • @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.

  • @salvadorinio
    @salvadorinio 9 лет назад +9

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

  • @mansitiwari4893
    @mansitiwari4893 9 лет назад +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 9 лет назад +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 RUclips, 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
      ruclips.net/video/jc1t0KFsOcs/видео.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.

  • @wassimboussebha2561
    @wassimboussebha2561 3 года назад +1

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

  • @vibinvenu8708
    @vibinvenu8708 4 года назад +1

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

  • @surjyaroy1496
    @surjyaroy1496 4 года назад +1

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

  • @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.

  • @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!

  • @nirmaljeffrey5263
    @nirmaljeffrey5263 3 года назад

    Reverse print using recursion explanation is mindblowing!!!!

  • @souravpati2007
    @souravpati2007 10 лет назад +2

    Very good explanation , clear and coherent !

  • @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;
    }

  • @rakanshadid1168
    @rakanshadid1168 8 лет назад +2

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

  • @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!

  • @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.

  • @RohitRetnakaran
    @RohitRetnakaran 9 лет назад +3

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

  • @HansNiemann762
    @HansNiemann762 5 лет назад +3

    How beautifully explained this video is :--)

  • @ariabanazadeh1016
    @ariabanazadeh1016 5 лет назад +2

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

  • @gigachad6844
    @gigachad6844 4 года назад +4

    6:38 Mind Blown!!!!

  • @harshitsharma3226
    @harshitsharma3226 8 лет назад +1

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

  • @RohitDurvasula
    @RohitDurvasula 9 лет назад +3

    Amazing...reallllly nice! crystal clear explanation

  • @lastofthestars6481
    @lastofthestars6481 6 лет назад +1

    Really crystal clear explanation :)

  • @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

  • @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?

  • @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.

  • @riteshpatil3690
    @riteshpatil3690 9 лет назад +1

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

  • @chilinouillesdepommesdeter819
    @chilinouillesdepommesdeter819 6 лет назад +1

    excellcent diagrams,so kind of you!

  • @taruneshrai1828
    @taruneshrai1828 2 года назад

    amazing explanation....

  • @crisstone9386
    @crisstone9386 2 года назад

    Thank you and may you rest in peace

  • @095_shaniabalkhi9
    @095_shaniabalkhi9 3 года назад

    Great tutorial!

  • @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

  • @onems7281
    @onems7281 7 лет назад

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

  • @dungviet7786
    @dungviet7786 2 года назад +1

    GENIUS

  • @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.

  • @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);
    }

  • @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 ?

  • @shubhamdang4277
    @shubhamdang4277 7 лет назад +1

    which book should I refer after your tutorials.

  • @mikeljonas2256
    @mikeljonas2256 9 лет назад +6

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

  • @devrajgoswami4357
    @devrajgoswami4357 3 года назад +9

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

  • @freesoul2677
    @freesoul2677 9 лет назад +3

    Thank you !!!!

  • @soumyajitnayak970
    @soumyajitnayak970 10 лет назад

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

  • @kavitshah1076
    @kavitshah1076 4 года назад

    Just Beautiful!

  • @ivandrofly
    @ivandrofly 5 месяцев назад

    Thanks :)

  • @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?

  • @ahmadtahir3554
    @ahmadtahir3554 3 года назад +1

    Can Someone please explain how the Insert function works here ?

  • @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);
    }

  • @youyiliu7556
    @youyiliu7556 6 лет назад

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

  • @connections2190
    @connections2190 6 лет назад

    very intuitive.

  • @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 7 лет назад

      same doubt !!

    • @mishaalijaz8350
      @mishaalijaz8350 7 лет назад +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 7 лет назад

      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.

  • @ruthwik8772
    @ruthwik8772 5 лет назад

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

  • @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 7 лет назад

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

    • @vankaur19
      @vankaur19 7 лет назад

      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 7 лет назад

      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.

  • @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.

  • @cychou1845
    @cychou1845 7 лет назад

    Just amazing

  • @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 ?

  • @nikolamarkovic9906
    @nikolamarkovic9906 5 лет назад

    Thank you for all

  • @abcdeereijgfhd3215
    @abcdeereijgfhd3215 2 года назад +1

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

  • @rd-tk6js
    @rd-tk6js 6 лет назад

    Great Thanks lot !

  • @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!

  • @ashishashiq3
    @ashishashiq3 8 лет назад

    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

  • @piduruvenkat8619
    @piduruvenkat8619 4 года назад

    living legend

  • @scxdb9848
    @scxdb9848 4 года назад

    Now I understood the power of recursion

  • @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

  • @ShravanKumar-lq7et
    @ShravanKumar-lq7et 4 года назад

    how does print function passes the value of nest node

  • @usama57926
    @usama57926 6 лет назад

    thank u brother

  • @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.

  • @iamsksuthar
    @iamsksuthar 11 лет назад

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

  • @joshuakoehler6457
    @joshuakoehler6457 4 года назад +1

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

  • @darshanbrahmbhatt932
    @darshanbrahmbhatt932 6 лет назад

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

  • @dhavaldevildave
    @dhavaldevildave 10 лет назад

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

  • @bnssapp
    @bnssapp 10 лет назад

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

  • @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());
    }

  • @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 3 года назад

      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

  • @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 10 лет назад

    THANK BRO

  • @dissonantiacognitiva7438
    @dissonantiacognitiva7438 6 лет назад

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

  • @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

  • @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

  • @lifesmysteriesofficial
    @lifesmysteriesofficial 5 лет назад +1

    12:00

  • @vishaalgunashekar3913
    @vishaalgunashekar3913 8 лет назад +3

    i dont get the reverse print logic someone help

  • @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

  • @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);
    }

  • @ariabanazadeh1016
    @ariabanazadeh1016 5 лет назад

    I mean some doing not only the basics

  • @johnnybatafljeska6368
    @johnnybatafljeska6368 8 лет назад

    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

  • @devilfrost9491
    @devilfrost9491 3 года назад

    Perfect 👌 example of keep it simple and stupid

  • @hewang505
    @hewang505 5 лет назад

    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.

  • @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()+"|");

    }

  • @jagpreetsingh213
    @jagpreetsingh213 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);
    }