Bubble sort Please use speaker notes for additional information!
Bubble sort - PASS #1 Original numbers: SUB1 1 SUB Compare 5 which is what SUB1 is pointing to and 6 which is what SUB2 is pointing to. In this instance, 5 < 6 so nothing is done. After numbers: HOLDEND-PT 5 FLIP-CT 0
Bubble sort - PASS #1 Before numbers: SUB1 1 2 SUB Compare 6 which is what SUB1 is pointing to and 6 which is what SUB2 is pointing to. In this instance, 6 > 2 so flip and add one to the flip-ct.. After numbers: HOLD 6 END-PT 5 FLIP-CT
Bubble sort - PASS #1 Before numbers: SUB SUB Compare 6 which is what SUB1 is pointing to and 3 which is what SUB2 is pointing to. In this instance, 6 > 3 so flip and add one to the flip-ct.. After numbers: HOLD 6 END-PT 5 FLIP-CT
Bubble sort - PASS #1 Before numbers: SUB SUB Compare 6 which is what SUB1 is pointing to and 4 which is what SUB2 is pointing to. In this instance, 6 > 4 so flip and add one to the flip-ct.. After numbers: HOLD 6 END-PT 5 FLIP-CT
Bubble sort - PASS #1 Before numbers: SUB SUB At this point SUB2 is greater than END-PT so the pass is complete. After numbers: HOLDEND-PT 5 FLIP-CT
Bubble sort - Reset for PASS #2 Before numbers: SUB1 1 SUB2 2 HOLDEND-PT 5 4 FLIP-CT 0
Bubble sort - PASS #2 Before numbers: SUB1 1 SUB Compare 5 which is what SUB1 is pointing to and 2 which is what SUB2 is pointing to. In this instance, 5 >2 so a flip is done and 1 is added to flip-ct. After numbers: HOLD 5 END-PT 4 FLIP-CT
Bubble sort - PASS #2 Before numbers: SUB1 1 2 SUB Compare 5 which is what SUB1 is pointing to and 3 which is what SUB2 is pointing to. In this instance, 5 >3 so a flip is done and 1 is added to flip-ct. After numbers: HOLD 5 END-PT 4 FLIP-CT
Bubble sort - PASS #2 Before numbers: SUB SUB Compare 5 which is what SUB1 is pointing to and 4 which is what SUB2 is pointing to. In this instance, 5 >4 so a flip is done and 1 is added to flip-ct. After numbers: HOLD 5 END-PT 4 FLIP-CT
Bubble sort - PASS #2 Before numbers: SUB SUB At this point SUB2 is greater than END-PT so the pass is complete. After numbers: HOLDEND-PT 4 FLIP-CT END-PT signals the end of the pass. We can test either by using SUB2 > END-PT or SUB1 = END-PT.
Bubble sort - Reset for PASS #3 Before numbers: SUB1 1 SUB2 2 HOLDEND-PT FLIP-CT 0
Bubble sort - PASS #3 Before numbers: SUB1 1 SUB Compare 2 which is what SUB1 is pointing to and 3 which is what SUB2 is pointing to. In this instance, 2< 3 so a no flip is done. After numbers: HOLDEND-PT 3 FLIP-CT 0
Bubble sort - PASS #3 Before numbers: SUB1 1 2 SUB Compare 3 which is what SUB1 is pointing to and 4 which is what SUB2 is pointing to. In this instance, 3< 4 so a no flip is done. After numbers: HOLDEND-PT 3 FLIP-CT 0
Bubble sort - PASS #3 Before numbers: SUB SUB At this point SUB2 is greater than END-PT so the pass is complete. AND since there were no flips the sort is complete. After numbers: HOLDEND-PT 3 FLIP-CT 0 END-PT signals the end of the pass. We can test either by using SUB2 > END-PT or SUB1 = END-PT.