Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:59:33+00:00 2026-06-06T14:59:33+00:00

I have queue from struct type struct test { int numbers; }; queue<test> q;

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:59:34+00:00Added an answer on June 6, 2026 at 2:59 pm

    Since you need a queue of integers the easiest solution is to use std::deque<int>. Then you could use std::min_element to find the minimum element in the queue:

    std::deque<int> q{5, 1, 3};
    std::deque<int>::iterator it = std::min_element(q.begin(), q.end());
    std::cout << *it << std::endl;
    

    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 test is more complex (having more fields) then you can use exactly the same approach but defining a compare function for struct test (see @fljx answer for an example of such a compare function).

    If you can only use a queue you are restricted on the type of operations that you can do. Therefore, you would need to do something like:

    std::queue<int> q;
    /* fill queue ... */
    int min_value = INT_MAX;
    std::size_t size = q.size();
    while (size-- > 0) {
        int x = q.front();
        q.pop();
        q.push(x);
        if (x < min_value)
            min_value = x;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a server application receiving messages from a JMS queue. And client applications
I have a message handler, which consumes from a JMS queue and that sends
I have declared: queue<int, list<int> > Q After a series of calls: Q.push(37); Q.pop();
It is possible have one MSMQ queue in one machine and read masseges from
For example we have priority_queue<int> s; which contains some elements. What will be correct
Assume i have struct node{ int val; node* left; }; Now, I have a
Say I have a queue full of tasks which I need to submit to
I have a queue (from the Queue module), and I want to get indexed
I have priority queue which sorts elements by some value(lets name it rating). I
I have a blocking queue and workers taking from that queue and then working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.