Rob Prime wrote:I doubt you can do it with just one single loop.
Consider an array {4, 7, 3}. After not-swapping 4 and 7, the index moves one forward and you swap 7 and 3. The array is then {4, 3, 7}. Doesn't look sorted, does it?
hi guys, im new here and new to
java. based on what rob said, i think you should add 1 more loop to check the reverse way.
eg : you got {4,7,3}
currently it will sort to {4,3,7}.
then you check from reverse,
i think you will get
{3,4,7}
because 7 and 3 will not swap, but 3 and 4 will.
then add 1 more loop to check both sides of array[n], to make sure that its in the right spot.
im still new, but this is my input.