8
The Question
Given a set of 9 numbers, m[]
, which contains only numbers 1 through 9 in a random order, with no two numbers being the same, create a program in any language which rearranges the number to be in numerical order (1, 2, 3, etc. etc.) by only switching two numbers which are next to each other (ie. 1, 3, 2 → 1, 2, 3).
Rules
- You may only modify the set by switching two numbers which are next to each other
- The ending numbers (1 through 9 in order) should be contained in
m[]
- You can use any language you would like
- The answer with the smallest amount of bytes wins
Edit:
Your code does not have to print the output, but the rearranged array must be in m[]
.
6So basically a Bubble Sort algorithm ? – Optimizer – 10 years ago
@Optimizer Correct – Meow Mix – 10 years ago
1Do you have to print the intermediate steps? – xnor – 10 years ago
Can you show more examples? – Ismael Miguel – 10 years ago
7can we just return 1,2,3,4,5,6,7,8,9? – Ewan – 10 years ago
Should the output of the program be just the final sorted array ? – Optimizer – 10 years ago
@user3502615 Should the program have any output? If so, what? – isaacg – 10 years ago