#include
using namespace std;
class quick
{
public:
quick();
~quick();
void quick_sort();
void output();
private:
int *data;
int leng;
void quicksort(int p,int r);
int partition(int p,int r);
void exchange(int &a,int &b);
};
void quick::exchange(int &a,int &b)
{
int temp="a";
a=b;
b=temp;
}
int quick::partition(int p,int r)
{
int x="data"[p];
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 quick::output()
{
cout<<"现在数组中的数字分别为:\n";
for(int i="0";i {
cout< }
cout<}
void quick::quicksort(int p,int r)
{
if(p {
int q="partition"(p,r);
quicksort(p,q);
quicksort(q+1,r);
}
}
void quick::quick_sort()
{
quicksort(0,leng-1);
}
quick::~quick()
{
delete[] data;
}
quick::quick()
{
cout<<"请输入您需要排序的数字:\n";
cin>>leng;
data=new int[leng];
for(int i="0";i {
cout<<"请输入第"< cin>>data[i];
}
}
int main()
{
quick test;
test.output();
cout<<"排序中......\n";
test.quick_sort();
cout<<"排序完成!\n";
test.output();
return 0;
}
阅读(740) | 评论(0) | 转发(0) |