Answers for "sort char array c++ using insertion sort descending order"

C++
0

sort char array c++ using insertion sort

// Sort in ascending order
	int j;
    char k;
    for (int i = 1; i < length; i++)
    {
        k = arr[i];
        j = i - 1;
        while (j >= 0 && arr[j] > k)
        {
            arr[j + 1] = arr[j];
            j--;
        }
        arr[j + 1] = k;
    }
    std::cout << arr << "\n";
Posted by: Guest on April-26-2021
0

sort char array c++ using insertion sort descending order

// Sort in descending order
	int j;
    char k;
    for (int i = 1; i < length; i++)
    {
        k = arr[i];
        j = i - 1;
        while (j >= 0 && arr[j] < k)
        {
            arr[j + 1] = arr[j];
            j--;
        }
        arr[j + 1] = k;
    }
    std::cout << arr << "\n";
Posted by: Guest on April-26-2021

Code answers related to "sort char array c++ using insertion sort descending order"

Browse Popular Code Answers by Language