Pseudocode For Sorting Algorithms
Pseudocode For Sorting Algorithms
int TEMP
int J
int I = 0
loop while I <= size -1
input A[I]
J = I
loop while J > 0 and A[J] < A[J - 1]
TEMP = A[J]
A[J] = A[J - 1]
A[J - 1] = TEMP
J = J - 1
end loop
I=I+1
end loop
Bubble Sort
int TEMP
int J
int I = 0
loop while I < size -1
J = 0
loop while J < size -1
if A[J] > A[J + 1] then
TEMP = A[J]
A[J] = A[J + 1]
A[J + 1] = TEMP
end If
J=J+1
end loop
I=I+1
end loop
Selection sort
The idea of Selection Sort is that we repeatedly find the smallest
element in the unsorted part of the array and swap it with the first
element in the unsorted part of the array.
int I=0
int J
int SMALLSUB
int TEMP
loop while I <= size -1
SMALLSUB = I
J=I+1
loop while J <= size -1
if A[J] < A[SMALLSUB] then
SMALLSUB = J
end-If
J=J+1
end loop
TEMP = A[I]
A[I] = A[SMALLSUB]
A[SMALLSUB] = TEMP
I=I+1
end loop