QUICK Flashcards
Bubble sort
Procedure BubbleSort(List)
n = len(list)
repeat
swapped = false
for i = n to n - 1
if list[i - 1] > list[i] then
temp = list[i - 1]
list[i-1] =list[i]
list[i] = temp
swapped = true
end if
end for
until not swapped
end procedure
insertion sort
Procedure InsertionSort(List)
n = len(list)
for i = n to n - 1
temp = list[i]
z = i
if z > 0 and list[z - 1] > temp
list[z] = List[z-1]
z = z - 1
End While
List[z] = Temp
Next i
End Procedure
binary search
Function BinarySearch(List, SearchItem)
Lo = 0
Hi = Len(List) - 1
While Hi >= Lo
Mid = Lo + (Hi - Lo ) DIV 2
If SearchItem = List[Mid] Then Return Mid
Else if SearchItem < List[Mid]
Then
Hi = Mid - 1
Else
Lo = Mid + 1
End If
End While
Return -1
End Function