Write code which uses an array to implement a stack of nonnegative (i.e. greater or equal to zero) integers.

Question

Your code should implement the following functions:
stackEmpty

Returns true if the stack is empty or false if it is not.

stackFull

Returns true if the stack is full or false if it is not.

push

Accepts an integer parameter. Adds the value to the stack and returns the value of the parameter if successful. If the stack is full or the parameter is a negative integer, returns -1.

pop

Returns the value at the top of the stack. Returns -1 if the stack is empty.

Your answer should include code which tests that each of the four functions is working correctly.

Leave an answer

Sorry, you do not have permission to answer to this question .