Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ 4. Write a stack class using an array (from the heap) to implement it. What is a stack? We saw the run-time stack in

C++
image text in transcribed
4. Write a stack class using an array (from the heap) to implement it. What is a "stack"? We saw the run-time stack in class. It is a data structure that allows us to "push" an element to the "top", to "pop" from the "top". In fact, for the no-recursive towers, we used a vector as a stack. class stack\} private: int top; // top is the index into the array for the current top int * p;//p is a pointer into the heap where the stack is actually //located. Just like for SA class. int size; // size of the array allocated for the stack public: stack(); // a stack to hold 100 stack(int n ) // a stack to hold n elements rstack(); bool empty(); void push( int );// don't forget to test if stack is full int pop();// return and remove the "top" element of the stack. // don't forget to test if the stack is empty Test it with the following main function: int main()\{ stack s(10); s.push(1); s.push(2); s.push(3); for ( i=0;i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

b. Determine the 95% confidence intervals for the parameters.

Answered: 1 week ago