
Even if the program looks complicated - it is quite simple:
- "RowEnd" searches the end of the current row. If the end is reached
- "Longer" checks if the row above is longer. If not, Kara uses
- "Next Row" to get to the next row and restarts with "RowEnd". If the row above is longer, the two rows have to be swapped. This is done using
- "Swap". Afterwards, Kara continues in
- "*Next Row" and
- "*RowEnd". The states "*Next Row" and "*RowEnd" do exactely the same thing as "Next Row" and "RowEnd". The difference is that in these two states, Kara knows that at least two rows have been swapped. And that he therefore has to start over when reaching the bottom. This is done using the state
- "Restart". If Kara reaches the bottom in the state "Row", he knows that no rows have been swapped and that he can stop.