#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 = NULL;

	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;

	do
	{
		p = head->next;
		done = 1;
		while (/*1*/)
		{
			q = p->next;
			if (p->num > q->num)
			{
				temp = p->num;
				p->num = q->num;
				q->num = temp;
				done = 0;
			}
			p = p->next;
		}
	}
	while (/*2*/);

	//print list
	pos = head;
	printf("%d ", pos->num);
	pos = pos->next;
	while (pos != head)
	{
		printf("%d ", pos->num);
		pos = pos->next;
	}

	getch();
}