Question
C++ programming language Class Static: This class implements all methods required for an array based version ( static ) of a stack and queue that
C++ programming language
Class Static:
This class implements all methods required for an array based version ( static ) of a stack and queue that stores integers.
Class Static's methods function exactly as above with the following exceptions:
The constructor is going to take an argument and dynamically allocate an array of argument elements. It's going to set capacity to the argument. It's going to initialize length to 0. Use this length attribute in the same way I described using Top during lecture, except a length of 0 means it's empty, it never gets set to -1. You will need to figure out the adjustment to get the push and pop to work correctly.
The destructor deallocates the array.
clear() - resets the stack or queue to be empty
peek() - sets the reference parameter to either the top value of the stack, or the front of the queue, depending on how the class is used.
#include "Static.h" #include using namespace std; int main() { Static s(5); for(int i = 0; i Each of front, back --| and length are optional, depending on our implementation Static --head : int" -capacity int front: int back: int +Static( cap: int) +-Static) +push(i: int): int tenqueue(i int): int +pop(i: int&): int +dequeue( int&): int +dequeue(i : int&): int +clear): int +peek(i int&): const int tisFull(): const bool tisEmpty(): const bool +length(): const int I +print) : const void const int means the return type is int, -and the method should be marked const
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