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

  Рет қаралды 113,382

Neso Academy

Neso Academy

Күн бұрын

Data Structures: Inserting a Node in between the Nodes of a Doubly Linked List
Topics discussed:
1) C program for inserting a node after the given position in a doubly linked list.
2) addAfterPos function.
Data Structures: bit.ly/3hjudFV
C Programming: goo.gl/7Eh2SS
Follow Neso Academy on Instagram: @nesoacademy(bit.ly/2XP63OE)
Follow me on Instagram: @jaspreetedu(bit.ly/2YX26E5)
Contribute: www.nesoacademy.org/donate
Memberships: bit.ly/2U7YSPI
Books: www.nesoacademy.org/recommende...
Website ► www.nesoacademy.org/
Forum ► forum.nesoacademy.org/
Facebook ► goo.gl/Nt0PmB
Twitter ► / nesoacademy
Music:
Axol x Alex Skrindo - You [NCS Release]
#DataStructuresByNeso #DataStructures #DoublyLinkedList #LinkedList

Пікірлер: 43
@bertinaagnes73
@bertinaagnes73 3 жыл бұрын
Please do upload it completely, this series is gonna save my life.
@prateekbaheti8236
@prateekbaheti8236 3 жыл бұрын
One of the best series I have ever watched on KZbin to learn topics related to CSE. Sir, please organise live interaction sessions.
@CodeCampus_1
@CodeCampus_1 3 жыл бұрын
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 KZbin ❤❤
@zafdell8170
@zafdell8170 3 жыл бұрын
Yes really need this type of content
@balakrishnaprasad8928
@balakrishnaprasad8928 3 жыл бұрын
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 Жыл бұрын
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 2 жыл бұрын
I love Neso Academy :)
@YashKumar-br5xi
@YashKumar-br5xi Жыл бұрын
gigantic amount of help we are receiving only because of your mindset and your beliefs
@tejatej3628
@tejatej3628 3 жыл бұрын
Thank 🙏💕u sir. Plz upload the videos fastly...
@aniketmasram6500
@aniketmasram6500 2 жыл бұрын
Thnks a lot for this 🙏🏻🙏🏻🙏🏻
@anishlowanshi7766
@anishlowanshi7766 Жыл бұрын
Thank you ❤️
@user-ge3lm3mf5p
@user-ge3lm3mf5p Жыл бұрын
much obliged to you sir
@gulabpatel1249
@gulabpatel1249 3 жыл бұрын
Sir while loop will be become infinite loop am i right...
@DILESHCHURIWAL
@DILESHCHURIWAL Ай бұрын
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.
@okenk.6379
@okenk.6379 4 ай бұрын
at 3:36 shouldn't the prev node fore newP be linked to the next node of the temp?
@golamkibria4310
@golamkibria4310 10 ай бұрын
Dear sir, why do we need to newP=addToEmpty(newP,data).instead of this malloc for newP
@vijaygarothaya6673
@vijaygarothaya6673 2 жыл бұрын
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
@siphethonyambi441
@siphethonyambi441 3 жыл бұрын
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 жыл бұрын
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
@madhuritolambe898
@madhuritolambe898 3 жыл бұрын
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 Жыл бұрын
You explained very well but you didn't discuss any corner cases
@soumayadahel8989
@soumayadahel8989 2 жыл бұрын
i didn't understand the part of 'position -- ' any help pls?
@rockstarCoolz
@rockstarCoolz Жыл бұрын
🙏🙏🙏🔥
@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
@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. ?
@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 жыл бұрын
@@harshalkumar4538 thank you so much😊
@lawn_mower4941
@lawn_mower4941 3 жыл бұрын
that's because the sequence of pointer updations is wrong
@mohamedimadeddinefaoussi6966
@mohamedimadeddinefaoussi6966 7 ай бұрын
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 жыл бұрын
which softeware sir used plzz anyone tell me
@AishLovesSpaghetti
@AishLovesSpaghetti 3 жыл бұрын
Code blocks
@tahreemriaz2401
@tahreemriaz2401 3 жыл бұрын
@@AishLovesSpaghetti thank you so much😊
@user-el7ol6kg4o
@user-el7ol6kg4o 5 ай бұрын
me watching night before exam
@CodeCampus_1
@CodeCampus_1 3 жыл бұрын
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 3 жыл бұрын
Try English. Hindi aati hogi kya usko?
@CodeCampus_1
@CodeCampus_1 3 жыл бұрын
@@sayemaroyali3100 may be ati ho😁😅
@keshavramvishvakarma9100
@keshavramvishvakarma9100 3 жыл бұрын
NewP = addToEmpty(newP , data) In this line why newP is pass???
@duanedsilva3573
@duanedsilva3573 3 жыл бұрын
bcus the function return value is saved. hence it can be pass by value
@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; }
Doubly Linked List (Insertion between the Nodes) - Part 2
5:09
Neso Academy
Рет қаралды 53 М.
Learn Linked Lists in 13 minutes 🔗
13:24
Bro Code
Рет қаралды 275 М.
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 29 МЛН
Inside Out 2: Who is the strongest? Joy vs Envy vs Anger #shorts #animation
00:22
لقد سرقت حلوى القطن بشكل خفي لأصنع مصاصة🤫😎
00:33
Cool Tool SHORTS Arabic
Рет қаралды 27 МЛН
every good programmer should know how to code this data structure (its easy)
21:08
Doubly Linked List | Insert, Delete, Complexity Analysis
17:17
Blue Tree Code
Рет қаралды 65 М.
Reverse a Single Linked List
11:57
Neso Academy
Рет қаралды 250 М.
Doubly Linked List (Insertion at the End)
4:22
Neso Academy
Рет қаралды 99 М.
Linked Lists for Technical Interviews - Full Course
1:27:24
freeCodeCamp.org
Рет қаралды 351 М.
How to Create a Linked List C++ Introduction to Linked Lists
12:24
Paul Programming
Рет қаралды 923 М.
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 29 МЛН