Sorting Algorithms Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Bubble Sort

A
for outer = (listLength - 1) to 0 step -1 
For inner = 0 to outer
if list(inner) > list(inner+1) then
Swap values
End if
Next inner
Next outer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Insertion Sort

A
Set current to 0
Set position to 0
For counter = 1 to (listlength-1)
Set current to list(counter)
Set position to counter
WHILE (position > 0) AND list(position -1) < current DO
SET list(position) TO list(position-1) 
Set position to position - 1
END WHILE
Set list(position) TO current
END FOR
How well did you know this?
1
Not at all
2
3
4
5
Perfectly