#include h>#include 1.For Merge Sort “); printf(” For Selection Sort”); printf(” ENTER YOUR CHOICE :”); scanf(“%d”,&CHC); printf(” Before sorting After merge sorting After Insert sorting After Selection sorting After bubble sorting ENTERED A WRONG INPUT “); } printf(” Enter -1 to exit. Or any other key to repeat conversion: “); scanf(” %d”, &CHC); headNode = NULL; }while(CHC != -1);return 0;} /*+++++++++++++++++++++++++++++++++++++++++++++++++++*/ /*++++++++++Implementation of Functions+++++++++++++*/ /*+++++++++++++++++++++++++++++++++++++++++++++++++*/nnode *mergeNodes(nnode *prv, nnode *NXXT){ if (!prv) return NXXT; if (!NXXT) return prv; if (prv->Value < NXXT->Value) { prv->Nexxt = mergeNodes(prv->Nexxt,NXXT); prv->Nexxt->previous = prv; prv->previous = NULL; return prv; } else { NXXT->Nexxt = mergeNodes(prv,NXXT->Nexxt); NXXT->Nexxt->previous = NXXT; NXXT->previous = NULL; return NXXT; }}nnode *mergeSort(nnode *headNode){ if (!headNode || !headNode->Nexxt) { return headNode; } nnode *NXXT = splitNode(headNode); headNode = mergeSort(headNode); NXXT = mergeSort(NXXT); return mergeNodes(headNode,NXXT);}void insert(nnode **headNode, int Value){ nnode *temp =(nnode *)malloc(sizeof(nnode)); temp->Value = Value; temp->Nexxt = temp->previous = NULL; if (!(*headNode)) { (*headNode) = temp; } else { temp->Nexxt = *headNode; (*headNode)->previous = temp; (*headNode) = temp; }}void print(nnode *headNode){ nnode *temp = headNode; while (headNode) { printf(“%d “,headNode->Value); temp = headNode; headNode = headNode->Nexxt; }}void swap(nnode *a, nnode *b){ int temp = a->Value; a->Value = b->Value; b->Value = temp;}nnode *splitNode(nnode *headNode){ nnode *fast = headNode,*slow = headNode; while (fast->Nexxt && fast->Nexxt->Nexxt) { fast = fast->Nexxt->Nexxt; slow = slow->Nexxt; } nnode *temp = slow->Nexxt; slow->Nexxt = NULL; return temp;}void sortInsert(nnode** node, nnode* New){ nnode* current; if (*node == NULL) *node = New; else if ((*node)->Value >= New->Value) { New->Nexxt = *node; New->Nexxt->previous = New; *node = New; } else { current = *node; while (current->Nexxt != NULL &¤t->Nexxt->Value < New->Value) current = current->Nexxt; New->Nexxt = current->Nexxt; if (current->Nexxt != NULL) { New->Nexxt->previous = New; } current->Nexxt = New; New->previous = current; }}void ISort(nnode** node){ nnode* sorted = NULL; nnode* current = *node; while (current != NULL) { nnode* Nexxt = current->Nexxt; current->previous = current->Nexxt = NULL; sortInsert(&sorted, current); current = Nexxt; } *node = sorted;}void BSort(nnode *node){ int swapped, i; nnode *pointer1; nnode *ptr = NULL; if (pointer1 == NULL) return; do { swapped = 0; pointer1 = node; while (pointer1->Nexxt != ptr) { if (pointer1->Value > pointer1->Nexxt->Value) { swap(pointer1, pointer1->Nexxt); swapped = 1; } pointer1 = pointer1->Nexxt; } ptr = pointer1; } while (swapped);}void SelectionSort(nnode** head){ int i; nnode* temp; while( *head != NULL ){ temp = *head; while( temp != NULL ){ if( (*head)->Value > temp->Value ){ i = (*head)->Value; (*head)->Value = temp->Value; temp->Value = i; } temp = temp->Nexxt; } head = &(*head)->Nexxt; }}
++++++++++++++++++++++++++++++++++++”); printf(”
++ Doubly Linked List Sorting ++”); printf(”
++++++++++++++++++++++++++++++++++++
“); printf(”
2.For Insertion Sort “); printf(”
3.
4.For Bubble Sort”); printf(”
5.ENTER TO EXIT “); printf(”
“); print(headNode); if(CHC==1) { headNode = mergeSort(headNode); printf(”
“); print(headNode); } else if(CHC==2) { ISort(&headNode); printf(”
“); print(headNode); } else if(CHC==3) { SelectionSort(&headNode); printf(”
“); print(headNode); } else if (CHC==4) { BSort(headNode); printf(”
“); print(headNode); } else if (CHC==5) { system(“cls”); exit(0); } else { printf(”