#include<iostream>
template<class T>
void Swap(T &x,T &y)
{
T temp;
temp=x;
x=y;
y=temp;
}
template <class T>
void SelectionSort(T A[],int n)
{
int smallIndex;
int i,j;
for(i=0;i<n-1;i++)
{
smallIndex=i;
for(j=i+1;j<n;j++)
if(A[j]<A[smallIndex])
smallIndex=j;
Swap(A[i],A[smallIndex]);
for(int k=0;k<n;k++)
cout<<A[k]<<" ";
cout<<endl;
}
}
int main()
{
int data1[]={1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20};
cout << "排序前的数据:" << endl;
for(int i=0;i<20;i++)
cout << data1[i] << " ";
cout << endl;
cout << "开始排序..." << endl;
SelectionSort(data1, 20);
cout << "排序后的数据:" << endl;
for(int i=0;i<20;i++)
cout << data1[i] << " ";
cout << endl;
}