How to create and display a Linked List in C programming

Поділитися
Вставка
  • Опубліковано 14 гру 2024

КОМЕНТАРІ • 196

  • @unforgetable4747
    @unforgetable4747 3 роки тому +24

    This is the hands-down BEST VIDEO I've found on internet explaining linked-lists. All videos from other people only use 2 nodes and that leaves no possibility of automating head->next = temp in while loop. You'd have to write manually such as head->next = temp, head->next->next = temp and so on.
    Using a 3rd node p really solved my problem on which I was stuck for quite long time.
    You're the best. THANK YOU VERY MUCH.

  • @tejasshelke2081
    @tejasshelke2081 2 роки тому +1

    Mere teacher se accha sikhya aapne sir 3 din se sar fod raha tha me aaj finally ek perfect video mila jo dekh kar samaj me aya thanks sir

  • @RahulPal1998
    @RahulPal1998 4 роки тому +6

    best linked list implementation program ever explained
    every point in detail and I was try to do for about 3 day.
    and now every thing is cleared
    really thanks

  • @shubhamjha4158
    @shubhamjha4158 4 роки тому +95

    I was serious during the whole program. But when he said that this is a simple program, i laughed .

  • @tanbiralam5829
    @tanbiralam5829 7 років тому +51

    Sir you're really one of the best tutor I've ever seen..... I regularly follow you and recommended your channel to all my college mates.... keep uploading more contents for students like us. May god bless you

  • @dallasdominguez2224
    @dallasdominguez2224 4 роки тому +14

    Great explanation. I like that you walk through the code step by step. It really helped me understand how linked lists work.

  • @tumarisyalqun7327
    @tumarisyalqun7327 5 років тому +14

    Thank you! This was one of the best explained tutorials I've seen so far:) very helpful

  • @huec7184
    @huec7184 2 роки тому +1

    This is absolutely the best video of linked list for beginners

  • @tabletuser123
    @tabletuser123 Рік тому +2

    FINALLY AN ACTUAL GOOD VIDEO ON THIS TOPIC THANK YOU KING

  • @relaxationmusic3535
    @relaxationmusic3535 2 роки тому +1

    thanku so much sir for the clear explaination am searching for this type of video only where i can understand from basics.

  • @PinoyOnlineClass
    @PinoyOnlineClass 3 роки тому +5

    Oh my! Thank you! I've been racking my brain how to get this to work.

  • @aidenrhode8580
    @aidenrhode8580 6 років тому +2

    probably the best explanation of ow to create a linked list

  • @namrata1518
    @namrata1518 3 роки тому +1

    Thank you so much! I was stuck in linked list. I got savior like you really if teachers will teach and explain each and everything like you DSA won't be boring. Again Thank you🙏

  • @eduard289
    @eduard289 2 роки тому

    Best tutorial for LINKED LIST IN C !!!!!!!!!!!!!!!!!!!!!
    the best !

  • @franciscrypto9143
    @franciscrypto9143 2 роки тому

    finally you save me from cramming! I'm used to head being a global variable so when the prof provide assignment that making the head as local variable, that's where i stuck up to

  • @Moukraan
    @Moukraan 3 роки тому +6

    Thank you so much! I wonder why my college teacher couldn't explain like this

  • @zeus119
    @zeus119 2 роки тому

    Woow nice. I think I learned linked list with 3 videos and ur video is the bigest step.

  • @tt1281
    @tt1281 5 років тому +2

    Thank you sir , I was understanding nothing on linked list . Big thanks to your video

  • @luizhenriquebraunermoraes3175
    @luizhenriquebraunermoraes3175 4 роки тому +3

    Your explanation is top-notch! Thanks a lot!

  • @chibbi9745
    @chibbi9745 2 роки тому +1

    I was very happy yesterday that I found your channel but after that I saw many videos i want are not there😓
    It's ok I'm not blaming you sir it's just that I loved your teaching.

  • @nikitabiswas1061
    @nikitabiswas1061 3 роки тому

    Thank you so much sir. Was stuck on this for quite a long time.

  • @udaykirantheegala439
    @udaykirantheegala439 2 роки тому

    awsome sir i had sarched many website but i didn't find tq sir

  • @eliy5550
    @eliy5550 3 роки тому +1

    THANK YOU . YOU LITERALLY SAVED ME BRO

  • @pyb.5672
    @pyb.5672 6 років тому +5

    In a linked list, whenever you add a new node, there is no point adding it to the end of the list.
    This makes the operation O(n) which can take a very long time when you are adding your 1 millionth element to the list. Inserting a new node and attaching it to the former head and then defining it as the new head, takes a lot less time, O(1). If you do this, your list is reversed and checking whether an element is in the list or printing all the data in the nodes will take just as much time.

  • @ashwingoku5120
    @ashwingoku5120 4 роки тому +1

    Great explanation. I understood linked list very well

    • @BBarters
      @BBarters  4 роки тому

      Glad it was helpful!

  • @rblxmach
    @rblxmach 2 роки тому

    are you able to add stuff to the linked list in the console?

  • @vikitor21
    @vikitor21 5 років тому +4

    Thanks a lot! It was very helpfull. Salutations from Brazil

  • @HakuzaPK
    @HakuzaPK Рік тому +2

    is * and -> the same thing in c?

    • @djankies
      @djankies 7 місяців тому +1

      *node.data is the same as node->data. The dereference operator (*) is used to retrieve the actual node instead of the memory address (since node here is a pointer). Then dot notation to access variables in that node struct. The arrow operator (->) combines those two steps into one.

    • @JohnBonwa
      @JohnBonwa 7 місяців тому

      Thx 🙏🏻 ​@@djankies

    • @thelosttomato4020
      @thelosttomato4020 7 місяців тому

      p->data is the same as (*p).data

  • @prestonyates3379
    @prestonyates3379 Рік тому

    My head node changes with every iteration, even after the first. It only does the if statement once but if temp changes so does head. How do you fix this?

  • @maumitadas4332
    @maumitadas4332 2 роки тому

    Awesome explanation... Thanks you very much ✅

  • @yashgajewar9019
    @yashgajewar9019 4 роки тому +1

    just great explanation thank you a lot sir this was very helpful

    • @BBarters
      @BBarters  4 роки тому +1

      Glad it was helpful!

  • @divyabhagat7375
    @divyabhagat7375 4 роки тому +1

    I keep getting an error warning: data argument not used by format string for printf("
    Enter the data for node number:", i+ 1); I don't know how to fix this

  • @idangaray4398
    @idangaray4398 5 років тому

    Thanks for the video, one of the understandable video I've ever seen about linkedl list

  • @segniguta6569
    @segniguta6569 4 роки тому +1

    Does the while loop in the createLinkedList function operate? I mean since it is always false? Because p is always set to head, and head has always head->next = NULL.

  • @pepperdayjackpac4521
    @pepperdayjackpac4521 2 роки тому

    do we need to free the memory with free()?

  • @udaykirantheegala439
    @udaykirantheegala439 2 роки тому

    but sir when i written same code the erron was comming at this line
    node* creareList(int n)
    the error is conflicting type error what should i do

  • @DS-me7kk
    @DS-me7kk 2 роки тому

    Great explanation. Although I wish you used curly braces on that while loop...took me a day to realize next line is outside of the loop

  • @johngates2602
    @johngates2602 4 роки тому +1

    Good explanation sir thanks.

  • @inhVietQuangbi-
    @inhVietQuangbi- 3 роки тому

    if i want to count node can i use this code?:
    void getcount(node*head){
    int count=0;
    struct node*current;
    current=head;
    while(current!=NULL){
    count++;
    current=current->next;
    }
    printf("the lenght of the train is:%d",count);
    return count;
    }
    in main () {
    getcount(HEAD);
    }

  • @arjuntyagi19
    @arjuntyagi19 2 роки тому +4

    here is the exact code,hope this helps
    .
    .
    #include
    #include
    struct node{
    int data;
    struct node*next;
    };
    void displaylist(struct node*head);
    struct node *createlinkedlist(int n);
    int main()
    {
    int n=0;
    struct node* HEAD=NULL;
    printf("
    how many nodes:");
    scanf("%d",&n);
    HEAD=createlinkedlist(n);
    displaylist(HEAD);
    }
    struct node *createlinkedlist(int n)//function to create a single ll and add to end
    {
    int i;
    struct node*head=NULL;
    struct node*temp=NULL;
    struct node*p=NULL;
    for(i=0;idata));
    temp->next=NULL;


    if(head==NULL) //if head is empty make temp as first node
    {
    head=temp;
    }

    else
    {
    p=head;
    while(p->next!=NULL)
    p=p->next;
    p->next=temp;
    }


    }
    return head;
    }
    void displaylist(struct node*head)//function to display code
    {
    struct node*z=head;

    while(z!=NULL)
    {

    printf("%d->",z->data);
    z=z->next;
    }
    }
    note-i did not use typedef because i prefer using struct node instead of node.

  • @vishaltanawade7637
    @vishaltanawade7637 5 років тому +2

    Which software you use for c programming

  • @jashwanthms740
    @jashwanthms740 4 роки тому +1

    Awesome explaination

    • @BBarters
      @BBarters  4 роки тому

      Glad you liked it!

  • @AnkitSaiyan
    @AnkitSaiyan 5 років тому +2

    Or we can use do while loop to successfully print the last node using logic condition (p->next != NULL)

  • @rajkishorprasad4707
    @rajkishorprasad4707 4 роки тому

    Sir, yr explaining way is perfect 🤗

  • @NHCS_MABUD
    @NHCS_MABUD 5 років тому

    Hi Sir which compiler you are using?

  • @daniellima6590
    @daniellima6590 4 роки тому

    theres a way to rank those numbers in crescent order?

  • @SONUKUMAR-sy7op
    @SONUKUMAR-sy7op 4 роки тому +2

    Thank you sir for well explanation.
    Sir I want lecture of data structure
    Please help me.

  • @humayqanizade4600
    @humayqanizade4600 2 роки тому

    Good explanation.Thank you!

  • @christinasamuel4994
    @christinasamuel4994 2 роки тому

    Sir, can you show me how to read values from struct manual input and passing a pointer containing name, id and cgpa to linked list. Thank you.

  • @stephenkolluri2856
    @stephenkolluri2856 3 роки тому

    do we have to free malloc?

  • @gamingfundas
    @gamingfundas 5 років тому

    Sir i executed this code and it is taking inputs(valur of nodes) correctly but when its the time of display then it is showing an infinite loop....plzz help

  • @hrithikjoshi6918
    @hrithikjoshi6918 5 років тому

    you did what my professor couldn't.......

  • @許廷瑋-x6x
    @許廷瑋-x6x 4 роки тому

    謝謝,我有疑問使用malloc怎麼沒使用free

  • @wrnlb666
    @wrnlb666 3 роки тому

    Don't u like, free the memory for LinkedList?

  • @harshsinha9709
    @harshsinha9709 4 роки тому +1

    best till date.....

  • @carlosmarx3193
    @carlosmarx3193 5 років тому

    is there a video about operations of linked lists like insert delete on your chanel?

  • @Burak-cr6um
    @Burak-cr6um 2 роки тому

    Thank you! it was very helpful.

  • @NaveenSingh-js6ts
    @NaveenSingh-js6ts 4 роки тому

    Thank you for explaining the code so neatly....♥️

  • @mramzanali8156
    @mramzanali8156 4 роки тому +1

    sir ap k lactures bhut a6y han
    add more lactures in linked list all operation

    • @BBarters
      @BBarters  4 роки тому

      Surely, that is on the agenda. Will be doing that soon.

    • @mramzanali8156
      @mramzanali8156 4 роки тому

      @@BBarters thaks you sir

  • @shobhitranjan3957
    @shobhitranjan3957 6 років тому +4

    This really helped me !

  • @duketheduke390
    @duketheduke390 5 років тому +2

    This is really helpful!

  • @atharvabetawadkar7865
    @atharvabetawadkar7865 3 роки тому

    where can i get a video where a character is used instead of integer data to make a linked list

  • @huhu698
    @huhu698 4 роки тому

    Thank you so much for this. You helped me a lot.

    • @BBarters
      @BBarters  4 роки тому

      Glad I could help!

  • @ArifMahmood
    @ArifMahmood 6 років тому

    What if we replace code line int data with line An_element data where An_element is a struct and it has a single member int integer. If I do it in your code I see exception on line temp=(node*)malloc(sizeof(node)). I m trying to learn struct use on a list like this.

  • @alvislim515
    @alvislim515 5 років тому

    Hi Sir, how can we do to delete the particular node. Any video of yours? Appreciate on it =)

  • @dzbro1194
    @dzbro1194 7 місяців тому

    you be smashing that keyboard

  • @umbranocturna6342
    @umbranocturna6342 4 роки тому +1

    very nice tutorial.

  • @GMAbdullahAl-Kafi
    @GMAbdullahAl-Kafi 3 роки тому

    Thank you! The vedio help me a lot.

  • @kwadh8629
    @kwadh8629 7 років тому +2

    sir please could you do Data Structures in one video....or maybe a playlist....especially with respect to interview

  • @陳翰儒-d5m
    @陳翰儒-d5m 3 роки тому

    Thanks a lot ! You help me very much!

  • @mdrajibhasnat2321
    @mdrajibhasnat2321 2 роки тому

    Amazing🥰

  • @ravikumargantla7998
    @ravikumargantla7998 6 років тому +1

    i will share this with my friends

  • @rishabhpathak6115
    @rishabhpathak6115 3 роки тому

    R.I.P to keyboard keys.....btw nice explanation

  • @edwardhaybell1938
    @edwardhaybell1938 3 роки тому

    Ahhh, I finally got what I did wrong! Thank you man!

  • @bapi6060
    @bapi6060 6 років тому

    Where did the other videos go?

  • @manjuarora3982
    @manjuarora3982 2 роки тому

    Sir r u running any institute.

  • @alanouri9965
    @alanouri9965 4 роки тому +1

    thank's broo, it was helpful

  • @sohamzemse
    @sohamzemse 6 років тому

    why we write the node * createLinkedList (int n); line? as we are not creating a function with that line. we again have to write it below and then also specify instructions in the function. what is the need of the earlier line.

  • @Pdq-_-
    @Pdq-_- 24 дні тому

    Sir youre best

  • @carlosmercado2780
    @carlosmercado2780 6 років тому

    Nice video. Which IDE are you using?

  • @joseantoniojunior5460
    @joseantoniojunior5460 3 роки тому

    Thanks for the tutorial!

  • @Babu-rj6ll
    @Babu-rj6ll 6 років тому

    Sir please say that why you used node* in node* createLinkedList(int n)....and also explain that why you only returned head as it contain only th value of head..Please explain that sir..

    • @ale-hl8pg
      @ale-hl8pg 6 років тому

      you can return pointers with functions
      the createlinkedlist is type node* because it returns a pointer to the struct node*
      structs are still data types they're just "complex" because they can contain int's, char's, etc, so you can't use an int pointer to a struct, you'd have to use a pointer which is of type struct (name of the struct)
      linked lists only need the starting value as in the function where the program creates it, it also iterates through them and changes the value of them in each
      {
      p = head;
      while(p->next_node != NULL)
      {
      p = p->next_node;
      }
      p->next_node = temp;
      p is just a pointer for iteration, so it's used to go through the list til it finds the last item, if there is one, it would change the value of the "next" to temp, because temp is a pointer to the last node so you don't need the individual address of each node saved, like you would with an array

    • @Babu-rj6ll
      @Babu-rj6ll 6 років тому

      @@ale-hl8pg But why is head enough to return

    • @ale-hl8pg
      @ale-hl8pg 6 років тому

      @@Babu-rj6ll the struct has a pointer called next
      when you make a new node you also cycle through them, and change that next value to the new one (aka temp, which stores the address of the new node), so all you need is the address of the first node which is pretty much contained in the head
      it's how a linked list functions, you have to go through each of them to get to the part of the list you want

  • @asranaseem1966
    @asranaseem1966 6 років тому +1

    sir could you please cover trees concept

  • @kedarjani4396
    @kedarjani4396 4 роки тому +1

    i will not write a long comment but ,
    thank you SO MUCH for this...

    • @BBarters
      @BBarters  4 роки тому +2

      You're very welcome!

  • @許廷瑋-x6x
    @許廷瑋-x6x 4 роки тому

    哈哈哈謝謝,我知道我錯在那了8:28,我把while(p->next!=NULL){p=p->next; p->next=temp;}寫在一起,抱歉抱歉

  • @rajkumar-uk6hk
    @rajkumar-uk6hk 3 роки тому

    i tried the same code but it showing segmentation fault

  • @kaansimsek9961
    @kaansimsek9961 4 роки тому +1

    I write this code and when I tried my output was 1-> 2-> 33->9772504... My input was 1,2,33. Why 9772504 occurs in my code. Can anybody help?

    • @josemanuelruizgonzalez9353
      @josemanuelruizgonzalez9353 3 роки тому

      Because it overflows the integer, the max number you can use is 32,767 or twice if it's an unsigned int

  • @healthinsurance59
    @healthinsurance59 5 років тому

    Where you have declared struct node

  • @zohramoiz6177
    @zohramoiz6177 5 років тому +1

    finally.....thank u so much sir

  • @OzzyR21
    @OzzyR21 6 років тому

    What happens if you need an empty list?

  • @playdagameythd6069
    @playdagameythd6069 3 роки тому

    For me it's not printing the last number, for example i input the number 5,6,8,7,4 and it prints 5->6->8->7
    Anyone help?

  • @ariqahmer
    @ariqahmer 6 років тому

    Awesome Video... Which IDE are you using on your MacBook?

  • @adamjunior4929
    @adamjunior4929 3 роки тому

    thanks for this video sir

  • @menifestationtechniques5921
    @menifestationtechniques5921 2 роки тому

    great sir

  • @shrinathdarur5184
    @shrinathdarur5184 6 років тому

    Thank you , nice explanation!

  • @babukamal473
    @babukamal473 3 роки тому

    very good...

  • @ARUNKUMAR-cn4ne
    @ARUNKUMAR-cn4ne 6 років тому

    Excellent Sir

  • @slippyfist747
    @slippyfist747 3 роки тому

    Man wish i found this video when i was taking data structures 8 years ago, maybe i wouldnt have switched to a useless physics degree

  • @santiherrera807
    @santiherrera807 5 років тому +8

    Am I the only one seeing a mistake in the printf argument??? The code should not compile, I mean, I do not like when someone hides his mistakes just to make everything seem perfect.

  • @dipakmishra7239
    @dipakmishra7239 5 років тому

    Thankq Sir, this help me a lot.