问题遇到的现象和发生背景
敲打快速排序,程序无法正常运行
用代码块功能插入代码,请勿粘贴截图
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main() {
int N;
int begin;
int end;
scanf("%d", &N);
int arr[N];
for (int i = 0; i < N; i++) {
scanf("%d", &arr[i]);
}
Quick_Sort(arr, 0, N - 1);
for (int j = 0; j < N; j++) {
printf("%d", arr[j]);
if(j<N)
printf(" ");
}
}
void Quick_Sort(int arr[], int begin, int end) {
if (begin > end)
return;
int tmp = arr[begin];
int i = begin;
int j = end;
while (i != j) {
while (arr[j] >= tmp && j > i) {
j--;
}
while (arr[i] <= tmp && i < j) {
i++;
}
if (i < j) {
int t = arr[j];
arr[j] = arr[i];
arr[i] = t;
}
}
arr[begin] = arr[i];
arr[i] = tmp;
Quick_Sort(arr, begin, i - 1);
Quick_Sort(arr, i + 1, end);
}