-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path040.cpp
59 lines (51 loc) · 1.16 KB
/
040.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// STL : Queues
#include <iostream>
#include <queue>
int main()
{
// program to demonstrate queue of the standard template library of c++
std::queue<char> q;
// inserting elements into the queue
for (int i = 0; i < 10; i++)
{
q.push('A' + i);
}
// printing the elements of the queue
std::cout << "Queue : ";
// using the empty function
while (!q.empty())
{
std::cout << q.front() << " ";
q.pop();
}
std::cout << std::endl;
// size of the queue
std::cout << "Size of the queue : " << q.size() << std::endl;
// understanding the Swap func. of queue stl
// first populating both queues
for (int i = 0; i < 10; i++)
{
q.push('A' + i);
}
std::queue<char> q2;
for (int i = 0; i < 10; i++)
{
q2.push('a' + i);
}
q.swap(q2);
std::cout << "Queue 1 : ";
while (!q.empty())
{
std::cout << q.front() << " ";
q.pop();
}
std::cout << std::endl;
std::cout << "Queue 2 : ";
while (!q2.empty())
{
std::cout << q2.front() << " ";
q2.pop();
}
std::cout << std::endl;
return 0;
}