Code

sort.go — the skeleton you fill in

Create sort.go (see the panel).

The file in the panel is complete and correct — you will create exactly that. It has the package, the import, three signatures, the contracts, and a panic("not implemented") in each.

Your job is to replace those three panics with real code, working from the previous step's pseudocode.

Read the contracts, not just the signatures

The doc comments state everything the test will check:

  • BubbleSort — stable; exactly n−1 comparisons on sorted input;
  • SelectionSortnot stable; exactly n(n−1)/2 comparisons on any input; at most n−1 swaps;
  • InsertionSort — stable; exactly n−1 comparisons and zero swaps on sorted input.

Three of those are exact numbers, not bounds. If your implementation gives n where n−1 is required, the test will catch it — and that is a real defect, not pedantry: it means you are comparing something twice, or comparing an element with itself.