How to sort numbers from STDIN

You get 10 numbers on STDIN, each followed by newline character, after that you have to display those numbers sorted from the smaller to the bigger. You cannot use sorting algorithms.


  1. If you will use any algoritm to show them sorted, that algorythm might be called "sorting algorythm" and become illegal to use ;)

  2. Hi Alex,

    sure, you're right :)

    I will precise this in that way: you can't use sort algorithms on data structure, that you are using to keep numbers after receiving them all from user.

  3. What about storing them into the tree? ;) will the "left/root\right" way of extracting numbers from tree be treating as sorting algorithm then? ;)

  4. I think, that it wouldn't be sorting :P

    There is plenty ways to do that, e.g. store new number in list in ordered way. This could be also done by storing numbers in array and then display smallest number and indicate in other array, that this element won't be displayed in next iteration. This would be repeated for all numbers in array.