Accessing Struct Data in a Queue

I have a queue of structs. I would like to access one of the two pieces of data at the front of the queue that each struct maintains.

Here is some of my code:

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <queue> 
using namespace std;

struct Customer
{
	int time;
	int priority;
}cust;


1
2
queue <Customer> lane1;
queue <Customer> lane2;


What I am asking is how do I get the priority of the struct item at the front (lane1.front()), in this case?
Create a linked list, and access tail pointer as front if you add to head, or head pointer as front if you add to tail.
I don't know if your question meant something different though.
Last edited on
There is no way to do it without using a linked list?
A dynamic array should work too.
Im still confused. You mean keep a parallel list to the queue and use that?
Sorry, I did not realize you were already using the std::queue.

To access an element, use
lane1.front()->priority
Ok, that makes sense. But I got this error on that code:

expression must have pointer type
all you did, at least in the above code, is declare the queue. You must add things to it before you can access them.

Oh and if your queue is Customer then use . else Customer* then use ->

lane1[0].priority; //me thinks
Last edited on
I think that works. I could have sworn I tried that originally but I mist have spelled something wrong. Thank you. Have a great day!
Topic archived. No new replies allowed.