Compare first
Select two neighboring positions and compare before swapping.
Compare neighboring numbered carriages and swap them into sorted order.
Grades 3 to 5 · Computer Science
Your goal
Put the carriages in nondecreasing order, smallest first. Select neighboring positions, compare them, then swap when needed. Equal values may stay together.
Reduced motion is on. The controls still update the scene.
Current train order: 3, 1, 2, 1. Comparisons: 0. Swaps: 0. Compare the selected pair before swapping.
Only pressing Compare increases the comparison counter. Only a legal swap increases the swap counter. There is no automatic sorting. Try another strategy after resetting and compare its actual work.
Sorting Train brings an algorithm into a familiar railway yard. Numbered carriages arrive out of order, including repeated values that belong next to each other in the finished train. Select neighboring positions, compare their numbers, and decide whether a swap helps. Each deliberate comparison and legal swap contributes to its own counter, so students can compare the work required by different strategies. Repeated left to right passes offer one useful approach. Resetting the same train makes it possible to try another strategy and explain how its sequence of decisions differs.
Select two neighboring positions and compare before swapping.
Nondecreasing order allows equal values side by side without a swap.
Compare different strategies using the separate comparison and swap counters.
Explore adjacent sorting strategies and count the comparisons and swaps performed. Ask students to predict what will happen, change one setting, and explain what they observe. Learn gives a starting point. Practice and Challenge offer new goals with the same scene.
Discrete adjacent compare and swap model with up to 200 operations. Counters are reconstructed from a validated operation history; duplicate values remain distinct carriages with equal numbers.