#include
using namespace std;
#include
class randquick
{
public:
randquick();
~randquick();
void randquick_sort();
void output();
private:
int *data;
int leng;
void randquicksort(int p,int r);
int randpartition(int p,int r);
void exchange(int &a,int &b);
int randomize(int p,int r);
};
int randquick::randomize(int p,int r)
{
return (rand()%(r-p+1)+p);
}
void randquick::exchange(int &a,int &b)
{
int temp="a";
a=b;
b=temp;
}
int randquick::randpartition(int p,int r)
{
int x="data"[randomize(p,r)];
int i="p-1";
int j="r"+1;
while(1)
{
do
{
j--;
}while(data[j]>x);
do
{
i++;
}while(data[i]
if(i {
exchange(data[i],data[j]);
}
else
{
return j;
}
}
}
void randquick::output()
{
cout<<"现在数组中的数字分别为:\n";
for(int i="0";i {
cout< }
cout<}
void randquick::randquicksort(int p,int r)
{
if(p {
int q="randpartition"(p,r);
randquicksort(p,q);
randquicksort(q+1,r);
}
}
void randquick::randquick_sort()
{
randquicksort(0,leng-1);
}
randquick::~randquick()
{
delete[] data;
}
randquick::randquick()
{
cout<<"请输入您需要排序的数字:\n";
cin>>leng;
data=new int[leng];
for(int i="0";i {
cout<<"请输入第"< cin>>data[i];
}
}
int main()
{
randquick test;
test.output();
cout<<"排序中......\n";
test.randquick_sort();
cout<<"排序完成!\n";
test.output();
return 0;
}
阅读(945) | 评论(0) | 转发(0) |