-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue-stack.cpp
More file actions
44 lines (39 loc) · 891 Bytes
/
queue-stack.cpp
File metadata and controls
44 lines (39 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
void queueOps() {
// Using std::queue
// Container adapter that provides FIFO (First In First Out) functionality
cout << "* Queue using std::queue" << endl;
queue<int> q;
q.push(10);
q.push(20);
q.push(30);
cout << "Queue size: " << q.size() << endl;
while (!q.empty()) {
cout << "Front element: " << q.front() << endl;
q.pop();
}
}
void stackOps() {
// Using std::stack
// Container adapter that provides LIFO (Last In First Out) functionality
cout << "* Stack using std::stack" << endl;
stack<int> s;
s.push(10);
s.push(20);
s.push(30);
cout << "Stack size: " << s.size() << endl;
while (!s.empty()) {
cout << "Top element: " << s.top() << endl;
s.pop();
}
}
int main() {
queueOps();
stackOps();
return 0;
}