I have queue from struct type
struct test {
int numbers;
};
queue<test> q;
how to find min value from:
q.front().numbers;
For example if in numbers have 5,1,3 I need to found 1.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since you need a queue of integers the easiest solution is to use
std::deque<int>. Then you could usestd::min_elementto find the minimum element in the queue:By doing so, you do not need to use the
struct test. This is especially true since it seems to just store an integer. If, on the other hand,struct testis more complex (having more fields) then you can use exactly the same approach but defining a compare function forstruct test(see @fljx answer for an example of such a compare function).If you can only use a
queueyou are restricted on the type of operations that you can do. Therefore, you would need to do something like: