Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <forward_list>
- using namespace std;
- bool checkQueue(queue<int> q,int x) {
- int position = 0;
- bool check = true;
- int i = 0;
- unsigned int size = q.size();
- while (!q.empty()) {
- if (q.front() == x) {
- if (check == true) {
- position = i;
- check = false;
- }
- else if (i == size - 1 - position) {
- return true;
- }
- }
- i++;
- q.pop();
- }
- return false;
- }
- void eraseQueue(forward_list<queue<int>>& list, int x) {
- auto it = list.before_begin();
- auto next = list.begin();
- while (next != list.end()) {
- if (checkQueue(*next, x)){
- next = list.erase_after(it);
- }
- else {
- it++;
- next++;
- }
- }
- }
- int main() {
- queue<int> q;
- int a = 2;
- q.push(4);
- q.push(2);
- q.push(3);
- q.push(2);
- q.push(9);
- queue<int> q2;
- q2.push(7);
- q2.push(8);
- q2.push(9);
- queue<int> q3;
- q3.push(1);
- q3.push(2);
- q3.push(3);
- q3.push(1);
- forward_list<queue<int>> list;
- list.push_front(q);
- list.push_front(q2);
- list.push_front(q3);
- eraseQueue(list, a);
- auto it = list.begin();
- while (it != list.end()) {
- while (!it->empty()) {
- cout << it->front() << " ";
- it->pop();
- }
- cout << endl;
- it++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement