struct account *order(struct account *head){ struct account *p1,*p2,*p0,*p3,*headnew; int m=0; headnew=NULL; while(head!=NULL){ p0=p2=head; p1=p0->next; while(p1!=NULL){ if(p1->account_num<p0->account_num) p0=p1; p1=p1->next; } if(p0==head) head=p0->next; else{ while(p2->next!=p0) p2=p2->next; p2->next=p0->next; } m++; if(m==1){ headnew=p3=p0; headnew->next=NULL; } else{ p3->next=p0; p3=p3->next; p3->next=NULL; } } return(headnew); }
根据账户对链表进行排序
struct account *order(struct account *head){
struct account *p1,*p2,*p0,*p3,*headnew;//定义account结构体指针
int m=0;
headnew=NULL;
while(head!=NULL){//如果节点不为空,进行循环
p0=p2=head;//指向头结点
p1=p0->next;//p1指向p0的下个节点
while(p1!=NULL){
if(p1->account_num<p0->account_num)//如果下一个节点比上一个小
p0=p1;
p1=p1->next;//指向下个节点
}
if(p0==head)//p0正好是头结点节点的情况
head=p0->next;
else{
while(p2->next!=p0)
p2=p2->next;//指向下个节点
p2->next=p0->next;
}
m++;
if(m==1){
headnew=p3=p0;
headnew->next=NULL;
}
else{
p3->next=p0;
p3=p3->next;
p3->next=NULL;
}
}
return(headnew);
}
函数名order,那就是排序的功能;这是一个插入排序的函数处理;