Stack and Queue in C++ STL
CSE/IT JUIT Waknaghat
April 24, 2026
Made by : Akshay Kumar Stack and Queue in C++ STL April 24, 2026 1/4
Stack: Visualization & STL
Container: Stack (LIFO)
top(): Access last element # include < stack >
# include < iostream >
push(): Insert at top
pop(): Remove from top std :: stack < int > s ;
empty(): Boolean check s . push (10) ;
s . push (20) ;
s . push (30) ;
Push Pop if (! s . empty () ) {
// Returns 30
int val = s . top () ;
30 Top // Removes 30
s . pop () ;
20 }
10
Made by : Akshay Kumar Stack and Queue in C++ STL April 24, 2026 2/4
Queue: Visualization & STL
Container: Queue (FIFO) # include < queue >
# include < iostream >
front(): Access first element
std :: queue < int > q ;
push(): Insert at back
q . push (10) ; // First in
pop(): Remove from front q . push (20) ;
empty(): Boolean check q . push (30) ;
if (! q . empty () ) {
// Returns 10
int f = q . front () ;
Pop 10 20 30 Push
// Removes 10
q . pop () ;
Front Back
}
Made by : Akshay Kumar Stack and Queue in C++ STL April 24, 2026 3/4
Comparison Summary
Operation Stack (STL) Queue (STL)
Insert push() push()
Remove pop() (removes top) pop() (removes front)
Access top() front()
Behavior Last-In, First-Out First-In, First-Out
Check Empty empty() empty()
Made by : Akshay Kumar Stack and Queue in C++ STL April 24, 2026 4/4