Singly Linked List (SLL) Reversal operation, Reverse function/algorithm

Reversal:- To reverse nodes of given Singly Linked List is called Reversal operation.
रेवर्सल:- दी गयी सिंगली लिंक्ड लिस्ट के नोड्स को विपरीत क्रम में व्यवस्थित करना , रेवर्सल कहलाता है।

Let Assume that SLL was previously created by createsll() and start pointing to the fisrt node of SLL.
माना कि createsll() द्वारा  SLL तैयार की गयी है, जिसके प्रथम नोड का एड्रेस स्टार्ट नामक पॉइंटर वेरिएबल में रखा गया है 

//Reversal of SLL
void reversesll(){
NODE *p=start,*q=NULL,*r=NULL;
while(p!=NULL){
r=q;
q=p;
p=p->link;
q->link=r;
}
start=q;
printf("Singly Linked List is Reversed\n");
getch();
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...