Saturday 15 March 2014

what have i done wrong (c++ quickSort)? -



what have i done wrong (c++ quickSort)? -

my quicksort code works fine number of elements except 2 elements , doesn't sort odd numbers of element.

int quicksort::partition(int beg, int end) // function find pivot point { int p = beg, pivot = list[beg], loc; (loc = beg + 1; loc <= end; loc++) { if (pivot > list[loc]) { list[p] = list[loc]; list[loc] = list[p + 1]; list[p + 1] = pivot; p = p + 1; } } homecoming p; } void quicksort::sort(int beg, int end) { if (beg < end) { int p = partition(beg, end); // calling procedure find pivot sort(beg, p - 1); // calls (recursion) sort(p + 1, end); // calls (recursion) } }

c++ quicksort

No comments:

Post a Comment