Bubble sort

?
  • Created by: glennw
  • Created on: 09-05-19 12:49

How does bubble sort work?

Compares the current number starting with the first in the list and compares them with the next number, if the next number is smaller then the two are swapped this is repearted untill the no number is bigger than the next number in the list. 

1 of 2

Bubble sort (Must Know!)

FUNCTION bubblesort(list)

REPEAT

swapped = false

FOR n = 1 TO LEN(list)-1

IF list[n-1] > list[n] THEN

temp = list[n-1]

list[n-1] = list[n]

list[n] = temp

swapped = true

END IF

NEXT n

UNTIL NOT swapped

RETURN list

END FUNCTION

2 of 2

Comments

No comments have yet been made

Similar Computing resources:

See all Computing resources »See all Data structures resources »