quicksort.cpp

来自「用C++6.0编写」· C++ 代码 · 共 51 行

CPP
51
字号
#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 + =
减小字号Ctrl + -
显示快捷键?