我遇到堆栈溢出错误,如果有人能指出我在哪里做错了,我会很感激。 C语言,使用Visual Studio编译器。请注意,这只是我的讲师给我的修订版。我想我的其余代码,例如。排序很好。
#include <stdio.h>
void QuickSort (int data[], int size);
void QuickSortHelp (int data[], int from, int to);
void QuickSort (int data[], int size)
{
QuickSortHelp(data, 0, size-1);
}
void QuickSortHelp (int data[], int from, int to)
{
if (from >= to)
return;
else
{
int pivot;
int index;
int temp;
int left, right;
pivot = data[from];
left = from + 1;
right = to;
for (left = from + 1;left<= right;left++,right--)
{
if (data[left] > pivot)
{
if (data[right]<= pivot)
{
temp = data[left];
data[left] = data[right];
data[right] = temp;
}
}
}
temp = data[from];
data[from] = data[left];
data[left] = temp;
index = left;
QuickSortHelp (data, from, index-1);
QuickSortHelp (data, index+1, to);
}
}
int main()
{
int data[] = {4,5,3,8,2,6,1,7};
int i;
printf("Test");
QuickSort (data, 8);
while (i<=8)
{
printf("%d", data[i]);
i++;
}
printf("Test done");
}