Reduce elements repeated of queue
1
Reduce elements repeated of queue ...
#include <iostream>
#include <queue>
using namespace std;
void reducirCola(queue <int> &c);
int main(){
queue <int> c;
c.push(1);
c.push(1);
c.push(1);
c.push(2);
c.push(2);
c.push(2);
c.push(3);
c.push(3);
c.push(3);
reducirCola(c);
while (!c.empty()){
cout << c.front() << endl; c.pop();
}
return 0;
}
void reducirCola(queue <int> &c){
queue <int> q;
int x, y, z;
if (!c.empty()){
x = c.front(); c.pop();
q.push(x);
while (!c.empty()){
y = c.front(); c.pop();
if (x != y){
q.push(y);
x = y;
}
}
}
while (!q.empty()){
z = q.front(); q.pop();
c.push(z);
}
}






There are currently no comments for this snippet.