#ifndef QUICK_SORT_H #define QUICK_SORT_H #include<assert.h> template<class T,int n> void swap(T* s,int i,int j) { assert((i<n)&&(j<n)); T temp=s[i]; s[i]=s[j]; s[j]=temp; } template<class T,int n> int partition(T* s,int start,int end) { int i= start; int devide_line=start; int standard=s[end]; for(;i<end;i++) { if(i!=devide_line&&s[i]<standard) { swap<T,n>(s,i,devide_line); ++devide_line; } } swap<T,n>(s,devide_line,end); return devide_line; } template<class T, int n> void quick_sort(T* s,int i=0,int j=n-1) { if(s==0) return; if(i>=j) return; int devide_line =partition<T,n>(s,i,j); quick_sort<T,n>(s,i,devide_line-1); quick_sort<T,n>(s,devide_line+1,j); } #endif