单链表的快速排序,在DEV上无法运行,请大神解答。
#include
#include
typedef struct test{
int n;
struct test *next;
}Node;
Node create();
void print(Node *head);
Node quicksort(Node *head,Node *last);
void swap(Node *head,Node *last);
int main(void){
Node *head=NULL;
head=create();
head=quicksort(head,NULL);
print(head);
return 0;
}
Node *create(){
Node *head=NULL,*p,*tail;
head=(Node *)malloc(sizeof(Node));
head->next=NULL;
tail=head;
int n;
while(1){
scanf("%d",&n);
if(n<=0){
break;
}
p=(Node *)malloc(sizeof(Node));
p->next=NULL;
tail->next=p;
tail=p;
p->n=n;
}
return head;
}
void print(Node *head){
Node *temp;
temp=head;
while(temp->next!=NULL){
temp=temp->next;
printf("%d ",temp->n);
}
}
Node* quicksort(Node *head,Node *last){
Node *i,*m;
m=head->next;
for(i=m->next;i!=last;i=i->next){
if(i->nnext->n){
swap(i,m->next);
}
}
swap(m,head->next);
quicksort(head,m);
quicksort(m,last);
return head;
}
void swap(Node *head,Node *last){
int tmp=head->n;
head->n=last->n;
last->n=tmp;
}