Sorting Practice

Work one sweep of Bubble sort at a time. Each sweep is carried out exactly as you write it, so a wrong sweep follows you into the next one — after the last sweep the array is either sorted or it is not.

You are not signed in, so this practice will not be recorded. Sign in first if your teacher is collecting it.

sweep 0:

  1. compare from to to find the index of the smallest number, idx =
  2. swap two nodes: node 1 address: ; node 2 address:

Sweep0 / 7
Wrong entries0
Answers shown0

Write it as C

The sweep you have been doing by hand, and the whole sort that calls it. The signatures are given — write the bodies, then press Check my code. Your bubble_sort must do its work by calling bubble_sweep. Your code is saved with your run for your teacher to read beside what you actually did.

Code for a sweep

void bubble_sweep(int *arr, int len, int i)

Code for the sorting

void bubble_sort(int *arr, int len)

Your sweeps so far

    How to fill in a sweep
    • The array is always 8 blocks, so every run is 7 sweeps, numbered 0 to 6.
    • In sweep k, positions arr[0] … arr[k-1] are already settled (shown dark). The scan covers the rest: from arr[k] to arr[n-1].
    • idx is the index of the smallest value in that range (the largest, in descending order).
    • The swap is between two nodes, so those blanks take addresses, with the &: &arr[k] and &arr[idx]. Step 1 names elements, not addresses, so no & there. If the value is already in place, tick no swap needed.
    • A blank accepts arr[3], &arr[3] or just 3. Enter works like Apply.
    • Use ← and → (or the arrows beside the sweep number) to walk back through sweeps you have already applied. A past sweep is read-only; clicking a line in the log jumps to it.