Programming Quiz

Results

#1 [8, 1, 10, 6, 4, 2] Assume that these are the elements of a stack ‘S’ such that 2 is the top most element and 8 is the element at the bottom of the stack. Note that, push(), pop(), peek() are the methods used with the stack; push(int x) inserts an integer x onto the top of the stack; int pop() removes the integer at the top of the stack and returns that integer; int peek() returns the integer at the top of the stack without removing it from the stack. How does the Stack look like after executing the following code segment?

#2 What is the output of the following code segment?

#3 Given the function “fun”, what will be the output of fun (16) ?

#4 What is the output of the following code segment?