selection sorting

implements of slection sorting with c++ code

template<class T> void selectionSort_1(T srcArr[],int n)
{
    for (int i = 0;i < n ;i++)
    {
        int index = i;
        for (int j = i+1;j < n ;j++)
        {
            if (srcArr[j] <= srcArr[i])
            {
                index = j;
            }
        }
        if (index != i)
        {
            swap(srcArr[i],srcArr[index]);
        }
    }
}

 

posted @ 2013-01-13 23:26  理想空间  阅读(267)  评论(0编辑  收藏  举报