#include<stdio.h>
#include<stdbool.h>
void swap(int* a, int* b)
{
int t = *a;
*a = *b;
*b = t;
}
void stoogeSort(int a[], int left, int right)
{
int temp;
if (a[left] > a[right])
{
swap(&a[left],&a[right]);
}
if (right - left + 1 >= 3)
{
temp = (right - left + 1) / 3;
stoogeSort(a,left,right-temp);
stoogeSort(a,left+temp,right);
stoogeSort(a,left,right-temp);
}
}
int main()
{
int a[] = { 12,232,34,34,45,4,6,56,53,4,423,2 };
int n = sizeof(a) / sizeof(int);
stoogeSort(a, 0, n-1);
for (int i = 0; i < n; i++)
{
printf("%d\t",a[i]);
}
getchar();
return 0;
}
03-29
847
07-23
07-23