Also used acm.java.
This uses selection sort, one of the easier (but a bit inefficient) ones.
It checks all the elements in an unsorted array… (marked blue when checking)
and selects the appropriate one, and inserts in the proper order. The result below:
what I did was quite inefficient but it worked.
I had two arrays: one an int array to store an actual number array, and the other an array of GRects.
The height value of the GRects would match the numbers in the int array.
In the sort method part that actually sorted stuff, I sorted not the numbers but compared the GRects’ height values instead. The coding got a bit dirty as as result, but programming the bars to change color was much more easier this way.
The fact that the (0,0) point of the acm package lies in the top left created a lot of bugs. In order to pull the bars to the ground, I had to subtract the canvas size and then add the height values.