c++ - how do i store and get a queue of structure? -
How can I store and obtain the value of the structure in a row where I have 2 values? I want to quote some of these values.
| 4, 2.
| 3, 5.
Where a variable can be from 4,2 and 3,5 such as
primaryQ.push (a, b);
My structure:
struct primarytemp {double process; Double secondary; };
Here's how I declared my main:
int main () {queue & lt; Primarytemp & gt; PrimaryQ; Primary Q.push (4, 2); }
You just type a primarytemp
object, type Without modifications:
Qi < Primarytemp & gt; Q; Q.push (Primetime {4., 2.}); // Existing C ++ standard (C ++ 11) priorityEmpep P = {3., 5} is required; Q.push (p); // PreC + 11 11 works
As mentioned by other people, you can add a constructor for primitiv
, though This means that it is no longer this altogether, it can not be the priority or the case altogether.
primarytemp {}: process (), secondary () {} primarytemp (double process, double secondary): process (process), secondary (secondary) {} dual process; Double secondary; };
This allows you to say
q.push (primarytemp (4., 2.)); // also works with pre-C ++11
, use the back ()
method to push the element that you just pushed , Which gives the reference:
std :: cout & lt; & Lt; "Process" & lt; & Lt; Q.back () Process () & lt; & Lt; Std :: endl; You can also make a copy of that element: primarytemp = q.back ();
The front ()
method allows you to do this with the first element in the queue.
To remove element in front:
q.pop ();
Comments
Post a Comment