Page 304 - Learn to Program - Basic-256
P. 304
Chapter 19: Stacks, Queues, Lists, and Sorting Page 288
swapping the order of adjacent items until the sort is complete,
Start
set sorted flag to true
start with first two elements of array
i = 0
have we compared all yes
no
elements?
i = length(d) - 2
yes
no is array
sorted?
no is the next element yes
less than the current?
d[i+1] > d[i]
Finish
swap elements
t = d[i]
d[i] = d[i+1]
d[i+1] = t
and set sorted flag
to false
move to next element
i = i+1
Illustration 36: Bubble Sort - Flowchart
1 # bubblesortf.kbs
2 # implementing a simple sort
3
4 # a bubble sort is one of the SLOWEST algorithms
© 2019 James M. Reneau (CC BY-NC-SA 3.0 US)

