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;
}

Comments

Popular posts from this blog

Priority Queue

Data Structure and Algorithms (DSA) USING C/C++ Topics Covered