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";
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";