View Single Post
 Go4Expert Member 24Dec2011,11:20 Hi It seems that your algorithm for quick sort is wrong. The following is the algorithm for quick sort. I hope this helps. Best regards Chong Code: +++++++++++++++++++++++++++++++++++++++++ // quicksort.cpp // // This program shows how to use Quicksort to sort arrays. // Note that pivot in the program is nothing more than a guide!! It // is used just for a comparison!! // #include #include #include //for getche() #include #include #define swap(x,y) { int t; t=x; x=y; y=t;} #define order(x,y) if (x > y) swap(x,y) #define O2(x,y) order(x,y) #define O3(x,y,z) O2(x,y);O2(x,z);O2(y,z) typedef enum {yes, no} yes_no; static yes_no find_pivot(int *left, int *right, int *pivot_ptr); static int *partition(int *left, int *right, int pivot); void quicksort(int *left, int *right); main( ) { int *p,pivot; int age[5] = {7,2,5,8,9}; int len = sizeof(age)/sizeof(int); quicksort(age, age+len-1); for (int k=0; k= pivot) --right; if (left < right) { swap(*left, *right); ++left; --right; } // if } // while return(left); } // partition Last edited by shabbir; 24Dec2011 at 11:28.. Reason: Code blocks