For example, if the numbers are:
30, 12, 49, 6, 10, 50, 13
The array will be:
[10, 6, 30, 12, 49, 13, 50]
This can be done in O(n):
Of course, this assumes that all elements are distinct, otherwise sometimes it will fail.