// ListSort.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
typedef struct _node
{
int data;
struct _node *next;
}Node;
int _tmain(int argc, _TCHAR* argv[])
{
int arr[]={12,34,1,89,6,56,45,2,31};
Node* head=new Node();
Node* p=head;
for(int i=0;i<9;i++)
{
Node* n=(Node*)malloc(sizeof(Node));
n->data=arr[i];
n->next=NULL;
p->next=n;
p=p->next;
}
head=head->next;
Node* temp=head->next;
head->next=NULL;
while(temp)
{
Node* p=temp->next;
for(Node *t=head;t!=NULL;t=t->next)
{
if(temp->data>t->data&&t->next!=NULL&&(t->next)->data>temp->data)
{
temp->next=t->next;
t->next=temp;
break;
}
else if(temp->data>t->data&&t->next==NULL)
{
t->next=temp;
temp->next=NULL;
break;
}
else if(temp->data<t->data)
{
temp->next=head;
head=temp;
break;
}
}
temp=p;
}
while(head)
{
cout<<head->data<<" ";
head=head->next;
}
cin.get();
return 0;
}