sort char array c 2b 2b using insertion sort descending order

Solutions on MaxInterview for sort char array c 2b 2b using insertion sort descending order by the best coders in the world

showing results for - "sort char array c 2b 2b using insertion sort descending order"
Logan
29 Oct 2016
1	// Sort in ascending order
2	int j;
3    char k;
4    for (int i = 1; i < length; i++)
5    {
6        k = arr[i];
7        j = i - 1;
8        while (j >= 0 && arr[j] > k)
9        {
10            arr[j + 1] = arr[j];
11            j--;
12        }
13        arr[j + 1] = k;
14    }
15    std::cout << arr << "\n";
Ethan
17 Jun 2018
1	// Sort in descending order
2	int j;
3    char k;
4    for (int i = 1; i < length; i++)
5    {
6        k = arr[i];
7        j = i - 1;
8        while (j >= 0 && arr[j] < k)
9        {
10            arr[j + 1] = arr[j];
11            j--;
12        }
13        arr[j + 1] = k;
14    }
15    std::cout << arr << "\n";