📄 quicksort.cpp
字号:
#include "stdafx.h"
#include<iostream>
#include "QuickSort.h"
using namespace std;
QuickSort::QuickSort(int qs_Size)
{
reset(qs_Size);
}
void QuickSort::reset(int qs_Size)
{
Array2=new int[qs_Size];
qsSize=qs_Size;
}
void QuickSort::split(int a[],int low,int high)
{
int i=low;
int x=a[low];
for(int j=low+1;j<=high;j++)
{
if(a[j]<x)
{
i++;
if(i!=j)
{
int temp;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
int temp;
temp=a[low];
a[low]=a[i];
a[i]=temp;
w=i;
}
void QuickSort::quick(int a[],int low,int high)
{
if(low<high)
{
split(a,low,high);
quick(a,low,w-1);
quick(a,w+1,high);
}
}
void QuickSort::output()
{
cout<<"长度为"<<qsSize<<"的数组";
cout<<"执行快速排序所需的时间为:"<<costTime<<" ms"<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -