Hello people,
I am pretty new to C and tried programming the quicksort algorithm.
But Code::Blocks keeps keeps terminating my process with the status above.
Also when printing my value, it says 6422272 instead of the I did put in.
Here is my Code:
Code:
#include <stdio.h>
void quicksort(int a[], int L, int R) //array, left end, right end
{
int i, j, w, x, k; // i is left index, r is right index, k is pivot
i = L; j = R;
k = (L + R) / 2; // pivot set to middle
x = a[k]; // x gets value of k th element
do
{
while(a[i] < x) i = i + 1;
while(a[j] > x) j = j - 1;
if(i <= j)
{
w = a[i];
a[i] = a[j]; // swaps values of a[i] and a[j]
a[j] = w;
i = i + 1;
j = j - 1;
}
}
while(i <= j); // starts of on right and left side
if(L < j) quicksort(a, L, j);
if(R > i) quicksort(a, i, R);
}
int main()
{
int length, value, i;
printf("How long is your array?\n");
scanf("%d", &length); // I put 5 in
printf("%d\n", &length); // prints 6422272
int array[length];
for(i = 0; i <= length; i++)
{
printf("Give value number %d\n", &i);
scanf("%d", value);
array[i] = value;
}
quicksort(array, 0, length);
}