Consider a stack implemented using a dynamic array (as done in class). The code is attached. See that the Stack class ha

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Consider a stack implemented using a dynamic array (as done in class). The code is attached. See that the Stack class ha

Post by answerhappygod »

Consider a stack implemented using a dynamic array (as done in
class). The code is attached. See that the Stack class has a
private member called arr, which is an object of type Array. In
other words, Stack.arr in turn has two private members, called els
and capacity. The Stack class has another private member called
top.
Show the values of the three data members (top; the array arr.els;
arr.capacity) after each operation, as per the attached code. The
first two are shown for you. Each operation is done on the result
of the previous operation. [6 pts]
Operation 1: Stack<int> s1;
arr.els:
arr.capacity: 2
top: -1
Operation 2: s1.push(5);
arr.els:
5
arr.capacity: 2 top:
0
Operation 3: (this is done after Operation 2, so start from the
result of Operation 2).
s1.push(7);
Operation 4: int x; s1.pop(x); (done after Operation 3)
Operation 5: s1.push(6); (done after Operation 4)
Operation 6: s1.push(10); (done after Operation 5)
Operation 7: int x; s1.pop(x); (done after Operation 6)
Operation 8: s1.makeEmpty(); (done after Operation 7)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply