⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quicksort.cpp

📁 归并排序
💻 CPP
字号:
#include "QuickSort.h"

template<class T>
int Partition(T a[],int low,int high)
{
	T temp;
	temp=a[low];
	int i,j;
	i=low+1;
	j=high;
	while(i<j)
	{
		while(i<=j && a[i]<temp)
		  i++;
		while(i<=j && a[j]>temp)
		  j--;
		if(i<j)
	  	Swap(a[i],a[j]);
	}
	a[low]=a[j];
	a[j]=temp;
	return j;	
}

template<class T>
void Swap(T a,T b)
{
	T temp;
	temp=a;
	a=b;
	b=temp;
}

template<class T>
void QuickSort(T a[],int low,int high)
{
	int j;
	if (low<high)
	{
		j= Partition(a,low,high);
		QuickSort(a,low,j-1);
		QuickSort(a,j+1,high);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -