Single Linked List (Inserting a Node at the Beginning)

Sdílet
Vložit
  • čas přidán 7. 09. 2024

Komentáře • 154

  • @souravmukherjee7508
    @souravmukherjee7508 Před 4 lety +226

    Teaching is an art & you are the picasso of it.

  • @letsgethealthytogether1257
    @letsgethealthytogether1257 Před 4 lety +84

    Neso Academy is a blessing to all CS students. Shine on! How can you make your videos so brief yet so elaborate. Passed two of sems watching you guys. Looking forward to excel in my academics and crack a Top Tech company interview on the basis of the knowledge provided by you. Lots and lots of love from Assam. Thank you if this could suffice anyway. 💛💛💛💛💙💙💙💙💙💙💙💙💙💜💜💜💜💜💜💜🖤🖤🖤🖤🖤🖤🖤🖤

    • @subhamroy5368
      @subhamroy5368 Před 3 lety +2

      Hey, I'm from Assam too, you're in which college?

    • @-error102
      @-error102 Před 2 lety

      So, true!!

    • @ummesidra8403
      @ummesidra8403 Před 9 měsíci

      this channel is made for electrical and electronics

  • @kritagyaprasad7230
    @kritagyaprasad7230 Před 3 lety +29

    The way of teaching is so awesome....just like a pro.

  • @harsh1027
    @harsh1027 Před rokem +11

    Been trying to understand this logic from past one month, n i understood clearly in 5 mins after watching this video, really appreciated! Thank you soo much!

  • @awakeningcore9452
    @awakeningcore9452 Před 2 lety +7

    I felt Sparks Of Knowledge in under a minute of watching this video, LEGENDARY MYTHICAL Channel

  • @anusmitsaha8604
    @anusmitsaha8604 Před 4 lety +17

    Sir please increase the frequency of videos. Data Structures and Algorithms are the most important topics in Gate and campus placements. Your teaching is just too awesome. We are unable to find a better teacher for this subject somewhere else. Please sir, it's our request to increase the frequency of lectures.

  • @badxcode
    @badxcode Před 4 lety +9

    Please, upload these video as soon as possible. We know it takes a lot of time to make these videos, but keep uploading them sir. We are waiting for the next video. Thank you sir. Watching from Bangladesh.

  • @amytie7942
    @amytie7942 Před rokem +9

    Clear explanation. This is just what I needed to understand the topic, thank you so much Neso Academy

  • @puripatratanaarpa4066
    @puripatratanaarpa4066 Před 2 lety +2

    You save my life. Trying to understand this concept take me very long time. Your video clear my brain.

  • @kevin-xr1wf
    @kevin-xr1wf Před 3 lety +7

    Teaching is art.... Neso is artist👌

  • @quoctuan2002
    @quoctuan2002 Před rokem +2

    very easy to understand. In my class,teacher teaches very fast and sketchy so it took me a lot of time to understand

  • @nithyarao8039
    @nithyarao8039 Před 3 lety +3

    Never in my life I would feel this happy.. thanks lot

    • @aakashakku5
      @aakashakku5 Před 3 lety

      can u share this code? I'm not understanding

  • @vickyt116
    @vickyt116 Před rokem +2

    Wish ur my professor who gets straight to the point with clear explain

  • @invaderffgaming4475
    @invaderffgaming4475 Před rokem +2

    You are my greatest teacher of my all time thanks a lot sir

  • @nehagupta9357
    @nehagupta9357 Před 2 dny

    And ur teaching way is so amazing which is easy to understand

  • @MahaLakshmi-yx5ip
    @MahaLakshmi-yx5ip Před 3 lety +2

    The way you are teachig is awesome,this is very easy to understand......really Wowww,really thank you soo much Neso Academy.....

  • @manavpatel1420
    @manavpatel1420 Před 4 lety +3

    Please continue this data structure series
    Don't stop kindly send video as soon as possible

  • @user-ow4un4kt1j
    @user-ow4un4kt1j Před 8 měsíci

    I have watched this lesson of various channels but in vain.
    Finally I have learned it from you.🎉❤

  • @bindhushreeg1758
    @bindhushreeg1758 Před 3 lety +4

    sir ur teaching just awsm sir I'm love with ur neso academy seriously
    Oh my god I felt data structures as so difficult but the way u thought me made my data structure perfect
    Tq so much sir once again👑👑👑👑👑👑

  • @kajalmondal9745
    @kajalmondal9745 Před 4 lety +5

    Teaching is an art
    And you are the artist💜💜💜

  • @dhananjaypandey9977
    @dhananjaypandey9977 Před 3 lety +3

    Sir I am student of b.tech cse you teach great ...but please put algorithm for all the videos you have made i want to find step by step algorithm....but without any doubt you are very helpful thanks...😊

  • @manuelconte2127
    @manuelconte2127 Před rokem +5

    EXPLANATION MASTERPIECE !

  • @accessdenied9393
    @accessdenied9393 Před 3 lety +1

    Dr. Neso, why I cannot do something like so, is so brief:
    typedef struct node
    {
    int data;
    struct node *ptr;
    }
    node;
    int main(void)
    {
    node n2 = {20, NULL};
    node n3 = {30, NULL};
    n2.ptr = &n3; // link node 2 with node 3
    node n1 = {10, NULL};
    n1.ptr = &n2; // link node 1 with node 2
    for (node *tmp = &n1; tmp; tmp = tmp->ptr)
    printf("%i
    ", tmp->data);
    }

  • @jdrex5039
    @jdrex5039 Před rokem +3

    Your videos are awesome! Great job teaching this stuff!

  • @manideep.v8b500
    @manideep.v8b500 Před 11 měsíci

    It is really a blessing to have neso academy.. Thanks a lot for this... ❤

  • @itlti5557
    @itlti5557 Před 3 lety +2

    THANKS MAN! THIS IS SO EASY NOW...

  • @pookiecookie02
    @pookiecookie02 Před 7 měsíci +3

    His font colours are of the Indian flag.

  • @bartlomiejodachowski
    @bartlomiejodachowski Před 2 lety +2

    instead of returning head via return we could have used pointer to head; beacuse head is already a pointer it would have been double pointer.
    void add_beg(node **headPtr, int d){
    node* new = malloc(sizeof(node));
    new->data = d;
    // _new->link = NULL;_
    *new->link = *headPtr;*
    **headPtr = new;*
    }
    e.g add_beg(&head, data);

  • @prajithshetty2027
    @prajithshetty2027 Před 3 lety +1

    I really understood linked list by watching your videos

  • @ojewandetaofeek9737
    @ojewandetaofeek9737 Před rokem +2

    Thank you so much for the videos

  • @AryanKumar-cc7ku
    @AryanKumar-cc7ku Před 4 lety +1

    Sir... please upload all videos as fast as you can.... because i have to end this data structure in this lockdown..and i am totally depend on you

  • @Veda8285
    @Veda8285 Před 3 lety +1

    Big fan of Neso Academy

  • @58__tannurawat95
    @58__tannurawat95 Před 3 lety +4

    Now the linked list looks like bacho Ka khel 😂😂😂😂 outstanding sirr kept up sir👍🏾

  • @dynamite4677
    @dynamite4677 Před 3 lety +2

    You are such an amazing tr..thankyou sir

  • @Gsk710
    @Gsk710 Před 2 lety

    you are the best teacher

  • @siddhantpathak2063
    @siddhantpathak2063 Před 3 lety +9

    4:00
    We have to typecast ptr into node* as malloc function returns as void pointer datatype

    • @rishabhjain7119
      @rishabhjain7119 Před 3 měsíci

      It isn't compulsory. You can do it without explicitly typecasting it.....I don't know the reason behind it tho...

  • @dipeshsamrawat7957
    @dipeshsamrawat7957 Před 3 lety +1

    I love Neso Academy. :)

  • @414kunchalavenkatesh9
    @414kunchalavenkatesh9 Před 3 lety +1

    Sir,not getting output,it showing error" undefined reference to" add-beg', plz help me

  • @naurinsultana1166
    @naurinsultana1166 Před 4 lety +3

    U are a pure gem

  • @mirmohsinali732
    @mirmohsinali732 Před 3 lety +3

    Can someone explain why we use "head=add_beg(head,data);"? Why are we assigning the function to head? Also, why is "return head;" necessary for this program?

    • @comp_131_takshpatel9
      @comp_131_takshpatel9 Před 2 lety +3

      Before this line writing our head address us 1000
      And after writing this line head=add_beg(head,data); we update the head 3000 instead of 1000
      Why return the head ,because we achieve a new value of head it means we update the value of head

    • @LeoL123
      @LeoL123 Před rokem

      pointer head and ptr in the function are local to its function. pointer head in the add_beg function only copies the values from the pointer head in main function, both have the same name 'head' but they are different pointer. even though there is 'head = ptr' in the add_beg function, it doesn't mean the value of the pointer head in main function will change to ptr. therefore the value of ptr should be return to main function as pointer head. Actually 'return ptr' will do the same job as 'return head' in this case and you don't need 'head = ptr'.

  • @nirupamabhoi923
    @nirupamabhoi923 Před 4 lety +2

    First ptr was pointing to the node address 2000. How the same pointer will point to the newly created node of address 3000 ? little confusing sir.

    • @rajeshprajapati6662
      @rajeshprajapati6662 Před rokem

      pointer with address 3000 is local to addbeg function only. It is different pointer from the main function one.

  • @anasshilar1293
    @anasshilar1293 Před 13 dny

    Is the function you shown in back is have to insert in a program or not

  • @darkshadowgamming645
    @darkshadowgamming645 Před rokem

    sir as we know this data is stored in Heap so after printing the data isn't it lost forever in Heap when we exit the program without even deallocating the memory.

  • @tails_the_god
    @tails_the_god Před 3 lety +1

    i tried following this and it worked! :D but arent you suppose to free the memory after?

  • @daverussell4052
    @daverussell4052 Před 3 lety +1

    im a little bit confuse if i remove head = ptr; the program is just work fine, because the functions already returns the ptr and you assign the head with the ptr in the main functions. why we should assign head to the pointer in the local variable ? and also if you dont assign the head in the main section the head still remains the address of the first node you store not the one that you append

    • @rajeshprajapati6662
      @rajeshprajapati6662 Před rokem +1

      ptr = head in the main function is done to traverse the node while head is always there to point to the first node.

  • @AbdulRahman-se6db
    @AbdulRahman-se6db Před 4 lety +3

    After the explanation, plssss write the whole code together, as I'm unable to understand where to put the add_beg function that you created at 3:25 in the main code ??? Can anyone help me out

    • @aakashakku5
      @aakashakku5 Před 3 lety

      m too struggling.. He said to add_beg code but where.. somebody pls help me

  • @ANKITKUMAR-hj8pm
    @ANKITKUMAR-hj8pm Před 4 lety +2

    Plz upload complete video on ds ASAP🙏

  • @mayankyadav1290
    @mayankyadav1290 Před 3 lety +2

    sir when do we have to declare the function as void and when to struct node * type

    • @roudra323
      @roudra323 Před 3 lety +1

      when a function returns nothing, it is called void, and when a function returns something it you have to write the return type instead of void,

  • @marva2163
    @marva2163 Před 2 lety

    Thanks a lot.......no words to express.

  • @xiaoshen194
    @xiaoshen194 Před 2 lety +1

    Beautiful . Thank u 😘😘😘 muuuaahhh

  • @pujariom8466
    @pujariom8466 Před 10 měsíci +23

    Not understanding sir

  • @saicharan8638
    @saicharan8638 Před 2 lety

    Excellent teaching sir

  • @guldencetin3939
    @guldencetin3939 Před rokem +1

    Hocam niye alt yazıyı kapattınız .Lütfen açar mısınız ayrıca mükemmel anlatıyorsunuz

  • @amitsingh-fu5jl
    @amitsingh-fu5jl Před 3 měsíci

    where do you free all the memory allocated by malloc?

  • @dominiquefortin5345
    @dominiquefortin5345 Před 2 lety

    The use of a caboose is another way and it simplifies all the code. struct node *createList() {struct node *nd = malloc(sizeof(struct node)); nd->link = nd; return nd;}; void insertBefore(struct node *nd, int new_data) {struct node *new_nd = malloc(sizeof(struct node)); new_nd->link = nd->link; new_nd->data = nd->data; nd->link = new_link; nd->data = new_data;}; Now all the other functions get simplified : void add_beg(struct node *head, int new_data) {insertBefore(head, new_data);}; void add_at_end(struct node *head, int new_data) {struct node *nd = head; while (nd->link != nd) {nd = nd->link;}; insertBefore(nd, new_data);}; void add_at_position(struct node *head, int new_data, in pos) {struct node *nd = head; --pos; while (nd->link != nd && pos > 0) {nd = nd->link; --pos;}; insertBefore(nd, new_data);};

  • @nishchhalpachouri1658
    @nishchhalpachouri1658 Před 3 lety +1

    @neso acadmey
    This code isn't working showing an error. can u plz give me the source code...

  • @tahirnawaz9821
    @tahirnawaz9821 Před 2 lety +1

    Great work

  • @mohammadimranaameri225
    @mohammadimranaameri225 Před 3 měsíci

    Awesome Job 👏💯 thanks 👍

  • @reverbism
    @reverbism Před 2 lety

    Thank You 7/03/2022 5:28 am

  • @kimdev11
    @kimdev11 Před 3 lety

    one of the best! kudos

  • @tadkoleindhu5617
    @tadkoleindhu5617 Před 2 lety

    what we need to use instead of add_beg?it is not working on code blocks

  • @29_d_abhishekshukla21
    @29_d_abhishekshukla21 Před 2 lety

    Sir one error will come at line 9 at struct node *ptr is declaration is not allowed here

  • @santhoshsiva281
    @santhoshsiva281 Před 2 lety

    whether ptr!=NULL and ptr->link !=NULL are all same?

  • @abhayrathore9136
    @abhayrathore9136 Před 2 lety +2

    Where can we find the source code?

  • @rabiakainat7865
    @rabiakainat7865 Před 2 lety

    Thank you so much sir😍😍😍😍😍😍😍

  • @j.r.r.tolkien8724
    @j.r.r.tolkien8724 Před 2 lety

    You're the best!

  • @GlobalYoung7
    @GlobalYoung7 Před rokem

    Thank you ❤😊

  • @rythmikz_beatbox
    @rythmikz_beatbox Před 2 lety

    Is it mandatory to create two nodes manually to insert a node at the beginning

  • @siddhantaasarmya3718
    @siddhantaasarmya3718 Před 3 lety

    Why is there * after struct_node in function? can you answer this

  • @amanmenda2407
    @amanmenda2407 Před 2 lety

    Tysm man ! ❤️

  • @rajumaurya7901
    @rajumaurya7901 Před 9 měsíci +2

    why am i getting two different output by calling traverse().
    #include
    #include
    struct node{
    int data;
    struct node *link;
    };
    void main(){
    struct node *head;
    head = (struct node*)malloc(sizeof(struct node));
    head->data = 10;
    head->link = NULL;
    insert_at_beg(head);
    traverse(head);
    }
    void insert_at_beg(struct node *head){
    int item;
    struct node *newnode;
    newnode = (struct node*)malloc(sizeof(struct node));
    printf("Enter the data which you want to insert : ");
    scanf("%d",&item);
    newnode->data = item;
    newnode->link = NULL;
    if(head==NULL){
    newnode->link = NULL;
    }else{
    newnode->link = head;
    }
    head = newnode;
    traverse(head);
    }
    void traverse(struct node *head){
    int count=0;
    if(head == NULL){
    printf("linked list is empty!!");
    }
    struct node *ptr = NULL;
    ptr = head;
    while(ptr != NULL){
    printf("%d ", ptr->data);
    ptr = ptr->link;
    count++;
    }
    printf("
    total number of items in linked list = %d
    ", count);
    }
    OUTPUT:-
    Enter the data which you want to insert : 55 // traverse() call inside the insert_at_beg()
    55 10
    total number of items in linked list = 2
    10 //traverse() call inside the main()
    total number of items in linked list = 1

    • @kanak328
      @kanak328 Před 5 měsíci

      Why you are calling travers function 2 times..No need inside the function..

  • @pradhmrajeswar
    @pradhmrajeswar Před rokem

    bro one doubt, in struct node why we should'nt declare the head

  • @battuadityarao
    @battuadityarao Před rokem +2

    someone paste the full code here. i am in confussion

  • @patel_darshan_2803
    @patel_darshan_2803 Před rokem

    Where we write new node code before int main or inside int main??

  • @sakshigokhale11
    @sakshigokhale11 Před rokem +1

    In comparison with this no such content is available anywhere on CZcams

  • @shubhamjha445
    @shubhamjha445 Před 2 lety

    Why we are using functions for inserting node at the begginning

  • @user-qe7kw7qx7x
    @user-qe7kw7qx7x Před 10 měsíci

    Hello,sir,why some videos don't have captions, I love your CS videos but if there are not captions it is diffficult for me to understand you.

  • @saifmos6516
    @saifmos6516 Před 3 lety +2

    why dont you free all the pointers from the heap after all with free() , is not that better?

  • @jatinkumar-ln5sh
    @jatinkumar-ln5sh Před rokem

    Yaar tum bilkul correct bata rahe ho baki bahut sare log galat salat bata rahe hai phir bhi log na jaane kya kya dekh rahe hai. Self explanatory video

  • @naaznkv8958
    @naaznkv8958 Před 3 lety +1

    Good information but it would be more beneficial if it's in Hindi language 👍👍

    • @kasinathvaradi357
      @kasinathvaradi357 Před 3 lety +3

      What about the people who don't know hindi bro 😂😂😂

  • @Family_12362
    @Family_12362 Před rokem +3

    Bro that code is not compiling

  • @hariomkeswani9150
    @hariomkeswani9150 Před 2 lety

    Thank you bro🥳🥳🥳

  • @beeanonymous5032
    @beeanonymous5032 Před 3 lety

    Bro stack implementation of linked list and queue implementation of linked list.

  • @023_srayanchakraborty3

    why is the function struct Node* type??

  • @sathwiknaveen3786
    @sathwiknaveen3786 Před 2 lety

    Tq bro😍😍

  • @nehagupta9357
    @nehagupta9357 Před 2 dny

    Sir pls program ko online run kraya kriye

  • @amithp6703
    @amithp6703 Před 5 měsíci

    Why struct node* used while writing a function

  • @programacionpse3520
    @programacionpse3520 Před 3 lety

    sir can you help me how to understand easily code of data structure
    From South india

  • @charanteja8859
    @charanteja8859 Před 3 lety

    what if the list is empty then where you will add at beginning or end?

    • @sagarsrivastava8230
      @sagarsrivastava8230 Před 3 lety +1

      if(head==NULL)
      {
      head=temp;
      }
      and temp will be our first node in this case.

  • @rishabhjain7119
    @rishabhjain7119 Před 3 měsíci

    Why even do head=ptr? We have already linked ptr to the node what's the need to update the head pointer?

    • @milic5068
      @milic5068 Před 20 dny

      because head needs to represent the first node in the list
      if we don't update the head we won't be able to access the first node later

  • @rumanajabeen6080
    @rumanajabeen6080 Před 9 měsíci

    Does this program execute or any errors in this program..??!!

    • @rumanajabeen6080
      @rumanajabeen6080 Před 9 měsíci

      Please reply it

    • @chaudarysuleman4018
      @chaudarysuleman4018 Před 8 měsíci

      @@rumanajabeen6080 yes bro it execute
      #include
      #include
      using namespace std;
      struct NODE{
      int data;
      struct NODE *link;
      };
      struct NODE* add_node(struct NODE*head,int data)
      {
      struct NODE*ptr;
      ptr=new NODE;
      ptr->link=NULL;
      ptr->data=data;
      ptr->link=head;
      head=ptr;
      return head;
      }
      int main()
      {
      struct NODE *head;
      head=new NODE;
      head->data=45;
      head->link=NULL;
      struct NODE *current;
      current=new NODE;
      current->data=46;
      head->link=current;

      current=new NODE;
      current->data=47;
      head->link->link=current;
      int data=48;
      head=add_node(head,data);
      if (head==NULL)
      cout

  • @sinegazer
    @sinegazer Před rokem

    Lifesaver 😭😭😭

  • @nquanta1548
    @nquanta1548 Před 3 lety

    Super👍👍👍

  • @naturelovers1838
    @naturelovers1838 Před 2 lety

    wont ptr -> link=head update address of head in ptr

  • @pacikkondeng6994
    @pacikkondeng6994 Před 4 lety +1

    How about adding a node at the end of the list?

  • @emma_promise_smartnbc4331

    I still don't undertand why we need "head = ptr"; Since new_node is already linked to the first node(head)

    • @rajeshprajapati6662
      @rajeshprajapati6662 Před rokem +1

      first node (head) becomes second node but we need head pointing to the first node. So, head = ptr makes head to point to the first node.

  • @beyond3941
    @beyond3941 Před 4 lety

    how much more content remains in this course

  • @zazatjijombo174
    @zazatjijombo174 Před 11 měsíci

    Let me tell you❤

  • @liveonphoenix5045
    @liveonphoenix5045 Před rokem

    start @3:38, ptr->link = head; head = ptr; ???

  • @hemlataverma354
    @hemlataverma354 Před rokem

    Is this program is working on pc Or not