Having trouble with an assignment about sorting, the toilet stall problem


I’m in programming 2 and my professor is both unhelpful and a harsh grader. So I don’t want to take any chances so i wont get another F.

I’m sure this assignment is common enough that someone here has heard of it, Given a number of stalls, each stall should be filled in the midpoint of unfilled stalls. Currently, my code works for around 4-5 iterations, however it has to work for at least 30.

   {         for(int i=1;i<Stalls.length;i++)       {           if(Stalls[i]==false)           {             freeStallRange++;              i++;             }        }             Stalls[freeStallRange/2]=occupant;     }  

It looks blindingly simple right now, because I’m quite stumped at the moment, any assistance?