Doubly Linked List (Deleting the Last Node)

preview_player
Показать описание
Data Structures: Deleting the Last Node of a Doubly Linked List
Topics discussed:
1) C program for deleting the last node of a doubly linked list.

Music:
Axol x Alex Skrindo - You [NCS Release]

#DataStructuresByNeso #DataStructures #DoublyLinkedList #LinkedList
Рекомендации по теме
Комментарии
Автор

method 2 is also there which is same as the method 2 of the deleting the first node
....

thank you sir

VikashSinghYT
Автор

we want c++ also sir..please upload as soon as possible

asishgokarakonda
Автор

There is also a method that we don't need to create an extra pointer :

struct node *ptr = head;


            ptr = ptr->next;

        free(ptr->next);
        ptr->next = NULL;

        return head;

dipeshsamrawat
Автор

while(temp->next!=NULL)
{
temp=temp->next;
}
temp->prev->next=NULL;
free(temp) ;
Is this correct sir?
Thank you so much❤❤.

mihirvora
Автор

I have found every videos of yours is very useful, mainly ur os classes are pretty much helpful and structure part in c... i am following your channel sine 2018.. but from my 1st account and its my 2nd account. And i want to please upload the videos on computer graphics...

hunterkhan
Автор

find it so much more intuitive to use one temp node. Using two node is like throwing complex hand signs

SaywhateverI
Автор

Can we do it like :
While(temp->next->next != NULL)
And then delete the last node
Is it possible?

ThakkarSelvi
Автор

Is this correct sir ?

void delLast(struct node *head) {
struct node *temp=head;

temp=temp->next;
free(temp->next);
temp->next=NULL;
}

SauravKumar-ywkw
Автор

At 1:33
Sir why you passed Null to temp after freeing it. Is it necessary to do?

PROTECHRAHUL
Автор

Can't i use the head pointer only to delete the last node?
Free(head->next->next);
Head->next->next=NULL;
Is this correct?

amishakadu
Автор

Sir, I have completed learning c and data structures.(by your videos).I am 1st year cse student.(still the class haven't begin). Is this enough sir. Will start practicing in hackkerank from tomorrow.🙏🙏🙏 is this enough before college starts. Kindly reply sir.🙏🙏🙏🙏🙏🙏

dhayalanm
Автор

As we know the Node * head is local to the function, we can write

void deleteLast(Node *head){
while(head->next != NULL)
head=head->next;
head->prev->next=NULL;
free(head);
}

krb
Автор

Here is function uses single pointer


void delete_last(node *head)
{
node *tmp = head;

if(!head){
puts("List is already empty"); return;}

else if(!head->next){
puts("The list contains one node only"); return;}

else
{
while(tmp->next->next) tmp = tmp->next;
free(tmp->next);
tmp->next = NULL;
}
tmp = NULL;
return;
}

accessdenied
Автор

I tried with using one pointer.
while(pointer->next->next != NULL) and then using free(pointer->next->next) and the pointer->next = NULL. this too deleted the last node.
Is it right or I'm missing something?

MKSundaram
Автор

It has to be return head for delast function

pragnabheemaneni
Автор

node *delL(node *head){
if(head==NULL){
cout<<"DLL is empty! ";
}
else{
node *p=head;
while(p->next->next != NULL){
p=p->next;
}
delete [] p->next;
p->next=NULL;
}
return head;
}

the above code is correct or not?

nitishdiwakar