-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue_tests.cpp
40 lines (28 loc) · 877 Bytes
/
queue_tests.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
#include <iostream>
#include <queue>
using namespace std;
void HotPotato(string nameArray[], int arrayLength, int num)
{
queue<string> nameQueue;
// Fill initial queue
for (int i = 0; i < arrayLength; i++)
nameQueue.push(nameArray[i]);
while (nameQueue.size() > 1)
{
for (int i = 0; i < num; i++)
{
nameQueue.push(nameQueue.front());
nameQueue.pop();
}
cout << nameQueue.front() << " is out!" << endl;
nameQueue.pop();
cout << nameQueue.size() << " remaining" << endl;
}
cout << nameQueue.front() << " is the final person remaining" << endl;
}
void run_queue_tests()
{
string names[] = {"Ash", "Cash", "Bash", "Dash", "Gash", "Nash"};
int arrayLength = sizeof (names) / sizeof (names[0]);
HotPotato(names, arrayLength, 2);
}