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 – 2015-05-10T18:34:14.063
@Optimizer Correct – Meow Mix – 2015-05-10T18:38:09.223
1Do you have to print the intermediate steps? – xnor – 2015-05-10T18:50:19.827
Can you show more examples? – Ismael Miguel – 2015-05-10T22:46:14.927
7can we just return 1,2,3,4,5,6,7,8,9? – Ewan – 2015-05-11T09:27:01.400
Should the output of the program be just the final sorted array ? – Optimizer – 2015-05-11T10:07:20.167
@user3502615 Should the program have any output? If so, what? – isaacg – 2015-05-11T10:09:07.077