刚学会链表,尝试了一下链表的排序
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
node *next;
}*head,*p,*t;
int main()
{
int n,x;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
t=head;
scanf("%d",&n);
while(n--)
{
scanf("%d",&x);
p=(struct node*)malloc(sizeof(struct node));
p->data=x;
p->next=NULL;
t->next=p;
t=p;
}
node *i,*j;
int k;
for(i=head->next; i->next->next!=NULL; i=i->next)
for(j=i->next; j->next!=NULL; j=j->next)
if(i->data>j->data)
{
k=i->data;
i->data=j->data;
j->data=k;
}
p=head->next;
while(p)
{
printf("%d",p->data);
p=p->next;
if(p)
printf(" ");
}
printf("\n");
}