Printing all items in a Queue
Hello,
I'm currently attempting to print out all the items in a Queue. Here is the code I'm using to do this:
Code:
while (event >> word2) {
if (word2 == "1") {
string elem1 = run.front();
if (ready.size() != 0 ) {
string toRun1 = ready.front();
run.pop();
run.push(toRun1);
}
}
else if (word2 == "2") {
string elem2 = run.front();
run.pop();
wait.push(elem2);
if (ready.size() != 0) {
string toRun2 = ready.front();
run.push(toRun2);
}
else {
string toRun2 = wait.front();
run.push(toRun2);
}
}
else if (word2 == "3") {
string elem3 = wait.front();
wait.pop();
ready.push(elem3);
if (ready.size() == 0 && run.size() == 1) {
string toRun3 = ready.front();
ready.pop();
run.push(toRun3);
}
}
int runSize = run.size();
int readySize = ready.size();
int waitSize = wait.size();
// Printing items begins here
cout << "Event #" << eventNum << endl;
cout << "Running: ";
while (runSize != 0) {
string running = run.front();
cout << running << " ";
run.pop();
run.push(running);
runSize--;
}
cout << endl;
cout << "Ready: ";
while (readySize != 0) {
string readyToGo = ready.front();
cout << readyToGo << " ";
ready.pop();
ready.push(readyToGo);
readySize--;
}
cout << endl;
cout << "Waiting: ";
while (waitSize != 0) {
string waiting = wait.front();
cout << waiting << " ";
wait.pop();
wait.push(waiting);
waitSize--;
}
cout << endl;
eventNum++;
}
This prints everything in the Queues, but I think it alters my results as it pushes items back on to it that I wanted to remove earlier in my code. What I want to do is remove items from the Queues depending on the situation. When I print the results, nothing is removed from the Queues, but things are added to them. Any suggestions?
EDIT: Actually, I just realized that the if (word2 == "3") part of the first part of the code is working correctly. It removes from the wait Queue and puts it on to the ready queue. However, the first two if statements are not removing from their Queues.