Doubly Linked List(DLL) deletion operation, Delete functions/algorithms

Deletion:- To remove an element from a given Singly Linked List is known as Deletion. It is of four types-
डिलीशन:- डबली लिंक्ड लिस्ट से किसी एलिमेंट को हटाना, डिलीशन कहलाता है। यह चार प्रकार से किया जा सकता है- 
a) Delete first node (पहला नोड हटाना )
 
//Delete First Node from DLL
void deletefirstdll(){
clrscr();
if(first==NULL){
printf("Underflow Condition\n");
getch();
return;
}
n=first;
if(first->next==NULL){
first=last=NULL;}
else{
first=first->next;
first->back=NULL;}
printf("first node %d is deleted\n",n->info);
getch();
free(n);
return;
}

b) Delete last node (अंतिम नोड हटाना)

//Delete Last Node from DLL
void deletelastdll(){
clrscr();
if(last==NULL){
printf("Underflow Condition\n");
getch();
return;
}
n=last;
if(last->back==NULL){
first=last=NULL;}
else{
last=last->back;
last->next=NULL;}
printf("last node %d is deleted\n",n->info);
getch();
free(n);
return;
}

c) Delete a node after given location (किसी दी गयी स्थिति के पश्चात नोड को हटाना)
 
//Delete a Node after given Location from DLL
void deleteafterlocdll(NODE *loc){
clrscr();
if(first==NULL){
printf("Underflow Condition\n");
getch();
return;
}
if(loc==last){
printf("loc is last node\ndeletion is not possible\n");
getch();
return;
}
if(loc->next=last){
printf("location is second last node\nChoose option delete last node in dll\n");
getch();
return;
}
else{
n=loc->next;
loc->next->next->back=loc;
loc->next=loc->next->next;
}
printf("Node= %d after given location  is deleted\n",n->info);
getch();
free(n);
return;
}
 
d) Delete a node before given location  (किसी दी गयी स्थिति के पुर्व नोड को हटाना)

//Delete a Node before given Location from DLL
void deletebeforelocdll(NODE *loc){
if(last==NULL){
printf("Underflow Condition\n");
getch();
return;
}
if(loc==first){
printf("loc is first node\ndeletion is not possible\n");
getch();
return;
}
if(loc->back=first){
printf("location is second node\nChoose option delete first node in dll\n");
getch();
return;
}
else{
n=loc->back;
loc->back->back->next=loc;
loc->back=loc->back->back;
printf("Node= %d before given location  is deleted\n",n->info);
getch();
free(n);
return;
}

No comments:

Post a Comment

Priority Queue

Priority queue:-  It is a special type of queue which stores group of elements. Each element has a priority number associated with it. Prior...