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

  • SEARCH
  • Home
  • 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 9115287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:23:42+00:00 2026-06-17T04:23:42+00:00

Quite frequently I need to extract the N (> 1) highest elements from an

  • 0

Quite frequently I need to extract the N (> 1) highest elements from an unsorted STL container. The naive way to do this is using <queue>.

Is there a quicker, less boilerplate way?

  • 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-17T04:23:44+00:00Added an answer on June 17, 2026 at 4:23 am

    std::partial_sort if you need them in order, otherwise std::nth_element, using greater as your predicate in either case.

    I can’t tell if by extract you mean you want to remove, but if you do then another option is heapifying your container with make_heap and then yanking the N elements out of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use cast() from the reshape package quite frequently. Almost every time, this warning
Quite frequently in C++11 I need to define a function that takes a container
I see this code quite frequently in some OSS unit tests, but is it
When I develop web applications I'm frequently need to sync files from a working
I need to do several two-step or three-step commands in Git quite frequently, that
I have a function that I use quite frequently, which allows me to write
We use Infopath at work, quite frequently for form design and then we integrate
When discussing sealed classes, the term virtual function table is mentioned quite frequently. What
Quite embarrassing really, but I tested creating a database from a spreadsheet with a
This is a follow-on from: Debugging a Multithreaded C# - C++/CLI - C++ Solution

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.