Doubly Linked List(DLL) 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 DLL was previously created by createdll() and first pointing to the fisrt node of DLL.
माना कि createdll() द्वारा DLL तैयार की गयी है जिसके प्रथम नोड का एड्रेस फर्स्ट नामक पॉइंटर वेरिएबल में रखा गया है 

//Sorting DLL
void sortdll(NODE *f){
NODE *i,*j;
int swap;
if(f==NULL){
printf("Doubly Linked List is Not Exist\n");
getch();
return;
}
for(i=f;i!=NULL;i=i->next){
for(j=i->next;j!=NULL;j=j->next){
if(i->info>j->info){
swap=i->info;
i->info=j->info;
j->info=swap;
}}}
printf("DLL is Sorted\n");
getch();
return;
}

Comments

Popular posts from this blog

Priority Queue

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