标题:[求助]快速排序,小弟的程序有问题
取消只看楼主
java在线
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2005-7-9
结帖率:100%
 问题点数:0 回复次数:0 
[求助]快速排序,小弟的程序有问题

#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;
}
}

搜索更多相关主题的帖子: include please number create 
2006-02-20 10:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-46271-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.358654 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved