第一次写快排,折磨
#include<iostream>
using namespace std;
void Quick_Sort(int *arr,int start,int end)
{
int i = start;
int j = end;
int temp = arr[start];
if (start == end)
{
cout << "return1" << endl;
return;
}
else if (start > end)
{
cout << "start>end" << endl;
return;
}
else
{
while (i!=j)
{
while (i != j)
{
if (arr[j] < temp)
{
arr[i] = arr[j];
break;
}
else
{
j--;
}
}
while (i != j)
{
if (arr[i] > temp)
{
arr[j] = arr[i];
break;
}
else
{
i++;
}
}
}
arr[j] = temp;
}
Quick_Sort(arr, start, j - 1);
Quick_Sort(arr, i + 1, end);
}
int main()
{
int arr[10] = { 5,9,6,8,1,3,4,2,15,7 };
int len = sizeof(arr) / sizeof(arr[0]);
Quick_Sort(arr,0,len-1);
for (int i = 0; i < len; i++)
{
cout << arr[i] << " ";
}
system("pause");
return 0;
}
|