急!求助排序问题!
链表中怎么排序我的怎么没效果,帮看下写程序写晕了
Head是全局变量
int TaxisEngneer(void)
{
struct engineer *Cur=NULL;
struct engineer *p=NULL;
struct engineer *New=NULL;
struct engineer *pt=NULL;
int input=1;
printf("请选择1.编号升序,2.姓名升序,3.工龄升序(默认为编号升序):");
fflush(stdin);
scanf("%d",&input);
if(input==1)
{
for( Cur=Head; Cur!=NULL; Cur=Cur->Next )
{
New=Cur;
pt=Cur;
for( p=Cur->Next; p!=NULL; p=p->Next )//选择排序
{
if(Cur->number > p->number)
{
pt=p;
}
}
if(pt!=Cur)
{
p=New;
Cur=pt;
}
}
printf("已完成排序,按任意键退出!");
getch();
return 0;
}
else if(input==2)
{
for( Cur=Head; Cur!=NULL; Cur=Cur->Next )
{
New=Cur;
pt=Cur;
for( p=Cur->Next; p!=NULL; p=p->Next )
{
if( strcmp(Cur->name,p->name) >0 )
{
pt=p;
}
}
if( pt!=Cur )
{
p=New;
Cur=pt;
}
}
printf("已完成排序,按任意键退出!");
getch();
return 0;
}
for( Cur=Head; Cur!=NULL; Cur=Cur->Next )
{
New=Cur;
pt=Cur;
for( p=Cur->Next; p!=NULL; p=p->Next )
{
if( Cur->workyear > p->workyear )
{
pt=p;
}
}
if( pt!=Cur )
{
p=New;
Cur=pt;
}
}
printf("已完成排序,按任意键退出!");
getch();
return 0;
}