游戏中很多地方用到排序
代码如下
#include<iostream>
using namespace std;
int len = 6;
void QuickSort(int* t, int start, int end)
{
if (start >= end) return;
int s = start;
int e = end;
int num = t[start];
while (start < end)
{
while (t[end] > num && end > start) end--;
while (t[start] <= num && start < end) start++;
int x = t[start];
t[start] = t[end];
t[end] = x;
}
t[s] = t[start];
t[start] = num;
QuickSort(t, s, start-1);
QuickSort(t, end+1, e);
}
int main()
{
int t[7] = { 3,5,1,4,7,6,2 };
QuickSort(t, 0, 6);
for (int i = 0; i < 7; i++) cout << t[i] << endl;
return 0;
}