I've been having a lot of trouble with this lately, and I was hoping someone could give me a clue as to what to do. Mostly because the smallest in the array is displayed last, rather than first.
Code:#include <stdio.h> #include "simpio.h" #define size 10 void GetArray(); void quicksort (int array[size], int arraybegin, int end); int rotate (int array[size], int arraybegin, int end); void displayarray (int array [size]); void swap (int array [size], int first, int second); main() { printf("What is your array? Enter 10 numbers please.\n"); GetArray(); } void GetArray() { int array[size]; int i; for (i=0; i<size; i++) { array[i]=GetInteger(); } quicksort(array, 0, size-1); displayarray(array); } void quicksort(int array[], int arraybegin, int end) { int count; if (arraybegin<end) { count=rotate(array, arraybegin, end); quicksort(array, arraybegin, count-1); quicksort(array, count+1, end); } } int rotate(int array[size], int arraybegin, int end) { int piv, poscount, negcount, j; j=0; piv=array[arraybegin]; poscount=arraybegin; negcount=end; j=size; while(poscount<=negcount) { for(poscount=arraybegin;array[poscount]<=piv&&poscount<=size;poscount++); for(negcount=end;array[negcount]>piv;negcount--); } swap(array, poscount, negcount); return (negcount); } void swap (int array [size], int high, int low) { int change; change=array[high]; array[high]=array[low]; array[low]=change; } void displayarray(int array [size]) { int i; printf("The sorted array is:"); for(i=0;i<size;i++) { printf("%d, ",array[i]); }}



LinkBack URL
About LinkBacks



