//Ex5_20.cpp
#include "iostream" 
using namespace std;
template <class TEM> //定义函数模板，模板类型参数为TEM 
void sort(TEM x[],int n) 
{int i,j,k; TEM w;   //注意w变量的定义需与数组元素类型一致 
 for(i=0;i<n-1;i++) 
 {k=i; 
  for(j=i+1;j<n;j++) 
    if(x[k]>x[j])k=j; 
  if(i!=k){w=x[i];x[i]=x[k];x[k]=w;} 
 } 
} 
void main() 
{int i,a[10]={3,1,5,4,6,0,7,8,2,9}; 
 double b[5]={3.2,1.7,2.8,5.1,6.8}; 
 sort(a,10);   //调用函数，对int型数组排序 
 sort(b,5);    //调用函数，对double型数组排序 
 for(i=0;i<10;i++) cout<<a[i]<<"  ";
 cout<<endl; 
 for(i=0;i<5;i++) cout<<b[i]<<"  ";
 cout<<endl; 
}
