Saw this challenging question posted in the hardwarezone forum on sorting an array with one for loop without using array list.
The question is
This is a simple programming question...very simple and short question, but its really hard to solve.. Anyone who could do it, you are god of programming. Given an array of random numbers let say.. arrayX = {15, 20, 35, 45, 10, 40, 1, 3, 45};You are supposed to use ONLY ONE loop to swap the above into the following: arrayX = {15, 20, 3, 1, 10, 40, 45, 35, 45}; NOTE: The purpose of your loop is to move all digits < 25 from the right hand side to the left side, and move all digits >= 25 to the right side. You can't sort the array but to use a single loop to scan the array from left and scan the array from right...and do the necessary swapping. You can try do it with C, C++...etc.. Not easy as it seems to be!
Since the night is still young, I took some time to sit down and figure out the solution.