wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Stack

Total questions: 6

Worksheet time: 3mins

Name
Class
Date
1.

Which method inserts an element into the stack?

a)

a) pop()

b)

b) peek()

c)

c) push()

d)

d) displayStack()

2.

Which method removes the top element of the stack?

a)

a) peek()

b)

b) pop()

c)

c) push()

d)

d) displayStack()

3.

What is the role of peek() method?

a)

a) Inserts an item

b)

b) Removes an item

c)

c) Shows the top element without removing it

d)

d) Prints all elements

4.

If we push elements 10, 20, 30 into a stack, and then pop once, which element is removed?

a)

a) 10

b)

b) 20

c)

c) 30

d)

d) None

5.
  1. In the given program, after executing:

stack.push(5);

stack.push(10);

stack.push(7);

stack.pop();

Which element is removed?

a)

a) 5

b)

b) 7

c)

c) 10

d)

d) -1

6.
  1. After the following operations:

stack.push(5);

stack.push(10);

stack.pop();

stack.push(15);

What will peek() return?

a)

a) 5

b)

b) 10

c)

c) 15

d)

d) -1