In this sorting method, elements are flipped and added in the last of the list. This is also known as PanCake Sorting.
Input:
{1, 2, 5, 4, 3, 10, 9, 8, 7}
Output:
Including all intermediate results
10 3 4 5 2 1 9 8 7
9 8 7 1 2 5 4 3 10
8 7 1 2 5 4 3 9 10
7 1 2 5 4 3 8 9 10
5 4 3 2 1 7 8 9 10
4 3 2 1 5 7 8 9 10
3 2 1 4 5 7 8 9 10
2 1 3 4 5 7 8 9 10
1 2 3 4 5 7 8 9 10
1 2 3 4 5 7 8 9 10 (final Result)
Input:
{1, 2, 5, 4, 3, 10, 9, 8, 7}
Output:
Including all intermediate results
10 3 4 5 2 1 9 8 7
9 8 7 1 2 5 4 3 10
8 7 1 2 5 4 3 9 10
7 1 2 5 4 3 8 9 10
5 4 3 2 1 7 8 9 10
4 3 2 1 5 7 8 9 10
3 2 1 4 5 7 8 9 10
2 1 3 4 5 7 8 9 10
1 2 3 4 5 7 8 9 10
1 2 3 4 5 7 8 9 10 (final Result)
No comments:
Post a Comment