Bubbling algorithm + selection algorithm

void BubbleSort(int arr[], int n)
{
    for(int i = 0; i < n - 1; i++)
    {
        for(int j = 0; j < n - i - 1; j++)
        {
            if(arr[j] > arr[j+1])
                std::swap(arr[j],arr[j+1]);
        }
    }
}
void select_sort(int  p[], int length)
{
    int index;
    for (int i = 0; i < length - 1; i++)
    {
        index = i;
        for (int j = i + 1; j < length;j ++)
        {
            if (p[index] < p[j])
            {
                index = j;
            }
        }

        swap(p[index], p[i]);
    }
}

 

Guess you like

Origin blog.csdn.net/weixin_42137874/article/details/110410562