快速排序,求指教
#include<stdio.h>int a[101], n;
void quicksort(int left,int right)
{
int i, j, t, temp;
if (left > right)
{
return;
}
temp = a[left];
i = left;
j = right;
while (i != j)
{
while (a[j] >= temp&&i < j)
{
j--;
}
while (a[i] <= temp&&i < j)
{
i++;
}
if (i < j)
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
a[left] = a[i];
a[i] = temp;
quicksort(left, i - 1);
quicksort(i + 1, right);
return;
}
int main()
{
int i, j;
int n;
scanf_s("%d", &n);
for (i = 1; i <= n; i++)
{
scanf_s("%d", &a[i]);
}
quicksort(1, n);
for (i = 1; i <= n; i++)
{
printf_s("%d ", a[i]);
}
return 0;
}
这个算法里有个地方我不理解
if (left > right)
{
return;
}
这个语句有社么用,把他删了,就打印不出结果。