Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Write a stack class using an array (from the heap to implement What is a \"st

ID: 3843598 • Letter: 4

Question

4. Write a stack class using an array (from the heap to implement 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 from the "top". In fact, for the non-recursive towers problem, we used a vector as a stack. (50 points total) class stackt private int top; ll 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 IMocated. Just like for the SA class. int size; ll current size of the array allocated for the stack public: stack0; ll a stack to hold 100 elements stack(int n); ll a stack to hold n elements -stack0; bool fullo/l returns true if the stack is empty, false otherwise bool empty0; ll returns true if the stack is empty, false otherwise void push( int i); ll push new element to the top of the stack int pop0; ll return and remove the "top" element of the stack stack & operator cons stack& r); llassign one stack to another We should be able to do things like this: int mai 0f stack s(10), s push(1); s push(2); s push(3); for (i 0; i for (i 0; i 3: i++) cout

Explanation / Answer

The answers are as follows:

b. Write stack(int n);
  
   stack(int n){
       p = new int[n];
       size = n;
   }

c.Write ~stack();
   
    ~stack(){
       delete [] p;
       size = 0;
    }

d. Write bool full();

   bool full(){
      if (top == size)
         return true;
      else
         return false;
   }

e. Write bool empty();

   bool empty(){
      if (top == 0)
         return true;
      else
         return false;
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote