-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathqueueDemo.cpp
More file actions
39 lines (36 loc) · 1.02 KB
/
queueDemo.cpp
File metadata and controls
39 lines (36 loc) · 1.02 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
32
33
34
35
36
37
38
39
#include <iostream>
#include <queue>
#include <cstdlib>
#include <ctime>
// Function to generate random numbers in a range
namespace algo {
int random_range(int min, int max) {
static bool first = true;
if (first) {
srand(static_cast<unsigned int>(time(nullptr))); // Seed the random number generator
first = false;
}
return min + rand() % ((max + 1) - min);
}
}
int main()
{
const int QUEUE_SIZE = 10;
std::queue<int> Q;
std::cout << "Pushing following values to queue:\n";
for ( int i = 0; i < QUEUE_SIZE; ++i )
{
int rand_value = algo::random_range( 5, 50 );
std::cout << rand_value << " ";
Q.push(rand_value);
}
std::cout << std::endl;
// std::cout << "Size of Queue is :" << Q.count() << std::endl; // Incorrect line, removed
std::cout << "Size of Queue is :" << Q.size() << std::endl;
while ( !Q.empty() ) {
std::cout << Q.front() << " ";
Q.pop();
}
std::cout << std::endl;
return 0;
}