Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Bubble sort Pseudocode

Function bubbleSort (S: array sort item)


n = length(S)
repeat
swap = false
for i = 1 to n -1 do
if S[i-1] > S[i] then
S[i-1] = temp
temp = S[i]
S[i] = S[i] -1
swap = true
end if
end for
until not swap
end function

Insertion Sort Pseudocode

Function insertionSort(S: array sort item)
for i = 1 to length(A)
j = i
while j > 0 and S[j-1] > S[j]
swap(S[j-1], S[j])
j = j-1
end while
end for
end function


shell sort pseudocode

gap = round (n/2)
While gap > 0
for index = gap to n
temp = array[index]
subIndex = index
while subIndex >= gap and array[subIndex gap] > temp
array[subIndex] = array[subIndex gap]
subIndex = subIndex gap
array[subIndex] = temp
gap = round(gap/2)








merge sort pseudocode
if n <=1
return array
middle = n/2
for index = 0 to middle - 1
leftArray[index] = array[index]
for index = middle to n
rightArray[index-middle] = array[index]
left = mergeSort(left)
right = mergeSort(right)
return merge(left, right)

quick sort pseudocode

Quicksort(A as array, low as int, high as int)
if (low < high)
pivot_location = Partition(A,low,high)
Quicksort(A,low, pivot_location - 1)
Quicksort(A, pivot_location + 1, high)


Partition(A as array, low as int, high as int)
pivot = A[low]
leftwall = low

for i = low + 1 to high
if (A[i] < pivot) then
leftwall = leftwall + 1
swap(A[i], A[leftwall])

swap(A[low],A[leftwall])

return (leftwall)

You might also like