Doubly Linked List (Insertion at the End)

  Рет қаралды 103,390

Neso Academy

Neso Academy

Күн бұрын

Пікірлер: 49
@mihirvora391
@mihirvora391 3 жыл бұрын
So simple to understand after seeing singly linked list lectures. Thank you❤❤
@Anurag_singh51
@Anurag_singh51 3 жыл бұрын
my favourite channel....NESO ACADEMY
@satvikshukla596
@satvikshukla596 3 жыл бұрын
This looks soo simple, bcoz you taught it soo well. Thank you
@SumedhaChallagundla
@SumedhaChallagundla 6 ай бұрын
Helped a lot. Thank you so much sir😊😊
@rnmali4243
@rnmali4243 2 жыл бұрын
Clean and clear 🔥
@sabbysays
@sabbysays 3 жыл бұрын
Thanks a ton sir! Please try increasing upload frequency.
@tahirnawaz9821
@tahirnawaz9821 2 жыл бұрын
Thank you sir very helpful video God bless you, amazing concept,, keep it up,,.
@kiranhaya9099
@kiranhaya9099 3 жыл бұрын
My favourite channel and my favourite Sir....What is the name of the sir?
@sr-sunny-raj
@sr-sunny-raj 3 жыл бұрын
Greatttt🔥🔥🔥🔥🔥
@dipeshsamrawat7957
@dipeshsamrawat7957 3 жыл бұрын
I love Neso Academy :)
@01.abhishekkumar33
@01.abhishekkumar33 3 жыл бұрын
Outstanding lecture
@elhadimohamed1336
@elhadimohamed1336 3 жыл бұрын
You're the best ✌️
@PROTECHRAHUL
@PROTECHRAHUL 3 жыл бұрын
U r genius sir😍
@boblopez7649
@boblopez7649 Жыл бұрын
node_t * add_new_node(int data , node_t *ptr) { node_t *temp=(node_t*)malloc(sizeof(node_t)); temp->data=data; temp->next=NULL; temp->prev=ptr; ptr->next=temp; return temp; } I think using this would reduce time complexity cuz there is no loop ....
@tahirnawaz9821
@tahirnawaz9821 2 жыл бұрын
Thanks a lot sir love you,,.
@aashishbhatt4888
@aashishbhatt4888 3 жыл бұрын
Please upload videos fast
@sonysayannagari2889
@sonysayannagari2889 3 жыл бұрын
In addAtEnd function, head is not getting changed right..so we can just delclare addAtEnd function of void type right?
@shivp436
@shivp436 3 жыл бұрын
Head is not getting changed yes, you can make it void. But if you want to keep a pointer tp pointing at the last node of the list.. which is helpful when you add next node, you should return the updated pointer .. so you can't make it void.. If you still want to make it void. You can use call by reference method
@Dnsx_plus
@Dnsx_plus 3 жыл бұрын
No need to return anything, makes no difference for this method of inserting a node at the end look at this: #include #include #include // Not required, just like importing this library typedef struct node{ struct node * prev; int data; struct node * next; }Node; Node * AddNodeToEmptyList(Node* Head, int Data) { // Initializes Head Pointer Node * temp = (Node*)malloc(sizeof(Node)); temp -> prev = NULL; temp -> data = Data; temp -> next = NULL; Head=temp; return Head; } Node * AddNodeAtBeginning(Node* Head, int Data) { // Inserts node in the beginning, taking place as a new head Node * Temp = (Node*)malloc(sizeof(Node)); Temp->prev = NULL; Temp->data = Data; Temp->next = Head; Head->prev = Temp; Head->next = NULL; Head=Temp; // Have to change where the head is pointing, it has to point to the new updated node, which // Was added at the beginning, so the old node has to be updated and the Head pointer will point to the // Newely added node. return Head; } void AddNoteAtEnd(Node* Head, int Data) {// Adds a Node at the end of the Linked List Node* Temp = Head; while(Temp->next != NULL) { Temp = Temp->next; } printf("Last node's value: %d", Temp->data); Node* NewNode = (Node*)malloc(sizeof(Node)); NewNode->prev = Temp; NewNode->data = Data; NewNode->next = NULL; Temp->next = NewNode; Temp = Head; while(Temp != NULL) { printf(" Node data: %d ", Temp->data); Temp = Temp->next; } // return Head; } int main() { /* Unlike a single-linked list a double linked list's node consists of two pointer, one for the previous node, the next, and the data segment. This is good news since now we can access the previous and next node in the linked list. */ Node * Head = AddNodeToEmptyList(Head, 2); Head = AddNodeAtBeginning(Head, 1); // Head = AddNoteAtEnd(Head, 3); // Head = AddNoteAtEnd(Head, 4); AddNoteAtEnd(Head, 3); AddNoteAtEnd(Head, 4); free(Head); Head = NULL; return 0; }
@techknowgemes7860
@techknowgemes7860 3 жыл бұрын
sir do we need to write ptr-next for traversing ??
@Ashhlleeeeyyy
@Ashhlleeeeyyy 11 ай бұрын
why is all nodes named head?????? just name the other 2 current
@mr_blaze62
@mr_blaze62 3 жыл бұрын
Thank you sir❤️
@subhajitchoudhury4981
@subhajitchoudhury4981 2 жыл бұрын
i love you NESO you are not in earth
@kashafrafique0508
@kashafrafique0508 Жыл бұрын
Thankuuu sir
@BiqSam2002
@BiqSam2002 Ай бұрын
Neso Academic is my college
@janhvitolambe3331
@janhvitolambe3331 3 жыл бұрын
Sir please upload complete series of ds.... It's kind request plz sir🤞✨
@nesoacademy
@nesoacademy 3 жыл бұрын
Yes, we're creating the videos regularly and soon the course will be over.
@janhvitolambe3331
@janhvitolambe3331 3 жыл бұрын
@@nesoacademy okay sir ji😁
@Dnsx_plus
@Dnsx_plus 3 жыл бұрын
@@nesoacademy good job
@himaldangi9399
@himaldangi9399 4 ай бұрын
Also post algorithm
@abdokako3883
@abdokako3883 3 жыл бұрын
we hope course for c++ or data structure & algorithms & Design patterns with c++
@anshikayadav7857
@anshikayadav7857 3 жыл бұрын
Sir please explain this:- We're using "struct node *_____; " so this means ___ will contain data & link too. So whenever we're creating any new pointer why don't we use int. Because if we're using struct node * then everytime it'll create a new node due to struct node data type. Please explain anyone can do so please.
@shivp436
@shivp436 3 жыл бұрын
When we use struct node *x; It just creates a pointer to some non existing memory location; it does not allocate any memory or link; To allocate memory , we use the malloc function. And our pointer x automatically links to the allocated memory location. Hope this helps you.
@anshikayadav7857
@anshikayadav7857 3 жыл бұрын
@@shivp436 Thankyou
@ayushanand4990
@ayushanand4990 3 жыл бұрын
when will u sum up the course
@Dnsx_plus
@Dnsx_plus 3 жыл бұрын
Wrote my own version before watching the video, let's hope I did it right! #include #include #include // Not required, just like importing this library typedef struct node{ struct node * prev; int data; struct node * next; }Node; Node * AddNodeToEmptyList(Node* Head, int Data) { // Initializes Head Pointer Node * temp = (Node*)malloc(sizeof(Node)); temp -> prev = NULL; temp -> data = Data; temp -> next = NULL; Head=temp; return Head; } Node * AddNodeAtBeginning(Node* Head, int Data) { // Inserts node in the beginning, taking place as a new head Node * Temp = (Node*)malloc(sizeof(Node)); Temp->prev = NULL; Temp->data = Data; Temp->next = Head; Head->prev = Temp; Head->next = NULL; Head=Temp; // Have to change where the head is pointing, it has to point to the new updated node, which // Was added at the beginning, so the old node has to be updated and the Head pointer will point to the // Newely added node. return Head; } Node * AddNoteAtEnd(Node* Head, int Data) {// Adds a Node at the end of the Linked List Node* Temp = Head; while(Temp->next != NULL) { Temp = Temp->next; } printf("Last node's value: %d", Temp->data); Node* NewNode = (Node*)malloc(sizeof(Node)); NewNode->prev = Temp; NewNode->data = Data; NewNode->next = NULL; Temp->next = NewNode; Temp = Head; while(Temp != NULL) { printf(" Node data: %d ", Temp->data); Temp = Temp->next; } return Head; } int main() { /* Unlike a single-linked list a double linked list's node consists of two pointer, one for the previous node, the next, and the data segment. This is good news since now we can access the previous and next node in the linked list. */ Node * Head = AddNodeToEmptyList(Head, 2); Head = AddNodeAtBeginning(Head, 1); Head = AddNoteAtEnd(Head, 3); Head = AddNoteAtEnd(Head, 4); free(Head); Head = NULL; return 0; }
@reverbism
@reverbism 2 жыл бұрын
Noice
@divinitygod6002
@divinitygod6002 Жыл бұрын
This malloc goes over my head...... c++ is easier. we just use "new" variable for that whole gunk.
@xkostmand6257
@xkostmand6257 2 жыл бұрын
at 1:45 , would this work? temp->prev=&(tp->next);
@Ayush37262
@Ayush37262 Жыл бұрын
That Worked?? I think it shouldn't work...
@meditationmusicforpositive8798
@meditationmusicforpositive8798 3 жыл бұрын
where do I get the code of all these ?
@ritikshrivastava9442
@ritikshrivastava9442 3 жыл бұрын
//insertion at the end of the doubly linked list #include #include struct node{ struct node *prev; int data; struct node *next; }; struct node * add_at_beg(struct node *head, int data) { struct node *temp = malloc(sizeof(struct node)); temp->prev=NULL; temp->data=data; temp->next=head; head->prev=temp; head=temp; return head; } void add_at_end(struct node * head, int data) { struct node *temp2 = malloc(sizeof(struct node)); temp2->prev=NULL; temp2->data=data; temp2->next=NULL; struct node *trav=head; while(trav->next!=NULL) { trav=trav->next; } trav->next=temp2; temp2->prev=trav; } int main() { struct node *head=malloc(sizeof(struct node)); head->prev=NULL; head->data=45; head->next=NULL; head=add_at_beg(head,58); add_at_end(head,89); struct node *ptr=head; while(ptr!=NULL) { printf("%d ",ptr->data); ptr=ptr->next; } return 0; }
@vaibhavsingh335
@vaibhavsingh335 3 жыл бұрын
Sir how to convert y parameter to h parameter ,plz sir
@coders8180
@coders8180 3 жыл бұрын
i don't undestand why we are using *tp in place of tp...may u plz make me this to be understable
@luthfiardiansyah8530
@luthfiardiansyah8530 3 жыл бұрын
I think *tp same as the iterator
@harikpriyatirumalaraju674
@harikpriyatirumalaraju674 3 жыл бұрын
PLS make video on QUICK SORT AND MERGE SORT
@bhupeshpattanaik7150
@bhupeshpattanaik7150 3 жыл бұрын
Please bring videos more frequently , as I can't follow along the syllabus ..... Your videos coming very slow
@YZ1000
@YZ1000 3 жыл бұрын
sir i am getting segmentation fault (core dumped) error even though the code is 100% similar , what to do 🤔
@hustlinhr
@hustlinhr Жыл бұрын
Bhai code hi glt h to error to aaiga hi glt code h iska
Doubly Linked List (Insertion between the Nodes) - Part 1
6:19
Neso Academy
Рет қаралды 116 М.
Doubly Linked List | Insert, Delete, Complexity Analysis
17:17
Blue Tree Code
Рет қаралды 65 М.
Gli occhiali da sole non mi hanno coperto! 😎
00:13
Senza Limiti
Рет қаралды 24 МЛН
Doubly Linked List (Deleting the First Node)
3:36
Neso Academy
Рет қаралды 74 М.
Creating the Node of a Single Linked List
6:00
Neso Academy
Рет қаралды 1 МЛН
Insert node at the end of a Doubly Linked List in Java
10:26
Dinesh Varyani
Рет қаралды 28 М.
Doubly Linked List - Implementation in C/C++
15:21
mycodeschool
Рет қаралды 584 М.