Question #47543

If the character is an asterisk * it means the operations to be performed is pop. How to do it using queue?
1

Expert's answer

2014-10-08T01:10:26-0400

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>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS