My code compiles and also it runs. But after taking input it does not execute the next statement of the program.
It takes all input elements of the array then it does not do anything. I think there is problem after second scanf
statement which is inside the for
loop.
I am not sure that the code is correct but after compiling and running, I am expecting that it should give the final output even if it is not as expected (or incorrect).
I am using Code::Blocks(16.01)
as IDE.
My operating system is Windows 8.1(64-bit).
My code:
#include <stdio.h>
void quick(int *, int, int);
int main() {
int n, i, pivot, j, k, l, u;
printf("Give size\n");
scanf("%d", &n);
int a[n];
printf("Enter the list\n");
for (i = 1; i <= n; i++)
scanf("%d", &a[i]);
quick(a, 1, n - 1);
printf("\nSorted numbers are\n");
for (i = 1; i <=n; i++)
printf("%d ", a[i]);
printf("\n");
return 0;
}
void quick(int a[], int l, int u) {
int pivot, j, temp, i;
pivot = a[l];
i = l;
j = u;
while (i <= j) {
if (a[i] > pivot && a[j] < pivot) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
else if (a[i] < pivot)
i++;
else if (a[j] > pivot)
j--;
}
quick(a, l, j - 1);
quick(a, j + 1, u);
}