嗨,我仍然不知道为什么我的代码让我的堆栈溢出它的接缝,我的合并排序算法的下限和上限改变了不应该做的地方..
int[] arr = new int[10];
private void button1_Click(object sender, EventArgs e)
{
merge_sort(0, 9);
}
private void merge_sort(int left, int right)
{
if (left > right)
merge(left, right, (left + right) / 2);
else
merge_sort((left + right) / 2 + 1, right);
merge_sort(left, (left + right) / 2);
}
void merge(int low, int high, int mid)
{
int i, j, k, t;
j = low;
for (i = mid + 1; i <= high; i++)
{
while (arr[j] <= arr[i] && j < i)
j++;
if (j == i)
break;
t = arr[i];
for (k = i; k > j; k--)
arr[k] = arr[k - 1];
arr[j] = t;
}
}