0% found this document useful (0 votes)
2 views1 page

Stack Queue Syntax Revision

This document provides a concise reference for using stacks and queues in C++ with the Standard Template Library (STL). It includes syntax for declaration, insertion, deletion, and accessing elements, along with a complete example demonstrating their usage. The key distinction highlighted is that stacks operate on a LIFO basis while queues operate on a FIFO basis.
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)
2 views1 page

Stack Queue Syntax Revision

This document provides a concise reference for using stacks and queues in C++ with the Standard Template Library (STL). It includes syntax for declaration, insertion, deletion, and accessing elements, along with a complete example demonstrating their usage. The key distinction highlighted is that stacks operate on a LIFO basis while queues operate on a FIFO basis.
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 & QUEUE in C++ — Syntax Revision Sheet

Quick one-page lookup guide for beginners with STL syntax, operations, and examples.

Concept Stack Syntax Queue Syntax


Header File #include <stack> #include <queue>
Declaration stack<int> st; queue<int> q;
Insert [Link](10); [Link](10);
Delete [Link](); [Link]();
Access Element [Link](); [Link]();
Last Element — [Link]();
Check Empty [Link](); [Link]();
Size [Link](); [Link]();
Traversal while(![Link]()) while(![Link]())
Removal Order LIFO FIFO

Complete Example
#include <iostream>
#include <stack>
#include <queue>
using namespace std;

int main(){
stack<int> st;
queue<int> q;

[Link](1);
[Link](2);
cout << [Link]();

[Link](5);
[Link](10);
cout << [Link]();
}

Important: Stack follows LIFO (Last In First Out) while Queue follows FIFO (First In First Out).

You might also like