Hi!
I am really in trouble with this code![]()
![]()
![]()
I am not sure where is the mistake. Waiting for some good help![]()
![]()
![]()
Code:#include<iostream.h> template<class T> void quickSort(T* a, int lo, int hi) { if (lo >= hi) return; T pivot = a[hi]; int i = lo - 1; int j = hi; while (i < j) { while (a[++i] < pivot) ; while (j >= 0 && a[--j] > pivot) ; if (i < j) swap(a[i], a[j]); } swap(a[i], a[hi]); quicksort(a, lo, i-1); quicksort(a, i+1, hi); } template<class T> void sort(T* a, int n) { quicksort(a, 0, n-1); } int main() { const int n = 7; int ary[n] = {9, 5, 1, 8, 3, 4, 6}; cout << " Before soring : "; for(int i=0;i<n;++i) cout << ary[i] << '\t'; sort(ary,n); cout << "\n After sorting : "; for(int i=0;i<n;++i) cout << ary[i] << '\t'; return 0; }



LinkBack URL
About LinkBacks



