I need to implement the following in both pseudocode and java.
Input: an array of integers
Output: Rearrange the array to have the following:
There is no space requirement for the algorithm, only that the problem is solved in O(n) time.
Thus, I am under the impression that a bubble sort is best here.
A swapping algorithm in this case is not the best option and I would like to get some feedback on other methods that can be implemented here.
Thank you!
create an array with space to fit all the elements. If number is < x then place it at the beginning of the array, if number is > x then place it at the end. If number is equal to x then just ignore it and move on. Finally you fill up the remaining spots with the values equal to x.