Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What would be the result of multiplying the final capacity to the index corresponding to the item at the top of the stack if the

What would be the result of multiplying the final capacity to the index corresponding to the item at the top of the stack if the following operations were executed?

I'm having trouble on this bit of code. Please leave notes & comments if possible!! Thank you!

Given the following

class Stack{

private:

string * A;

int count;

int capacity;

Stack::Stack()

{

A = new string[2];

count = 0;

capacity = 2;

}

void Stack::push(string s) {

if (count == capacity) {

string* new_A = new string[2 * capacity];

for (int i = 0; i < capacity; ++i)

new_A[i] = A[i];

delete[] A;

A = new_A;

capacity *= 2;

}

A[count] = s;

++count;

}

void Stack::pop() {

if (count == 0)

return;

--count;

}

What would be the result of multiplying the final capacity to the index corresponding to the item at the top of the stack if the following operations were executed?

int main()

{

Stack s;

s.push("A");

s.push("B");

s.push("C");

s.push("D");

s.pop();

return 0;

}

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