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 899713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:15:55+00:00 2026-05-15T15:15:55+00:00

I need to sort some arrays of floats, modify the values, and then construct

  • 0

I need to sort some arrays of floats, modify the values, and then construct an array with the original ordering, but the modified values.

In R, I could use the rank() and order() functions to achieve this:
v a vector
v[order(v)] is sorted
v[i] goes in the rank(v)th spot in the sorted vector

Is there some equivalent of these functions in the standard c or c++ libraries? A permutation matrix or other way of encoding the same information would be fine too.
O(n) space and O(nlogn) time would be ideal.

  • 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-05-15T15:15:56+00:00Added an answer on May 15, 2026 at 3:15 pm

    There is the equivalent to the rank function in C++: it’s called nth_element and can be applied on any model of Random Access Container (among which vector and deque are prominent).

    Now, the issue seems, to me, that the operate on values might actually modify the values and thus the ranks would change. Therefore I would advise storing the ranks.

    1. std::vector<float> to std::vector< std::pair<float, rank_t> >
    2. Sort the vector (works without any predicate)
    3. Operate on the values
    4. std::vector< std::pair<float, rank_t> > to std::vector<float>

    Unless of course you want nth_element to be affected by the current modifications of the values that occurred.

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

Sidebar

Related Questions

I have some sort of recursive function, but I need to parse a string,
I've written the following IComparer but I need some help. I'm trying to sort
I need to sort some nested arrays alphabetically by their key... Is there a
I need some sort of interactive chart control for my .NET-based web app. I
I need some sort of node-graph editor, that hopefully works on both Mac and
To preface I am using Borland C++ and the VCL. I need some sort
We are starting a rather complex new project at work, and need some sort
I need to develop some sort of application featuring Editing Movie slices, Adding and
Is there some sort of built-in authentication in WCF? I need to expose a
I need to sort tuples according to the second element of each tuple but

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.