/*Head is a pointer,without data */
Node * FindBeforMax(Node * Head)
{
Node * befmax;
Node * result;
Node * max;
befmax = Head;
result = Head;
Head = Head->next;
max = Head;
while(befmax->next != NULL)
{
if(Head->data > max->data)
{
result = befmax;
max = Head;
}
befmax = Head;
Head = Head->next;
}
return result;
}
/*
Head is a pointer,without data
return new Head
*/
Node * inserSortList(Node * Head)
{
Node *out= NULL;
Node *bfmax,*afmax;
while(Head->next!= NULL)
{
bfmax=FindBeforMax(Head);
afmax = bfmax->next->next;
bfmax->next->next=out;
out = bfmax->next;
bfmax->next = afmax;
}
Head->next = out;
return Head;
}
阅读(1020) | 评论(0) | 转发(0) |