📄 quicksort.cpp
字号:
#include <iostream.h>
#include "datatype.h"
void QuickSort(datatype a[], int low, int high)
//用递归方法对对象a[low]--a[high]进行快速排序
{
int i, j;
datatype temp;
i = low;
j = high;
temp = a[low];
while(i < j)
{
//在数组的右端扫描
while(i < j && temp.key <= a[j].key) j--;
if(i < j)
{
a[i] = a[j];
i++;
}
//在数组的左端扫描
while(i < j && a[i].key < temp.key) i++;
if(i < j)
{
a[j] = a[i];
j--;
}
}
a[i] = temp;
//对子对象数组进行递归快速排序
if(low < i) QuickSort(a, low, i-1);
if(i < high) QuickSort(a, j+1, high);
}
void main(void)
{
datatype test[]={60,55,48,37,10,90,84,36};
int n = 8;
QuickSort(test, 0, 7);
for(int i = 0; i < n; i++)
cout << test[i].key << " ";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -