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

I got the first 2 parts of this answer now I just need help with the rest. Answe

ID: 3883024 • Letter: I

Question

I got the first 2 parts of this answer now I just need help with the rest.


Answer No 3:
a) int num,
s.pop();
num = s.pop(); // the second element will be removed and stored in num

b) int num;
int first;
first = s.pop();
num = s.pop(); // the second element will be removed and stored in num
//Now push second element again
s,push(num);
s.push(first); // push first again


duced by the output from the pops of an initally mpy stak he operations push, pop, top, and isEmpty to construct pseudocode operations that do each of the following o the second element from the top of the stack, leaving the stack without its top two elements. o the second element from the top of the stack, leaving the stack nchanged on Data Structures Page 12 cus

Explanation / Answer

c
for i = 1 to n-1
    s.pop();
end for
num = s.pop;

d
stack newStack
for i = 1 to n-1
    tmp = s.pop();
    newStack.push(tmp);
end for
num = s.peek();
while not(newStack.isEmpty())
   tmp = newStack.pop();
   s.push(tmp);
end while

e
while not(s.isEmpty())
   num = s.pop();
end while

f
stack newStack
while not(s.isEmpty())
    tmp = s.pop();
    newStack.push(tmp);
end while
num = newStack.peek();
while not(newStack.isEmpty())
   tmp = newStack.pop();
   s.push(tmp);
end while

g
stack newStack
while not(s.isEmpty())
    tmp = s.pop();
    newStack.push(tmp);
end while
for i = 1 to n-1
    tmp = newStack.pop();
    s.push(tmp);
end for
num = newStack.peek();
while not(newStack.isEmpty())
   tmp = newStack.pop();
   s.push(tmp);
end while