Pseudocode
← Building blocks
Bubble sort
built by teacher Quan
Example
One full bubble sort
Efficient (Swap flag + Top)
Already sorted (no swaps)
1
DECLARE Num : ARRAY[1:4] OF INTEGER
2
DECLARE Pass : INTEGER
3
DECLARE Index : INTEGER
4
DECLARE Temp : INTEGER
5
FOR Pass ← 1 TO 3
6
FOR Index ← 1 TO 4 - Pass
7
IF Num[Index] > Num[Index + 1] THEN
8
Temp ← Num[Index]
9
Num[Index] ← Num[Index + 1]
10
Num[Index + 1] ← Temp
11
ENDIF
12
NEXT Index
13
NEXT Pass
Hide notes
← Step
Step →
Reset
Random