https://smart888.taobao.com/ 立观智能监控
分类: C/C++
2009-03-10 22:33:14
struct person *sort(struct person *head)
/*选择法排序。bfp1为p1前一地址,bfmin为min前一地址。*/
{
struct person *p1=NULL,*p2=NULL,*bfp1=NULL,*min=NULL,*bfmin=NULL;
p1=head;
while(p1->next)/*判断链尾*/
{
min=p2=p1;
while(p2->next)/*判断链尾*/
{
if(strcmp(min->name,p2->next->name)>0)
{
bfmin=p2;
min=p2->next;
}
p2=p2->next;/*下移*/
}
if(min!=p1)/*成立则修改链表*/
{
bfmin->next=min->next;/*删除节点*/
min->next=p1;/*插入节点*/
if(p1==head) head=min;
else bfp1->next=min;
bfp1=min;
}
else
{
bfp1=p1;
p1=p1->next;/*下移*/
}
}
return(head);
}