0% found this document useful (0 votes)
4 views4 pages

Stack InClass

The document outlines a series of stack operations with varying sizes and initial conditions, including push, pop, peek, and size functions. It describes scenarios that lead to stack overflow and underflow. The operations are performed in a specified order to demonstrate stack behavior and state changes.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Stack InClass

The document outlines a series of stack operations with varying sizes and initial conditions, including push, pop, peek, and size functions. It describes scenarios that lead to stack overflow and underflow. The operations are performed in a specified order to demonstrate stack behavior and state changes.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Stack InClass

23 February 2026 10:18

1)
Given
• Stack size = 5
• Initially empty
• Perform operations in order:

push(10)
push(20)
push(30)
pop()
push(40)

2)
Given
• Stack size = 5
• Initially empty
• Perform operations
in order:

push(10)
push(20)
push(30)
push(40)
push(50)
pop()
pop()

3)
Given
• Stack size = 6
• Initially: top = -1
• Perform the following operations:

push(5)
push(15)
push(25)
pop()
push(35)
push(45)

Stack_InClass Page 1
pop()
push(35)
push(45)

What is the value of top ?

4) Given
• Stack size = 4
• Initially empty
• Operations:

push(10)
push(20)
push(30)
push(40)
push(50)

Overflow : if (top == n - 1)

5.
Given
• Stack size = 3
• Initially empty
• Operations:

push(5)
push(15)
pop()
pop()
pop()

Underflow : if (top == -1)

6. Pop vs peek

Push 10
Push 20
Push 30
Push 40
Push 50
Pop()

Stack_InClass Page 2
Push 50
Pop()

Push 10
Push 20
Push 30
Push 40
Push 50
Peek()

7)
GivenStack size = 5
• Initially:

top = -1
• Perform the operations in order:

push(10)
push(20)
peek()
push(30)
pop()
push(40)
push(50)
push(60)
peek()
pop()

8)
Given
• Stack size = 6
• Initially:

top = -1
• Operations:

push(10)
push(20)
push(30)
pop()
push(40)
size()

Stack_InClass Page 3
9)
Given
• Stack size = 4
• Initially empty
• Operations:

isEmpty()
push(5)
push(15)
pop()
pop()
isEmpty()

Stack_InClass Page 4

You might also like