Delete Values in Queue
Note:
This code was written during a crunch period and isn't perfect. There will
be some errant spacing, some files will be
using namespace std,
etc. But it's all still usable and can be a
handy guideline if you're learning Data Structures.
#include <vector>
#include <queue>
#include <stdlib.h>
#include <stdlib.h>
void deleteOccurencesInQueue(std::queue<int> &q, int value)
{
int size = q.size();
int shifts = 0;
while (shifts < size)
{
if (q.front() != value)
{
q.push(q.front());
}
q.pop();
shifts++;
}
}
int main(int argc, char *argv[])
{
std::vector<int> values = {
1,
2,
4,
5,
5,
5,
5,
4,
5,
2,
1,
};
std::queue<int> kyuu;
for (int x : values)
{
kyuu.push(x);
}
deleteOccurencesInQueue(kyuu, 5);
while (kyuu.size() > 0)
{
std::cout << kyuu.front() << " ";
kyuu.pop();
}
return 0;
}