Doubly Linked List (Insertion between the Nodes) - Part 1

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

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

  • @bertinaagnes73
    @bertinaagnes73 4 года назад +32

    Please do upload it completely, this series is gonna save my life.

  • @prateekbaheti8236
    @prateekbaheti8236 4 года назад +14

    One of the best series I have ever watched on RUclips to learn topics related to CSE. Sir, please organise live interaction sessions.

  • @CodeCampus_1
    @CodeCampus_1 4 года назад +21

    Sir please upload all the video of the Ds algo
    I have to give my semester exam
    And you really explained too good I am getting all you explained
    Please upload all topics asap
    Best Ds lecture on RUclips ❤❤

    • @zafdell8170
      @zafdell8170 4 года назад +2

      Yes really need this type of content

  • @balakrishnaprasad8928
    @balakrishnaprasad8928 4 года назад +7

    Please upload the dsa videos as fast as possible because our exams are coming . We know that you are keeping complete efforts on making a video not only video to clear concept .

  • @mohammedafnanshariff3142
    @mohammedafnanshariff3142 Год назад +1

    Thank you so much sir. I wish you and your family good health and loads of happiness. Thank you again for this wonderful work!

  • @dipeshsamrawat7957
    @dipeshsamrawat7957 3 года назад +3

    I love Neso Academy :)

  • @YashKumar-br5xi
    @YashKumar-br5xi 2 года назад

    gigantic amount of help we are receiving only because of your mindset and your beliefs

  • @vijaygarothaya6673
    @vijaygarothaya6673 3 года назад +5

    This can be done by one more option:
    Assume doubly link list like below
    head-> N1 -> N2 -> N3 -> N4
    Suppose we need to add NX after N2
    1. Traverse thru list to reach N2.
    Call N2 as currentNode.
    2. Add NX between N2 and N3
    NX.prev = currentNode
    NX.next = currentNode.next
    currentNode.next = NX
    NX.next.prev = NX

  • @DILESHCHURIWAL
    @DILESHCHURIWAL 3 месяца назад

    We can also do it without temp2 pointer.
    newP->next = temp->next;
    temp->next->prev = newP;
    temp->next = newP;
    newP->prev = temp;
    Also we should check the condition if(temp->next==NULL) before this.

  • @tejatej3628
    @tejatej3628 4 года назад +2

    Thank 🙏💕u sir.
    Plz upload the videos fastly...

  • @gulabpatel1249
    @gulabpatel1249 4 года назад +3

    Sir while loop will be become infinite loop am i right...

  • @成成成-b1q
    @成成成-b1q Год назад

    much obliged to you sir

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

    why not use *head instead of *temp to reduce the number of pointers you're using since head is difined as a local variable inside your function?

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

      you cant change where head is pointing. head must always point to first node, thats why you can only traverse using head and not update

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

    Thnks a lot for this 🙏🏻🙏🏻🙏🏻

  • @CodeCampus_1
    @CodeCampus_1 4 года назад +2

    Sir please jaldi upload krdo sara course sem kaa exam dena hai kuch nhi padha hai
    Poora DS padna hai
    aur apne sach me kafhi acha explain kiya hai
    Please jaldi upload kr do whole course ✌✌

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

      Try English.
      Hindi aati hogi kya usko?

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

      @@sayemaroyali3100 may be ati ho😁😅

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

    Thank you ❤️

  • @golamkibria4310
    @golamkibria4310 Год назад

    Dear sir,
    why do we need to newP=addToEmpty(newP,data).instead of this malloc for newP

  • @madhuritolambe898
    @madhuritolambe898 3 года назад +2

    sir can we implement this using only one ptr i.e temp only... rather than both temp and temp2?

    • @AnkitYadav-sc2sm
      @AnkitYadav-sc2sm 3 года назад

      Yes👍

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

      //insert at any position except last
      myNode* add_at_any_pos(myNode *head, int data, int pos){
      myNode *ptr = NULL;
      myNode *temp = head;
      if(pos == 1)
      add_at_beg(&head, data);
      else if(pos == (no_of_nodes(head) + 1))
      printf("Invalid Position
      ");
      else{
      ptr = malloc(sizeof(myNode));
      ptr->prev = NULL;
      ptr->data = data;
      ptr->next = NULL;

      pos--;
      // change temp if pos > 2 else below
      while(--pos){
      temp = temp->next;
      }
      temp->next->prev = ptr;
      ptr->next = temp->next;
      temp->next = ptr;
      ptr->prev = temp;
      }
      return head;
      }

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

    You explained very well but you didn't discuss any corner cases

  • @okenk.6379
    @okenk.6379 7 месяцев назад

    at 3:36 shouldn't the prev node fore newP be linked to the next node of the temp?

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

    Whether I want to avoid the newp=addtoempty(newp,data) . What should i write? it will work with temp->data or temp2->data. ?

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

    dear sir,
    will you please explain me about doubly linked list using strings?
    thank you.

    • @ritvikreddy3959
      @ritvikreddy3959 Год назад

      hey it is simple just replace the int data to char data[size of string] and use %s while taking the input i.e in scanf

  • @mohamedimadeddinefaoussi6966
    @mohamedimadeddinefaoussi6966 10 месяцев назад

    in case the position is out of range , this case should return NULL because we can't add the node in an out of range position

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

    I am using dev c++
    i write same code on dev, but something went wrong
    soo plz tell me which software you use
    or also if i use dev c++ , so what's i change in my program

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

      he's using codeblocks

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

      @@harshalkumar4538 thank you so much😊

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

      that's because the sequence of pointer updations is wrong

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

    i didn't understand the part of 'position -- ' any help pls?

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

    which softeware sir used
    plzz anyone tell me

  • @ATHULSHA-i9b
    @ATHULSHA-i9b 7 месяцев назад

    me watching night before exam

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

    NewP = addToEmpty(newP , data)
    In this line why newP is pass???

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

      bcus the function return value is saved. hence it can be pass by value

  • @rockstarCoolz
    @rockstarCoolz Год назад

    🙏🙏🙏🔥

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

    Sir i have written source code same as yours but got an error on codeblocks.
    Error:
    Process returned -1073741819 (0xC0000005) execution time : 0.896 s
    Press any key to continue.
    nothing is printing on console could you resolve this problem as soon as possible as all the things are exact same and even rechecked three times i am not getting it, I am attaching source code even for your consideration i will wait for your response. #include
    #include
    #include
    struct branch
    {
    struct branch* prev;
    int data;
    struct branch* next;
    };
    struct branch* inserttoempty(struct branch* head,int data)
    {
    struct branch* temp = (struct branch*)malloc(sizeof(struct branch));
    temp->prev = NULL;
    temp->data = data;
    temp->next = NULL;
    head = temp;
    return head;
    };
    struct branch* insertinbeg(struct branch* head, int value)
    {
    struct branch* newnode = (struct branch*)malloc(sizeof(struct branch));
    newnode->prev = NULL;
    newnode->data = value;
    newnode->next = head;
    head->prev = newnode;
    head = newnode;
    return head;
    };
    struct branch* insertatend(struct branch* head,int value1)
    {
    struct branch* trav;
    struct branch* newnode = (struct branch*)malloc(sizeof(struct branch));
    trav = head;
    newnode->prev = NULL;
    newnode->data = value1;
    newnode->next = NULL;
    while(trav->next!=NULL)
    {
    trav = trav->next;
    }
    trav->next = newnode;
    newnode->prev = trav;
    return head;
    };
    struct branch* addbeforepos(struct branch* head,int data,int position)
    {
    struct branch* newP = NULL;
    struct branch* temp = head;
    struct branch* temp2 = NULL;
    if(head==NULL)
    {
    newP = inserttoempty(newP, data);
    }
    int pos = position;
    while(pos>2)
    {
    temp = temp->next;
    pos--;
    }
    if(position==1)
    {
    insertinbeg(head,data);
    }
    else
    {
    temp2 = temp->next;
    temp->next = newP;
    temp2->prev = newP;
    newP->next = temp2;
    newP->prev = temp;
    }
    return head;
    };
    int main()
    {
    struct branch* head = NULL;
    struct branch* ptr;
    int position = 2;
    head = inserttoempty(head,45);
    head = insertinbeg(head ,98);
    head = insertatend(head,3);
    head = addbeforepos(head,56,position);
    ptr = head;
    while(ptr!=NULL)
    {
    printf("%d",ptr->data);
    ptr = ptr->next;
    }
    return 0;
    }