Singly Linked List (SLL) Sorting operation, Sort function/algorithm

Sorting:- To arrange nodes in ascending or descending order on the basis of info part is known as Sorting.
सॉर्टिंग:- सिंगली लिंक्ड लिस्ट के नोड्स को, इन्फो पार्ट के आधार पर, बढ़ते हुए या घटते हुए क्रम में व्यवस्थित करना, सॉर्टिंग कहलाता है। 
Let Assume that SLL was previously created by createsll() and start pointing to the fisrt node of SLL.
माना कि createsll() द्वारा SLL तैयार की गयी है जिसके प्रथम नोड का एड्रेस स्टार्ट नामक पॉइंटर वेरिएबल में रखा गया है 

//sorting nodes of SLL
void sortsll(NODE *s){
NODE *i,*j;
int swap;
if(s==NULL){
printf("Linked List is Not Exist\n");
getch();
return;
}
for(i=s;i!=NULL;i=i->link){
for(j=i->link;j!=NULL;j=j->link){
if(i->info>j->info){
swap=i->info;
i->info=j->info;
j->info=swap;
}}}
printf("SLL is Sorted\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...