void QuickSort(LineList r[], int first, int end) { /*快速排序算法函数*/ int i, j; LineList temp; i = first; j = end; temp = r[i]; /*初始化*/ while (i < j) { while (i < j && temp.Key <= r[j].Key) j--; r[i] = r[j]; while (i < j && r[i].Key <= temp.Key) i++; r[j] = r[i]; } r[i] = temp; if (first < i - 1) QuickSort(r, first, i - 1); /*对左侧分区域进行快速排序*/ if (i + 1 < end) QuickSort(r, i + 1, end); /*对右侧分区域进行快速排序*/ }这个呢
时间: 2024-03-12 13:43:13 浏览: 12
要让这段代码输出排序的过程,可以在排序过程中添加一些输出语句。具体修改如下:
```
void QuickSort(LineList r[], int first, int end) { /*快速排序算法函数*/
int i, j;
LineList temp;
i = first;
j = end;
temp = r[i]; /*初始化*/
while (i < j)
{
while (i < j && temp.Key <= r[j].Key) j--;
r[i] = r[j];
while (i < j && r[i].Key <= temp.Key) i++;
r[j] = r[i];
}
r[i] = temp;
// 添加输出语句,输出每次排序后的结果
printf("第 %d 次排序结果:", i-1);
for(int k=first; k<=end; k++){
printf("%d ", r[k].Key);
}
printf("\n");
if (first < i - 1) QuickSort(r, first, i - 1); /*对左侧分区域进行快速排序*/
if (i + 1 < end) QuickSort(r, i + 1, end); /*对右侧分区域进行快速排序*/
}
```
这样修改后,每次排序后都会输出排序结果。同时,还会输出排序进行的次数。