Singly Linked List (SLL) Deletion operation and their types, 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 SLL
void deletefirstsll(){
clrscr();
n=start;
if(n==NULL){
printf("Underflow Condition\n");
getch();
return;
}
if(start->link==NULL){
start=NULL;}
else{
start=start->link;
}
printf("First Node Deleted\n");
getch();
free(n);
return;
}

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

//Delete Last Node from SLL
void deletelastsll(){
NODE *temp=start;
clrscr();
if(start==NULL){
printf("Underflow Condition\n");
getch();
return;
}
if(start->link==NULL){
n=start;
start=NULL;}
else{
while(temp->link->link!=NULL){
temp=temp->link;
}
n=temp->link;
temp->link=NULL;
}
printf("last Node Deleted\n");
getch();
free(n);
return;
}

c) Delete a node after given location (किसी दी गयी स्थिति के पश्चात नोड को हटाना)

//Delete a Node after given Location from SLL
void deleteafterlocsll(NODE *loc){
clrscr();
if(start==NULL){
printf("Underflow Condition\n");
getch();
return;
}
if(loc->link== NULL){
printf("Location is Last Node\ndeletion will not perform here\n");
getch();
return;
}
if(loc->link->link==NULL){
printf(" Choose option delete last node in SLL\n");
getch();
return;
}
else{
n=loc->link;
loc->link=loc->link->link;
}
printf("Node after given location is deleted\n");
getch();
free(n);
return;
}

d) Delete a node before given location  (किसी दी गयी स्थिति के पुर्व नोड को हटाना)

//Delete a Node before given Location from SLL
void deletebeforelocsll(NODE *loc){
NODE *temp=start;
clrscr();
if(start==NULL){
printf("Underflow Condition\n");
getch();
return;
}
if(loc==start){
printf("Location is first Node\n Deletion will not perform here\n");
getch();
return;
}
if(start->link==loc){
printf("Location is Second Node\nChoose Option delete first Node in SLL\n");
getch();
return;
}
else{
while(temp->link->link!=loc){ temp=temp->link;}
n=temp->link;
temp->link=loc;
}
printf("Node before given location is deleted\n");
getch();
free(n);
return;
}

No comments:

Post a Comment

Stack Data Structure, Push, Pop and Peek Operations , Applications of Stack

Stack is a linear data structure. It is collection of ordered data elements. It is also known as LIFO system (last in first out). It means i...