Question
Language: C++ Design and implement a generic stack class. By using templates your stack has to be able to store any type of data. The
Language: C++ Design and implement a generic stack class. By using templates your stack has to be able to store any type of data. The underlying data structure should be an array. While designing and implementing your class you cannot use any of the container classes from the Standard Template Library (STL). Your class should support the following operations (read all the requirements before starting to write code): Stack(): this constructor initializes the stack to a size of 10. Stack(const Stack&): copy constructor, create a real copy of the stack. Stack(int size): this constructor sets the stacks size to the given size. bool push(T element): adds element to the top of the stack. It should return true, if the element has been successfully pushed. So as long as you do not provide an extend() method, you need to check for available space and return false if there is no more space. bool pop(T& out): pops an element from the top of the stack. The element is put into out. It should not crash if there are no elements on the stack, but rather return false, otherwise it should return true. T back(void): returns the data on the top of the stack, without changing the stack. int getNumEntries(): returns the number of entries of the stack at a given moment. Destructor for the template class.
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