Linked List in C/C++ - Inserting a node at beginning

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

КОМЕНТАРІ • 579

  • @youssefrezkou7003
    @youssefrezkou7003 5 років тому +109

    after 6 years of creating this videos ... no one created something better ! thanks alot teacher

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

      Sadly we dont have the founder of this channel

    • @ayushsharma9640
      @ayushsharma9640 3 роки тому +3

      @@bipulkumar6637 yes he is no more

    • @Fabios-br
      @Fabios-br 3 роки тому

      Is he Lord Harsha?

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

      @@Fabios-br The one teaching in this video is Animesh Nayan. Harsh also has a video on this channel - the one about GCD algorithm.

  • @mycodeschool
    @mycodeschool  11 років тому +39

    Hi Siddharth,
    Yes, we will continue creating more videos in data structures series. :)

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

      sir, please make video series on dynamic programming, greedy Algorithms,divide and conquer etc and some advance data structures like segment trees !!

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

      Numbers inputs from users display on List: are joint and no space between them why?

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

      @@convolutionalnn2582 use endl for c++ or newline character
      for C

  • @AkshayKumar-dz5ts
    @AkshayKumar-dz5ts 8 років тому +211

    For anybody getting the error "node not defined" -> after initial definition of the node and before the semicolon just put Node it looks something like this
    struct Node
    {
    int data;
    struct Node* next;
    }Node;
    If anybody wants the whole code to the one in this lesson:
    //INSERTION OF NODES AT THE BEGINNING AND IT'S DISPLAY
    #include
    #include
    struct Node
    {
    int data;
    struct Node* next;
    }Node;
    struct Node* head;
    void insert(int x);
    void print();
    void main()
    {
    head=NULL;
    printf("how many numbers?
    ");
    int n,i,x;
    scanf("%d",&n);
    for(i=0;idata=x;
    temp->next=head;
    head=temp;
    }
    void print()
    {
    struct Node* temp=head;
    printf("List is:");
    while(temp!=NULL)
    {
    printf("%d ",temp->data);
    temp=temp->next;
    }
    printf("
    ");
    }

  • @Gaggio23
    @Gaggio23 9 років тому +365

    Even if you are programming in C you can avoid to write "struct Node ..." every time by declaring the struct like this:
    typedef struct Node{
    int data;
    struct Node* next;
    }Node;
    This way you will be able to declare Node variables the same way you do in C++.

    • @anfield6321
      @anfield6321 7 років тому +49

      He assumes that people are fairly new to c because of which he wants to make the code as simple as possible

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

      Ahaa!!!

    • @andremuslim9594
      @andremuslim9594 6 років тому +3

      That's great man. Thanks a lot

    • @StockDC2
      @StockDC2 6 років тому +15

      Just as an FYI for anyone looking into doing this, this polutes the global namespace and is not recommended.

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

      Is there a way to do this without malloc? Because I am fairly new and I have no idea what malloc is.

  • @thestarinthesky_
    @thestarinthesky_ 4 роки тому +7

    The most AMAZING course explained brilliantly! So grateful!

  • @mycodeschool
    @mycodeschool  11 років тому +3

    Yes, that's true. You should free any memory allocated using malloc once you are done using it. In this lesson, the intent was to show the implementation of insert function. But despite that, not having an explicit free is not doing any bad here. As soon as we are done printing all the elements, we are anyway done in the main function and the program execution will finish. And once program finishes, all of its memory is freed anyway.

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

      Thank you for your patience, I have always had doubts here

  • @rohitaswasarbhangia7722
    @rohitaswasarbhangia7722 7 років тому +1

    the way you changed the implementation, one using global variable, others using return and pointer to pointer, dope sir. now I know how proficient I need to be to just participate in competitive programming. thanks again.

  • @mashable8759
    @mashable8759 8 років тому +593

    35 dislikes are those people who use ARRAY all the time XD

    • @manishbudhathoki892
      @manishbudhathoki892 7 років тому +5

      hahaha maybe

    • @anfield6321
      @anfield6321 7 років тому +20

      Well linked list is not efficient to use at all. We should avoid using linked list as much as possible

    • @ffantasyvii
      @ffantasyvii 7 років тому +1

      Why is that, and if so what is the most efficient way?

    • @rolandoaguilera3114
      @rolandoaguilera3114 6 років тому +8

      For RTOS (Real Time Operating Systems) linked lists are fundamental

    • @pathfinder750
      @pathfinder750 6 років тому +5

      Umm i think it depends on what you're working with

  • @randomvinesvids5703
    @randomvinesvids5703 9 років тому +34

    Complete code for: Insertion, Deletion and Print working:
    #include
    using namespace std;
    struct Node{
    int data;
    Node* next;
    };
    Node* Insert(Node* head, int x)
    {
    Node* newN=new Node();
    newN->data=x;
    newN->next=NULL;
    if(head!=NULL) newN->next=head;
    head=newN;
    return head;
    }
    Node* InsertNth(Node* head, int x, int nt)
    {
    Node* temp1=new Node();
    temp1->data=x;
    temp1->next=NULL;
    if(nt==1)
    {
    temp1->next=head;
    head=temp1;
    return head;
    }
    Node* temp2=head;
    for(int i=0; inext;
    }
    temp1->next=temp2->next;
    temp2->next=temp1;
    return temp2;
    }
    Node *DeleteNth(Node* head, int nt)
    {
    Node* temp1=head;
    if(nt==1){
    head=temp1->next;
    delete temp1;
    return head;
    }
    for(int i=0; inext;
    }
    Node *temp2=temp1->next;
    temp1->next=temp2->next;
    delete temp2;
    return temp1;
    }
    void Print(Node* head)
    {
    while(head!=NULL)
    {
    cout

  • @khedubaba
    @khedubaba 6 років тому +263

    After 9:50 , No thanx I'll keep my head global.

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

    better than books,teachers,those udemy courses. You are the best. These tutorials will never get outdated.

  • @mycodeschool
    @mycodeschool  11 років тому +2

    I was using a C++ compiler. You do not need to write struct keyword in C++. Moreover, this thing is testing whether someone running this code in C can debug simple compilation errors or not. :) Anyway, thanks for noticing.

  • @ramanjangu895
    @ramanjangu895 Рік тому +1

    quality of content is amazing ,I am just started learning from this playlist.

  • @mycodeschool
    @mycodeschool  11 років тому +1

    Your insertion logic is correct. You may have a bug in main or print functions. Try to debug. Print your list every-time you insert a new element. So like after every call to insert_node, make a call to print. You should be able to nail down the exact issue.

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

    This was my most daunting concept. It took me 3 hours to understand this but at last I did it.

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

      Watch this one , it is the best
      seedha dimag mein ghusegaa
      sara doubt clear
      ua-cam.com/play/PLbRk-vKGcVtbyctZWP9SUYewwUfx75CpZ.html

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

      @@NitishKumarTutorials thankyou sir

  • @AjaySharma-le3df
    @AjaySharma-le3df 4 роки тому +4

    Thank you so much.
    I finally understood this after watching it so many times.
    You guys are doing great work.👍🏽

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

      Lockdown ka poora productive utilization ho raha hai bhai.
      Ek number bhai aise hi laga reh.

    • @AjaySharma-le3df
      @AjaySharma-le3df 4 роки тому

      @@abhishekagarwal3852 😁😁
      same to you bro🙏🏼

  • @jamesbones1668
    @jamesbones1668 7 років тому

    i think you're the best when it comes to c-related material, dude. thanks.

  • @GabrielSousathe
    @GabrielSousathe 6 років тому +10

    THANK YOU, JUST, THANK YOU!
    Your work is amazing, your videos are great and the way you teach is just incredibly good.
    I really appreciate what you have done and have been doing.

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

    Amazing, this is the first time that I realize the beauty of pointer!

  • @Rishabh2352
    @Rishabh2352 7 років тому

    Best content on Internet for learning data structures. Great work. Thanks a lot.

  • @license2Bort
    @license2Bort 9 років тому

    Exceptional video man. I was in a complete blank about how to do a linked list, but this video explained everything perfectly. Thank you.

  • @MrPatex21
    @MrPatex21 11 років тому +17

    void Insert(int x){
    struct Node* temp = (struct Node*)malloc(sizeof(struct Node));
    ...

    • @praveenkumar.m7949
      @praveenkumar.m7949 4 роки тому

      Error: Node undefined symbol
      Correct super struct key is not mention in this program

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

    Best data structure course on earth.

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

    After all happy to see a video in english
    -a non hindispeaker

  • @divyadeb123
    @divyadeb123 10 років тому +11

    YOU, sir, are a life savior !!!!!!!!!!!!!!!!!!

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

      You code for work or as a hobby🤔😂

  • @opc816
    @opc816 10 років тому

    No joke he is the best. He makes everything so clear. Thank you so much sir

  • @MrPatex21
    @MrPatex21 11 років тому

    I just wanted to point it our for someone who would have the same problems as me. Btw very good tutorials and this one is the first that I'll have to watch a couple more times to completly understood.

  • @vasilvasilev7938
    @vasilvasilev7938 10 років тому +8

    I love your lessons! Can you please also upload c++ code implementation?

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

      #include
      using namespace std;
      struct Node
      {
      int data;
      Node* next;
      };
      Node* head;
      void insert(int ind_input)
      {
      Node* temp = new Node;
      temp -> data = ind_input;
      temp -> next = head;
      head = temp;
      };
      void print()
      {
      Node* temp = head;
      while(temp != nullptr)
      {
      cout data next;
      }
      cout user_input;
      int ind_input;
      for(int i = 0; i < user_input; i++)
      {
      cout > ind_input;
      insert(ind_input);
      print();
      };
      };

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

      @@kanicagoddard6330 thank youu

  • @freddyflores6608
    @freddyflores6608 7 років тому +1

    The best video of Linked List I've ever seen, a good way to explain programming :) .

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

    best teacher ever . you healed my pointers trauma ;-)

  • @sr5726
    @sr5726 9 років тому +2

    Thank you for the video. Print function can also have null check for empty list
    if (head == NULL)
    {
    cout next = head;
    head = newNode;
    }
    InsertBeginning(head, 300);

  • @ibrahimmuhammad6300
    @ibrahimmuhammad6300 3 роки тому +3

    this the c++ code, i implemented it and sure it's working
    =============================
    #include
    using namespace std;
    struct Node{
    int data;
    Node* next;
    };
    Node* head;
    void Insert(int x){
    Node* temp = new Node;
    temp->data = x;
    temp->next = head;
    head = temp;
    }
    void print(){
    Node* temp = head;
    cout

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

      why you used struct instead of class??

  • @Dhyanithamanavya
    @Dhyanithamanavya 7 років тому

    who would be scared of programming or hate it if someone is teaching so well like this..

  • @mycodeschool
    @mycodeschool  11 років тому +6

    Thanks Jason !

  • @maheshj01
    @maheshj01 8 років тому

    thank you very much for this video,I was struggling a lot to understand how lists were implemented in c Even my teachers failed to make me Understand thanks a lot.
    you know what Iam posting this comment after implementing the lists successfully thank a lot.👍

  • @supertran28
    @supertran28 7 років тому

    You have saved my grade in college. Thank you so much

  • @mohitbv2331
    @mohitbv2331 8 років тому +4

    Thank you. However, I am getting an error, when I compile:
    link.c:13:21: error: ‘Node’ undeclared (first use in this function)
    struct Node* temp = Node* malloc(sizeof(struct Node));

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

      struct Node* temp = (struct Node*)malloc(sizeof(struct Node));

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

      @@ranasikder5497 I was getting same error but now wonder how his code worked yet mine dodn't.🤔

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

    1. mycodeschool
    2. thenewboston
    3. Derek Banas

  • @unsaturated8482
    @unsaturated8482 8 років тому

    you make great videos sire.
    Thank you for all your efforts.
    I love your desire to help people.
    you're a real man.

  • @ManojKumar-bz7qm
    @ManojKumar-bz7qm 6 років тому +1

    your explanation is just awesome sir..keep it doing

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

    the c++ code implementation is:
    class linkedlist{
    private:
    struct node{
    int data;
    node*next;
    };
    node*head;
    public:
    linkedlist(){
    head=0;
    }
    void add(int value){
    node*newnode;//declare a new node
    newnode=new node();//free some memory for the new node
    newnode->data=value;//insert it
    newnode->next=head;
    head=newnode;//the head now is pointing the element that we added to the linked list
    }
    void print(){
    node*newnode=head;
    cout

  • @suryasahu9046
    @suryasahu9046 8 років тому

    Loved the call by reference used in insert function by you at the end where you change the value of memory reference of insert var by passing address of insert

  • @crazymexicandope
    @crazymexicandope 6 років тому +28

    12:08 I was taking a drink when he said it, I almost drowned! Lol

  • @monicaslv323
    @monicaslv323 9 років тому +1

    In DeV, while programming in C language, for any declaration or manipulation of structures, you should type "struct NameStructure".

  • @manjeetsinghmehta9462
    @manjeetsinghmehta9462 8 років тому

    awesome ...this is what i was in search of ......very helpful to clear basic understanding ....thanks buddy....

  • @sid1501
    @sid1501 11 років тому +2

    thanks a lot for your videos! they helped me a great deal!!!
    can you please continue making more ? like for stacks, queues, double linked list!
    it would be really helpful thanks!!

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

    Miss U legend !

  • @moongirl26cac
    @moongirl26cac 10 років тому +4

    Thank you ,this clarified a lot of things for me..

  • @NJM0901
    @NJM0901 7 років тому

    Thank you so much ....😁.... It helped me lot .... I am gonna rock my lab test ....💙💙💙💙💙💙💙💙💙💙💙💙💙💙💙💙💙💙💙

  • @darknawg63
    @darknawg63 8 років тому +6

    One question. Isn't this program leaking memory? Where in the code should we be deallocating with free?

  • @Shagawee
    @Shagawee 10 років тому +4

    Thank you for these tutorials! They make the concepts of coding way easier to grasp.

  • @Bigly
    @Bigly 8 років тому +4

    Working code:
    #include
    #include
    void Insert(int x);
    void Print();
    struct Nodes{
    int data;
    struct Nodes *next;
    }Node;
    struct Nodes *head;
    int main(){
    head = NULL;
    printf("Enter number of components:
    ");
    int n, i, x;
    scanf("%d", &n);
    for(i=0; i < n; i++){
    printf("Enter the number: ");
    scanf("%d",&x);
    Insert(x);
    Print();
    }
    }
    void Insert(int x){
    struct Nodes *temp = (struct Nodes *)malloc(sizeof(struct Nodes));
    temp -> data = x;
    temp -> next = NULL;
    if(head != NULL){
    temp -> next = head;
    }
    head = temp;
    }
    void Print(){
    struct Nodes *temp = head;
    while(temp != NULL){
    printf("%d", temp-> data);
    temp = temp -> next;
    }
    printf("
    ");
    }

    • @rohitashkumar781
      @rohitashkumar781 8 років тому

      what is problem in my code help my sir
      #include
      #include
      struct node
      {
      int data;
      node *next;
      };
      struct node *head;
      int insert(int x)
      {
      struct node* temp=(node*)malloc(sizeof(struct node));
      temp->data=x;
      temp->next=head;
      head=temp;
      }
      int Print()
      {
      struct node* temp=head;
      printf("list is:");
      while(temp !=NULL)
      {
      printf(" %d",temp->data);
      temp=temp->next;
      }
      printf("
      ");
      }
      int main()
      {
      head=NULL;
      printf("enter how many no
      ");
      int n,i,x;
      scanf("%d",&n);
      for(i=0;i

    • @huyvole9724
      @huyvole9724 7 років тому

      (struct node *)malloc ....

  • @s.baskaravishnu22
    @s.baskaravishnu22 6 років тому

    your videos are excellent. Your videos are very much useful to me, Many thanks for that. My warm regards to you.

  • @md-ayaz
    @md-ayaz 8 років тому +7

    where are you using "free" to deallocate the memory?

    • @adeelmuzaffar1050
      @adeelmuzaffar1050 7 років тому +1

      Salam Mohammed,
      I had the same question and I tried to free up memory in the insert function but it made my code run in over drive. it keeps printing random numbers. Let me know if you're able to free up dynamically allocated memory.
      Thanks!

    • @huyvole9724
      @huyvole9724 7 років тому +1

      sir, I use another Pointer, ex: *p and p = &head, head = head->next and i free p, this is loop ulti p point NULL

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

      there is no need to use free. It will delete the node from the memory. But we are doing program for "inserting" and not for "deleting". Hence, free is not used.

    • @Dark-ur4wl
      @Dark-ur4wl 4 роки тому

      @@gurtej5821 Wrong check your code with valgrind.

  • @GaganDeep-xz8kf
    @GaganDeep-xz8kf 4 роки тому

    sir thaxxx a lot ,your efforts are are priceless

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

    @mycodeschool in 2:50, we can use for(int i=0,..........) in C too

  • @neil9151
    @neil9151 8 років тому +12

    can you provide the actual file of the program for further analysis like a downloadable one? it will be a great add on to your tutorials

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

      www.mycodeschool.com/problems/insert-a-node-in-a-linked-list-at-head

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

    It's been 8 years. No other video on DSA is better than this.
    Sad that he stopped uploading videos.

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

      Hi is no more brother

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

      @@mrboon8856 i'm sorry to hear about that ,what a pity

  • @mycodeschool
    @mycodeschool  11 років тому +2

    There are a lot of compilation errors in your code. You are writing "prinf" in your print function instead of "printf" ( t is missing) ... your functions are not returning anything even though their return type is not void. You need to read the compilation errors and try to fix the issues.

  • @maenolis
    @maenolis 11 років тому

    There is no need for freeing at the end of the program but someone who is learning now should learn early to free resources for the future. At my university teachers are insisting on that. After all that shows that you know better what you are doing with memory and you have better control. I hadn't googled that before to be honest but this is my humble opinion.

  • @ravishrimal6145
    @ravishrimal6145 8 років тому

    I have question that in the last case when you passed &head as an argument in Insert why we don't need to return the value of head and how the argument in Print function gets updated.

  • @daitaswararnavam
    @daitaswararnavam 8 років тому +10

    Hi,head is also of type node,if I am correct, we are just writing head=temp,is the data part of the head null or any garbage?

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

      Null

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

      bro head is a pointer variable which stores adress. so if we write like head=temp, the adress of temp node would be stored in head node.

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

    Love u Sir Best teacher ever

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

    Thanks.... Great way of teaching.
    🙏🙏🙏🙏

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

    I always struggle to understand about linked list and pointer. I got my aha moment because of this video and the previous one about linked list in c/c++. Thank you

  • @irwincayo2725
    @irwincayo2725 7 років тому

    5:45 , since global variable head value is being changed inside of the function then head = temp only while inside the function right? Once the function is over, wouldn't head = NULL again? I thought you couldn't permanently change the value of a global variable inside of a function unless you pass by reference? I've just started programming on my own so sorry for the ignorance if I'm wrong.

  • @joeyvico
    @joeyvico 7 років тому

    Shouldn't there be a free() call somewhere after the malloc call? If so, where should it be placed?

  • @陳Y-p1g
    @陳Y-p1g 6 років тому

    Do I need to use delete() while I practice the sample??

  • @tushargoel5522
    @tushargoel5522 11 років тому

    Thanks for quick response..I resolved the issue. I forgot to initialize the struct to the starting point before printing it.. I spend several hours on ths but havent care abt it earlier.

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

    The perils of C!
    My memories of high school C are rather less convoluted.

  • @EntertainerOnline
    @EntertainerOnline 9 років тому

    which compiler are you using....?

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

    If you typedef the struct Node, then you can skip the struct on Node *next right?

  • @RajatJoshiChannel
    @RajatJoshiChannel 9 років тому +2

    few queries...
    1. Why do we require head? Can't we store and use the address of 1st node directly?
    2. Why does the new node gets added at the beginning of the list?

    • @advaitharmy
      @advaitharmy 7 років тому +5

      1) To clarify you 1st node does not has address of 1st node. 1st node will have address of 2nd node, 2nd node will have address of 3rd node.......etc. Head has the address of 1st node. S0 if you use address of 1st node you will get elements from node 2 onwards and you are missing 1st node itself. I hope you understood now.
      2) Node can be added to any location.

  • @tawhidurrahman1764
    @tawhidurrahman1764 9 років тому +12

    shouldn't we use free function here?

    • @Dark-ur4wl
      @Dark-ur4wl 4 роки тому

      Yes you should delete all temps and the whole linked list at the end of the program.

  • @SathishBatsy
    @SathishBatsy 8 років тому +2

    why do we need to collect the head 11:26 . isn't it call by reference. doesnt the values updated in its address by function itself. someone clarify my doubt

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

      You should see the lectures for *variable* *scope* .....
      Once you understand it , you won't ask it again!

  • @nolimangulabnan6101
    @nolimangulabnan6101 7 років тому

    @line head=temp .... is it the address of the first node (100) stored in the head? or is it the copy of temp stored to head which is pointing to null??

  • @Nurafnieka
    @Nurafnieka 11 років тому +3

    Can I get the source code?

  • @ashishmohanan3056
    @ashishmohanan3056 9 років тому

    is it necessary to initialize head inside the main or can we do it outside the main?

  • @agrawalsweety3961
    @agrawalsweety3961 10 років тому

    please upload boolean algebra if posiible as soon as possible....... and your videos are just awesome..thanks a lot....

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

    Sir, which compiler you have used in this video?

  • @srkrohit
    @srkrohit 9 років тому +2

    Thank you so much for the video. Very nicely explained.

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

    Thanks for the lesson its really helping me to usderstand the concept of linked list

  • @ShekharBhabad
    @ShekharBhabad 10 років тому

    keep doing man ......your videos are just awesome.......and much much helpfull

  • @shalinichatterjee4038
    @shalinichatterjee4038 10 років тому

    This programme is not being compiled in both TURBO C & CODEBLOCKS..its giving an error for that line where u used the malloc func...what should i do??plz suggest me.....

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

    OMG.
    Are you GOD of pointer?
    How can you understand pointer so fucking well...
    It was so cooooooooooooooooooooolllllllllllllllll.
    BTW, thank you ....

  • @shijithms5049
    @shijithms5049 7 років тому

    Which IDE is used in the video to write the c code ????

  • @rupaliroychoudhury2300
    @rupaliroychoudhury2300 9 років тому

    What are the advantages and disadvantages of declaring struct node * head locally? Is it bad in terms of memory?

  • @deepakbelani1573
    @deepakbelani1573 7 років тому

    which compiler(software) do u use???

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

    bro everything else is working fine...but I am not getting the list of numbers I have inserted in output..I am using TURBO C compiler....can u plz help me out with that......

  • @amananand2556
    @amananand2556 9 років тому

    Since head is also a pointer for struct node, won't it also have a field for data? Also why didn't we use the malloc function while creating temp inside print().

  • @testacc9381
    @testacc9381 10 років тому

    One professor at my college used this function to insert=> void addbeg(node ** start,int x)... can u please explain why pointer to pointer,or how it works?

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

    4:51

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

    We can simply insert the elements without using the if statement
    struct node* head=NULL;
    void print(int x)
    {
    struct node *temp=(struct node*)malloc(sizeof(struct node));
    temp->data=x;
    temp->next=head;//here the temp will be pointed to NULL and then to the next element.
    head=temp;//The head is again updated here.
    }

  • @GaganDeep-xz8kf
    @GaganDeep-xz8kf 4 роки тому

    sir at '7:57'... i hav a doubt that what is temp variable containing.....? Is it adderess of head node or that that adderess which head node is containing.
    please answr sir
    thankyou for reading .

  • @ankitsharma8221
    @ankitsharma8221 7 років тому

    What IDE are you using?

  • @simrandhamija8763
    @simrandhamija8763 8 років тому

    at 6:56 why is it written "temp->next = head;"? what does it do?

  • @usama57926
    @usama57926 6 років тому +3

    great explanation

  • @shashankmishra484
    @shashankmishra484 9 років тому +3

    Where are you compiling your code? i am getting multiple errors for this code
    plz send a link for your platform

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

      www.mycodeschool.com/problems/insert-a-node-in-a-linked-list-at-head

  • @AmanGupta-jj6jx
    @AmanGupta-jj6jx 7 років тому +2

    Do I need to clear memory which you allocated to temp. I need to make sure no memory is lost. Please tell what I can do?

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

      phkkk auff

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

      Pointer variable Temp is defined inside functions only i.e Insert and Print functions. They remain alive for a short duration i.e. memory for function variables is assigned in Stack when a function call is made & de-allocated as soon as function call is over.
      Though the nodes (which Temp pointer variables are pointing to) are allocated memory in Heap section of memory. These nodes in heap memory have to be manually de-allocated.
      Check his another video on Stack vs Heap memory.

  • @vishalmishra1937
    @vishalmishra1937 7 років тому

    sir is the address of head in memory will be differnt or same as that of node