主题:排序有问题 求教!谢谢帮忙
# include <iostream>
# define N 10
double a[]={2.9,3.7,3.5,2.1,2.7,2.3,3.3,2.5,3.1,3.9};
using namespace std;
class QuickSort
{
int low,high;
public:
QuickSort(int ,int);
void qkSort();
int part();
void prnt();
};
QuickSort::QuickSort(int l,int h)
{
low=l;
high=h;
}
int QuickSort::part()
{
int i,j;
float p;
i=low,j=high;
p=a[low];
while (i<j)
{
while(i<j && a[j]>=p)
{ j--;}
a[i]=a[j];
while(i<j && a[i]<=p)
{ i++;}
a[j]=a[i];
}
a[i]=p;
return(i);
}
void QuickSort::qkSort()
{
static int i ;
if(low<high)
{
i=part();
high=i-1;
qkSort();
low=i+1;
qkSort();
}
else
return;
}
void QuickSort::prnt()
{
cout<<"\n sorted sequence is:\n";
for(int i=0;i<=N-1;i++)
cout<<a[i]<<endl;
}
void main()
{
int m=0,n=N-1;
QuickSort qs (m,n);
qs.qkSort();
qs.prnt();
}
# define N 10
double a[]={2.9,3.7,3.5,2.1,2.7,2.3,3.3,2.5,3.1,3.9};
using namespace std;
class QuickSort
{
int low,high;
public:
QuickSort(int ,int);
void qkSort();
int part();
void prnt();
};
QuickSort::QuickSort(int l,int h)
{
low=l;
high=h;
}
int QuickSort::part()
{
int i,j;
float p;
i=low,j=high;
p=a[low];
while (i<j)
{
while(i<j && a[j]>=p)
{ j--;}
a[i]=a[j];
while(i<j && a[i]<=p)
{ i++;}
a[j]=a[i];
}
a[i]=p;
return(i);
}
void QuickSort::qkSort()
{
static int i ;
if(low<high)
{
i=part();
high=i-1;
qkSort();
low=i+1;
qkSort();
}
else
return;
}
void QuickSort::prnt()
{
cout<<"\n sorted sequence is:\n";
for(int i=0;i<=N-1;i++)
cout<<a[i]<<endl;
}
void main()
{
int m=0,n=N-1;
QuickSort qs (m,n);
qs.qkSort();
qs.prnt();
}