I have been told by my teacher that you don't have to be able to write one one the spot, but you have to be able to tell what one is by reading it. It is obvous that it would be better if you could though.
I've been told that the only ones you need to be able to replicate are Linear and Binary search. You would, however, need to know how the others work and be able to recognise them when reading the algorithm.
BEGIN bubbleSort
set counter = 1
set end = last index of array
WHILE end>1
counter=1
WHILE counter < last
IF thearray[current] > thearray[current+1] THEN
temp=thearray[current] //swaps the two
thearray[current]=thearray[current+1]
thearray[current+1]=temp
END IF
increment counter
ENDWHILE
decrement end
ENDWHILE
END
i'm still learning how to make the swap a function though D: ... test on tuesday morning
EDIT: OMG TOMORROW
i just learnt the insertion sort, which i just learnt
Code:
BEGIN MAINPROGRAM
set first to 1
set last to 100
set positionofnext to last -1
WHILE positionofnext => first //until there is no longer unsorted part
next = thearray[positionofnext]
current = positionofnext
WHILE current<last and thearray[current]>thearray[current+1]
increment current
thearray[current-1]=thearray[current]
ENDWHILE
thearray[current]=next
decrement positionofnext //reduces unsorted part by 1
ENDWHILE
END MAINPROGRAM