Question 5
OCR Computer Science June 2024 Algorithms and programming (H446-02)A level12 marks
On the specification
- (a)
- 1.4 Data types, data structures and algorithms2.3 Algorithms
- (b)
- 1.4 Data types, data structures and algorithms2.3 Algorithms
- (c)
- 2.2 Problem solving and programming2.3 Algorithms
Question text
5 The contents of a stack are stored in the 1-dimensional array called numbers. topStack stores the index of the next free space in the stack. The array is declared with space for 100 elements. (a) The function pop() returns the next item from the stack and updates the appropriate pointers. Describe the steps in the function pop(). [4] (b) The function push() inserts its parameter called dataValue onto the stack and updates the appropriate pointers. Complete the function push() using pseudocode or program code. function push( ) if != 100 then numbers[ ] = dataValue topStack = topStack + return true else return false endif endfunction [4] (c) Write an algorithm, using pseudocode or program code, to call the function push() with the value 15 and output a message saying "Added" if the value was successfully inserted onto the stack or "Not Added" if the stack is full. [4]