Tag:c++ Quick sort
#include <iostream>using namespace std;//quick Sort//In addition, if the array is a reference pass can be inferred by the function template's argument to automatically get its length template<typename T, int n> void Printarr (T (&arr) [N]) {int i = 0; while (i<n) {cout << arr[i] << ""; i++; } cout <<endl;} void swap (int &p,int &q) {int temp = p;p= q;q=temp;} int getindex (int arr[],int nlow,int nhigh) {int ntemp = Arr[nhigh];int j = nlow-1;for (int i=nlow;i<nhigh;i++) {if (arr [i] <= ntemp) {J=j+1;swap (arr[j],arr[i]);}} Swap (Arr[j+1],arr[nhigh]); return j+1;} void QuickSort (int arr[],int nlow,int nhigh) {if (Nlow < Nhigh) {int nIndex = GetIndex (Arr,nlow,nhigh); QuickSort (arr, NLOW,NINDEX-1); QuickSort (Arr,nindex + 1,nhigh);}} int main () {#ifdef __cpluspluscout << "C + +" <<endl; #elsecout << "C" <<endl; #endifint arr[] = { 52,49,80,36,14,75,58,56,57,78,42,22,22,44}; QuickSort (arr,0,sizeof (arr)/sizeof (arr[0));p Rintarr (arr); return 0;}
Http://www.cnblogs.com/pugang/archive/2012/06/27/2565093.html
See the link above for specific logic
Android with Paint,canvas drawing