typedef struct Node{//定义链表节点
struct Node* next;
int val;
}node;
void insert(node *head,node*p){//向头节点为head的有序链表中插入节点p
node *first=head->next;
node* second=head;
while(first!=NULL&&first->val<p->val){
second=second->next;
first=first->next;
}
if(first==NULL)//插在最后面
second->next=p;
else{
//插在中间
second->next=p;
p->next=first;
}
}
void sort(node* head){//对头节点为HEAD的无需链表进行插入排序
if(head==NULL)
return;
node*pre=head;
node*p=head->next;
while(p!=NULL){
pre=p;
p=p->next;
pre->next=NULL;
insert(head,pre);
}
}