Can you not simply reverse the loop?

reset the values of min and max
Create another while loop


while ( min >= 0) { ... }

Then work your way down
Something like