Ready to begin
No records have been processed. Start with Next step.
![For [ID,Physics] pairs, compare the last component. [1,45] comes before [3,53] in ascending Physics order.](/images/computational-thinking/week-6/pair-key.png)
Follow the selected procedure. Change a field, tie rule or weekday and explain why the result changes.
Ready
No records have been processed. Start with Next step.
Predict the next change. Keep track of which list level, field and position convention the procedure uses.
# In SortedListInsert for [ID,Mark] pairs:
if last(x) < last(z):
newList = newList ++ [x]
inserted = true
# Always append the WHOLE z pair after the test.
# Build pairs for a chosen subject:
marksList = []
foreach X in ScoreRecords:
marksList = marksList ++ [[X.CardNo,X[Subject]]]The outer list contains pairs; first(pair) is the ID and last(pair) is the selected mark. Comparing entire pair objects may use the wrong ordering in a programming language. State that the mark is the key. Only the comparison changes; the outer insertion pattern remains the same.
The source’s BuildMarksList moves rows from one table to another. Restore the data between consuming calls for Maths and Physics. Our explorer reads the existing records without consuming them, so several views can be produced safely.
Why not sort [ID,mark] pairs by first(pair)?
That sorts IDs rather than marks.
When moving a pair, do you copy only its key?
No. Copy both ID and mark so their association survives.
What does last(first(marksList)) return on a non-empty pair list?
The mark stored in the first pair, not the entire pair or the student ID.