How to create and display a Linked List in C programming

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ต.ค. 2024
  • In this video, we learn the program to create a Linked List of given length and then to display it.

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

  • @unforgetable4747
    @unforgetable4747 3 ปีที่แล้ว +19

    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.

  • @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 ปีที่แล้ว +13

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

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

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

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

    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

  • @tumarisyalqun7327
    @tumarisyalqun7327 5 ปีที่แล้ว +14

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

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

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

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

      Happy to help!

  • @tejasshelke2081
    @tejasshelke2081 ปีที่แล้ว +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

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

    probably the best explanation of ow to create a linked list

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

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

    FINALLY AN ACTUAL GOOD VIDEO ON THIS TOPIC THANK YOU KING

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

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

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

    This is absolutely the best video of linked list for beginners

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

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

  • @chibbi9745
    @chibbi9745 ปีที่แล้ว +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.

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

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

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

    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.

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

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

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

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

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

    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

  • @DS-me7kk
    @DS-me7kk ปีที่แล้ว

    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

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

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

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

    Great explanation. I understood linked list very well

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

      Glad it was helpful!

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

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

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

      Glad it was helpful!

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

    THANK YOU . YOU LITERALLY SAVED ME BRO

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

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

  • @SONUKUMAR-sy7op
    @SONUKUMAR-sy7op 4 ปีที่แล้ว +2

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

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

    Awesome explanation... Thanks you very much ✅

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

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

  • @NaveenSingh-js6ts
    @NaveenSingh-js6ts 4 ปีที่แล้ว

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

  • @Burak-cr6um
    @Burak-cr6um 2 ปีที่แล้ว

    Thank you! it was very helpful.

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

    Good explanation.Thank you!

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

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

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

      Glad I could help!

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

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

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

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

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

      @@BBarters thaks you sir

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

    I don't think it is absolutely necessary to iterate the existing list to attach to a new node to the last node.
    A simple node pointer variable, say "node *previous" can be used for this purpose in the else clause, thus:
    if(head == NULL)
    {
    ...
    }
    else
    {
    previous->next = temp;
    }
    Then at the end of the for loop the following assignment will ensure that "previous" is assigned a valid value for subsequent iterations and therefore, keeps track of the last created node
    for(...)
    }
    ....
    previous = temp;
    }

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

    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.

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

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

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

    Sir, yr explaining way is perfect 🤗

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

    Good explanation sir thanks.

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

      You are welcome!

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

    is * and -> the same thing in c?

    • @djankies
      @djankies 5 หลายเดือนก่อน +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 5 หลายเดือนก่อน

      Thx 🙏🏻 ​@@djankies

    • @thelosttomato4020
      @thelosttomato4020 5 หลายเดือนก่อน

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

  • @陳翰儒-d5m
    @陳翰儒-d5m 3 ปีที่แล้ว

    Thanks a lot ! You help me very much!

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

    This really helped me !

  • @dzbro1194
    @dzbro1194 5 หลายเดือนก่อน

    you be smashing that keyboard

  • @GMAbdullahAl-Kafi
    @GMAbdullahAl-Kafi 3 ปีที่แล้ว

    Thank you! The vedio help me a lot.

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

    Awesome explaination

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

      Glad you liked it!

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

    This is really helpful!

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

    sir, this is very inefficient. u keep setting p back to head instead of keeping it at the end of the list. can you please make a tutoriol to make a more efficient list perhaps?

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

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

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

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

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

    very nice tutorial.

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

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

  • @divyabhagat7375
    @divyabhagat7375 3 ปีที่แล้ว +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

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

    Thanks for the tutorial!

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

    thank's broo, it was helpful

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

      You're welcome!

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

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

    Which software you use for c programming

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

      it's CLion

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

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

    best till date.....

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

    Thank you , nice explanation!

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

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

    Thankq Sir, this help me a lot.

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

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

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

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

    sir could you please cover trees concept

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

    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

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

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

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

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

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

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

    i will share this with my friends

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

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

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

    Thank You so much

  • @sankethb.k642
    @sankethb.k642 5 ปีที่แล้ว +1

    Thanks a lot sir

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

    great sir

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

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

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

    Thank you so much ❤️

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

      You’re welcome 😊

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

    Nice video. Which IDE are you using?

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

  • @EzioAuditore-vr1oy
    @EzioAuditore-vr1oy 3 ปีที่แล้ว

    This stuff is so complex for a beginner, my prof acts like its nothing.

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

    finally.....thank u so much sir

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

    very good...

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

    thanks for this video sir

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

    It helped me a lot

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

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

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

    • @golu.chotushukla9000
      @golu.chotushukla9000 6 ปีที่แล้ว

      Ariq Ahmer I think it's xcode

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

      Golu.chotu Shukla thanks... I'll look into it

  • @Babu-rj6ll
    @Babu-rj6ll 5 ปีที่แล้ว

    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 5 ปีที่แล้ว

      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 5 ปีที่แล้ว

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

    • @ale-hl8pg
      @ale-hl8pg 5 ปีที่แล้ว

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

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

    very helpful thank you

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

    thank you so much!

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

    theres a way to rank those numbers in crescent order?

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

    Hi Sir which compiler you are using?

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

    Thank you!!!

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

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

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

    Very informative, thanks! However you used malloc, without freeing up the allocated memory at the end.

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

      This function will fix that:
      void freeMemory(node * head)
      {
      node * p = head;
      node * temp = NULL;
      while (p != NULL)
      {
      temp = p;
      free(p);
      p = temp->next;
      }
      }

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

  • @faisalahmed-dr9xh
    @faisalahmed-dr9xh 4 ปีที่แล้ว

    Write a function that is used to read 5 student marks and store them using
    Linked List.

  • @kaansimsek9961
    @kaansimsek9961 3 ปีที่แล้ว +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

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

    Thank you