#include#include#includestruct print(nnode *headNode);void swap(nnode *a, nnode *b);void sortInsert(nnode** node,

#include#include#includestruct LIST{    int Value;    struct LIST *Nexxt;    struct LIST *previous;};typedef struct LIST nnode;nnode *splitNode(nnode *headNode);nnode *mergeNodes(nnode *prv, nnode *NXXT);nnode *mergeSort(nnode *headNode);void insert(nnode **headNode, int Value);void print(nnode *headNode);void swap(nnode *a, nnode *b);void sortInsert(nnode** node, nnode* New);void ISort(nnode** node);void BSort(nnode *node);void SelectionSort(nnode** head);                /*+++++++++++++++++++++++++++++++++++++++++++++++++++*/                /*+++++++++++++++++ Main Functions +++++++++++++++++*/                /*+++++++++++++++++++++++++++++++++++++++++++++++++*/int main(){    int CHC;    nnode *headNode = NULL;    do{    insert(&headNode,5);    insert(&headNode,20);    insert(&headNode,4);    insert(&headNode,3);    insert(&headNode,30);    insert(&headNode,10);       system(“cls”);    printf(”
++++++++++++++++++++++++++++++++++++”);    printf(”
++   Doubly Linked List Sorting   ++”);    printf(”
++++++++++++++++++++++++++++++++++++
“);    printf(”

1.For Merge Sort “);    printf(”
2.For Insertion Sort “);    printf(”
3.For Selection Sort”);    printf(”
4.For Bubble Sort”);    printf(”
5.ENTER TO EXIT “);    printf(”

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

ENTER YOUR CHOICE :”);    scanf(“%d”,&CHC);    printf(”

Before sorting
“);    print(headNode);    if(CHC==1)    {        headNode = mergeSort(headNode);        printf(”

After merge sorting
“);        print(headNode);    }    else if(CHC==2)    {        ISort(&headNode);        printf(”

After Insert sorting
“);        print(headNode);    }    else if(CHC==3)    {        SelectionSort(&headNode);        printf(”

After Selection sorting
“);        print(headNode);    }    else if (CHC==4)    {        BSort(headNode);        printf(”

After bubble sorting
“);        print(headNode);    }    else if (CHC==5)    {        system(“cls”);        exit(0);    }    else    {        printf(”

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 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 &&current->Nexxt->Value 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;    }}

x

Hi!
I'm Neil!

Would you like to get a custom essay? How about receiving a customized one?

Check it out