    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
     
    typedef struct numType
    {
            int num;
            struct numType *next;
    }node;
     
    void main()
    {
            node *head, *pos;
            int done = 1;
            int temp;
            node *p, *q;
     
            head = (node*)malloc(sizeof(node));
            head->num = 2;
            pos = (node*)malloc(sizeof(node));
            head->next = pos;
            pos->num = 1;
            pos->next = (node*)malloc(sizeof(node));
            pos->next->num = 4;
            pos = pos->next;
            pos->next = (node*)malloc(sizeof(node));
            pos->next->num = 3;
            pos->next->next = head;
			head = pos->next;
			     
            //print list before sorting
			pos = head->next;
			printf("Before sorting:");
            printf("%d ", pos->num);
            pos = pos->next;
			while (pos != head->next)
            {
                    printf("%d ", pos->num);
                    pos = pos->next;
            }
			printf("\n");
			          
            do
            {
                    p = head->next;
                    done = 1;
                    while (done)
                    {
                            q = p->next;
                            if (p->num > q->num)
                            {
                                    temp = p->num;
                                    p->num = q->num;
                                    q->num = temp;
                                    done = 0;
                            }
                            p = p->next;
                    }
            }while (p!=head);
     
            //print list
			pos = head->next;
			printf("After sorting:");
            printf("%d ", pos->num);
            pos = pos->next;
			while (pos != head->next)
            {
                    printf("%d ", pos->num);
                    pos = pos->next;
            }
     
            getch();
    }
