Answer on Question #47543, Programming, C++
Problem.
If the character is an asterisk * it means the operations to be performed is pop. How to do it using queue?
Solution.
Code
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int main() {
queue<int> myQueue;
int n;
char c;
while (cin >> n) {
myQueue.push(n);
}
bool isAsterisk = true;
while (isAsterisk) {
c = getchar();
if (c == '*') {
myQueue.pop();
} else {
isAsterisk = false;
}
}
while (!(myQueue.empty())) {
cout << myQueue.front() << " ";
myQueue.pop();
}
}Result
1 2 3 4 5
***
4 5
http://www.AssignmentExpert.com/</int></queue></cstdio></iostream>
Comments