Okay so I have sucesfully completed the first and second part but am clueless as to how to proceed for the third step. The code is posted below. Any help would be appreciated. Regards, Willis.
#include <stdio.h>
#define MAXIMUMARRAYSIZE 20
void quicksort(int arr[], int low, int high);
int main(void) {
int array[MAXIMUMARRAYSIZE] = {0};
int i = 0;
for(i = 0; i < MAXIMUMARRAYSIZE; i++)
array[i] = rand() % 100;
printf("Array filled with random values: ");
for(i = 0; i < MAXIMUMARRAYSIZE; i++) {
printf(" %d ", array[i]);
}
printf("\n--------------------");
quicksort(array, 0, (MAXIMUMARRAYSIZE - 1));
printf("Array sorted using quicksort algorithm: ");
for(i = 0; i < MAXIMUMARRAYSIZE; i++) {
printf(" %d ", array[i]);
}
printf("\n--------------------");
return 0;
}
void quicksort(int arr[], int low, int high) {
int i = low;
int j = high;
int y = 0;
int z = arr[(low + high) / 2];
do {
while(arr[i] < z) i++;
while(arr[j] > z) j--;
if(i <= j) {
y = arr[i];
arr[i] = arr[j];
arr[j] = y;
i++;
j--;
}
} while(i <= j);
if(low < j)
quicksort(arr, low, j);
if(i < high)
quicksort(arr, i, high);
}

New Topic/Question
Reply




MultiQuote




|