Question
Create a class called Stack with the following members: a. A private integer array called stack that contains STACK_SIZE elements. You will only use this
Create a class called Stack with the following members:
a. A private integer array called stack that contains STACK_SIZE elements. You will only use this array in your constructor and st functions. Do NOT use it directly with any of your other member functions!
b. A private integer pointer called stack_pointer.
c. A public constructor. This constructor will set the stack_pointer to the bottom of the stack. Remember that stacks grow from bottom to top!
d. A public void function called push. This function takes one integer parameter which is the value to be pushed on the stack. This function will push the given value onto the stack.
e. A public function called pop. This function takes no parameters, but returns an integer. This function will pop the value given by the stack pointer.
f. A public function called sp. This function takes no parameters, but returns an integer pointer. This function will return the stack pointer variable.
g. A public function called st. This function takes no parameters, but returns an integer pointer. This function will return the TOP of the stack array. Remember that the stack grows from bottom to top. This function always returns the address of the top (the first element of the stack array).
NOTE: Notice that there are no if statements, conditionals, or any boolean logic for a stack. It is up to the user to make sure that they do not exceed the bounds of the stack. As such, you must not have any sanity checks in your code!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started