#include<stdio.h>
#define N 10
typedef struct Seq
{int data;
struct Seq *next;
}Seq,*Sq;
Sq create()
{Sq L,p;
int i;
L=(Sq)malloc(sizeof(Seq));
L->next=NULL;
for(i=N;i>0;i--)
{p=(Sq)malloc(sizeof(Seq));
scanf("%d",&p->data);
p->next=L->next;
L->next=p;
}
return(L);
}
int minkey(Sq L)
{Sq p,q;
int n;
p=L->next;
n=p->data;
for(;p!=NULL;p=p->next)
{if(p->data<n)
n=p->data;
}
return(n);
}
void selectsort(Sq L)
{Sq p,q,s;
for(p=L;p->next!=NULL;p=p->next)
{for(q=p->next;q!=NULL;q=q->next)
{s=q->next;
if(s->data==minkey(p))
{q->next=s->next;
s->next=p->next;
p->next=s;
}
}
}
}
void main()
{Sq L,p;
L=create();
selectsort(L);
for(p=L->next;p!=NULL;p=p->next)
printf("%d ",p->data);
getch();
}
评论