#include "stdio.h"
struct number
{
int num;
struct number *pri;
struct number *next;
};
main()
{
struct number *create(void);
void Qsort(int*,int*);
void list(struct number*);
}
struct number *create(void)
{
struct number *low,*high,*p1;
low=high=0;
printf("please input a number\n");
printf("input 0 to end");
p1=(struct number*)malloc(sizeof(struct number));
scanf("%d",&p1->num);
while(p1->num!=0)
{
if(low==0) { low=p1; p1->pri=0; }
else high->next=p1;
high=p1;
p1=(struct number*)malloc(sizeof(struct number));
scanf("%d",p1->num);
p1->pri=high;
}
high->next=0;
free(p1);
return low;
}
void Qsort(int* low,int* high)
{
struct number *pivotloc;
struct number *partition(int*,int*);
if(low!=high)
{
pivotloc=partition(low,high);
Qsort(low,pivotloc->pri);
Qsort(pivotloc->next,high);
}
}
struct number* partition(int* low,int* high)
{
int r;
struct number *pl,*ph;
pl=low;
ph=high;
r=pl->num;
while(low!=high)
{
while(pl!=ph&&ph->num>=r) ph=ph->pri;
pl->num=ph->num;
while(pl!=ph&&pl->num<=r) pl=pl->next;
ph->num=pl->num;
}
pl->num=r;
return pl;
}
void list (struct number *p)
{
printf("The linked list:\n");
while(p!=0)
{
printf("%d\n",p->num);
p=p->next;
}
}
[求助]快速排序,小弟的程序有问题