-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample_code_V5
More file actions
31 lines (26 loc) · 1.04 KB
/
Copy pathExample_code_V5
File metadata and controls
31 lines (26 loc) · 1.04 KB
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
#include <iostream>
#include <vector>
using namespace std;
#include <stack>
#include <queue>
// what tf do stacks do? they are like a vector but they only allow you to add and remove from the top of the stack
// we use it for first in last out (FILO) operations. The last item added to the stack is the first one to be removed.
// ex: undo button
// what tf do queues do? they are like a vector but they only allow you to add to the back and remove from the front of the queue
// basicaly a stack but reverse using fist in first out (FIFO) operations. The first item added to the queue is the first one to be removed.
int main()
{
stack<int> s;
s.push(1);
s.push(2);
s.push(3);
cout << "top of stack: " << s.top() << endl;
s.pop(); // removes the top item from the stack
cout << "top of stack after pop: " << s.top() << endl;
queue<int> q;
q.push(1);
cout << "front of queue: " << q.front() << endl;
q.pop();
cout << "front of queue after pop: " << q.front() << endl;
return 0;
}