Page 1 of 1

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

Posted: Mon May 02, 2022 12:45 pm
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)