Question 2: (15 marks) Suppose that we have three stacks s1, s2 and s3 of size 6, where stack s2 ...

Question 2: (15 marks)

Suppose that we have three stacks s1, s2 and s3 of size 6, where stack s2 and s3 are initially empty and stack s1 having the elements {1, 2, 3}, where 1 is at the bottom.

Draw the three stacks after executing the following piece of code.

while(!s1.isEmpty()){

    s2.push(s1.peek());

    s3.push(s2.peek());

    s2.push(s1.pop());

}

Solved
COMPUTER SCIENCE 1 Answer Nguyen Tue