ソート実装の選択


#include
using namespace std;
template<class T>
void Swap(T &a,T &b)//     
{
    T t = a;
    a = b;
    b = t;
}
template<class T>
void selectSort(T a[],int n)
{
    int leastIndex;
    for(int i = 0;i < n-1;i++)
    {
        leastIndex = i;
        for(int j = i+1;j < n;j++)
            if(a[j] < a[leastIndex])
                leastIndex = j;
        Swap(a[i],a[leastIndex]);
        for(int k = 0;k < n;k++)cout << a[k] << " ";
        cout << endl;
    }
}
int main()
{
    int a[] = {2,1,4,7,4,8,3,6,4,7};
    selectSort(a,10);
}
1 2 4 7 4 8 3 6 4 7 
1 2 4 7 4 8 3 6 4 7 
1 2 3 7 4 8 4 6 4 7 
1 2 3 4 7 8 4 6 4 7 
1 2 3 4 4 8 7 6 4 7 
1 2 3 4 4 4 7 6 8 7 
1 2 3 4 4 4 6 7 8 7 
1 2 3 4 4 4 6 7 8 7 
1 2 3 4 4 4 6 7 7 8