The answer, in order
Sorting the answer means moving whole rows. To sort is to put rows in order by one column. Here the order is smallest due first. Arrival order is the order in which the rows came.
- Four rows, in arrival order.
- Smallest due found: A-107 with 0.
- Next smallest: A-104 with 800.
- The rest follow: whole rows moved.
The rule
Sorting moves whole rows and compares one field at the key's position. The comparison is strict. Tied rows are never swapped with each other. Sorting nothing is not an error.
The sort key is the column to sort by, such as due. The sign < is strict: equal dues do not count as smaller.
A pass is one trip through the rows to find the smallest. Two names hold positions, not rows. The name best marks the smallest due so far. The name look marks the row being checked. The name column is the position of the column to compare.
if (answer[look][column] < answer[best][column]) {best = look;}
A swap exchanges two WHOLE rows. Their four values stay together, not just the due.
A-103, A-106, A-108 and A-111 all owe 1450 rupees. Sort only these four, and none is smaller than another. So none would move. But a swap with a smaller row can move a tied row. One tied row can end up after another it started before.
The lab has a copy loop. It copies the rows into a new list. You write the passes.
Loading lab…
Sorting nothing hands back nothing — that is not an error.