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]);
        }
    }
}

 

你可能感兴趣的:(select)