快排模板
1 void my_sort(int l,int r) 2 { 3 int i=l,j=r,mid=a[(l+r)>>1]; 4 while (i<=j) 5 { 6 while (a[i]<mid) 7 i++; 8 while (a[j]>mid) 9 j--; 10 if (i<=j) 11 { 12 swap(a[i],a[j]); 13 i++; 14 j--; 15 } 16 } 17 if (j>l) 18 my_sort(l,j); 19 if (i<r) 20 my_sort(i,r); 21 }
Every day is meaningful, keeping learning!