You are assigning true to sorted in the first code and false in the second.
It is also only the first time the code runs that hardcoding the values would work the same, as the next time the value is the opposite and would negate to false (and then to true, and so on).