#ifndef SELECT_SORT_H #define SELECT_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> T get_smalllest(T* s,int i) { assert(i<n); T result=i; for(;i+1<n;i++) { if(s[result]>s[i+1]) result=i+1; } return result; } template<class T,int n> void select_sort(T* s) { int i=0; for(;i<n-1;i++) swap<T,n>(s,i,get_smalllest<T,n>(s,i)); } #endif