Write an algorithm to check whether two numbers in a pair is in ascending order or descending order. (for example 10,2 : 2,10)
Answers
Answered by
1
(☞゚∀゚)☞Answer
in pairs:
1 5
7 1
3 8
5 6
out pairs:
1 7 <-- swapped
1 5
6 5 <-- swapped
8 3 <-- swapped
^^ Without swapping pairs it is impossible to build the solution. So we swap pairs (7, 1), (3, 8) and (5, 6) and build the result. or
in pairs:
1 5
6 9
out:
not possible
One more example that shows how 'sorting pairs' first isn't the solution.
in pairs:
1 4
2 5
out pairs:
1 4
5 2
please make me brainlest for my hard work
Similar questions