You are on page 1of 1

Department of Computer Science, Mathematics & Physics

COMP0002 – Prelim Computer Science II
Lab #3: Sorting & Functions

Question One

Define a Bubble Sort FUNCTION (which carries out a bubble sort on an array) along with a Swap
FUNCTION (which can be used to swap two values in an array).
[3 + 3 Marks]
You are then required to write an algorithm which accepts 10 character values from a user and
store them in an array. Once this is completed, call the Bubble Sort function to sort your array
in ascending order. Be sure to the call the Swap function at the appropriate time. Display the
sorted list.
[10 marks]
Question Two

Write an algorithm defining a stack structure which can hold a maximum of 5 integer elements.
Each of the four stack operations (pop, push, isEmpty, isFull) should be written as functions.
Your algorithm should ask the user whether they want to do:
[1] add to the stack,
[2] remove from the stack or
[3] exit
and carry out the appropriate steps. Your algorithm should allow the user to repeatedly carry
out these tasks until they have indicated that they are finished, at which time the algorithm
should display the contents of the stack and then end.
[20 marks]

“A whole stack of memories never equal one little hope.”
~ Charles M. Schulz