Example:
Lets write the template function that can sort array, of any data type, using quick sort:
template <typename T> void quickSort(T *arr, int low, int high) { if(low < high) { int mid = partition<T>(arr, low, high); quickSort<T>(arr, low, mid-1); quickSort<T>(arr, mid+1, high); } } template<typename T> int partition(T *arr, int low, int high) { int pivot = l; // Index of Pivot element while(low < high) { while(arr[low] <= arr[pivot]) l++; // Move l forward while(arr[high] > arr[pivot]) h--; // Move h backward if(low < high) swap(arr[low], arr[high]); } /* h is final position for the pivot */ swap(arr[pivot], arr[high]); return high; }
1 Comment
Great goods from you, man. I’ve understand youir stuff previous to
and you’re just too fantastic. I really like
what you’ve acquired here, certainly like what you’re
stating and the way bby which you are saying
it. You mwke it enjoyable and you continue to care for to keep
it sensible. I can not wait to read far more from you.
That is actually a great website.