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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:37:20+00:00 2026-06-06T23:37:20+00:00

I am working on a C++ application. I have 2 vectors of points vector<Point2f>

  • 0

I am working on a C++ application.

I have 2 vectors of points

vector<Point2f> vectorAll;
vector<Point2f> vectorSpecial;  

Point2f is defined typedef Point_<float> Point2f;

vectorAll has 1000 point while vectorSpecial has 10 points.

First Step:

I need to order the points in vectorSpecial depending on their order in vectorAll.
So something like this:

For each Point in vectorSpecial
    Get The Order Of that point in the vectorAll
    Insert it in the correct order in a new vector

I can do a double loop and save the indexes. and then order the points based on their indexes. However this method is taking too long when we have lots of points (for example 10000 points in vectorAll and 1000 points in vectorSpecial so that’s ten million iteration)

What are better methods of doing that?

Second Step:

Some points in vectorSpecial might not be available in vectorAll. I need to take the point that is closest to it (by using the usual distance formula sqrt((x1-x2)^2 + (y1-y2)^2))

This also can be done when looping, but if someone has any suggestions for better methods, I would appreciate it.

Thanks a lot for any help

  • 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-06T23:37:22+00:00Added an answer on June 6, 2026 at 11:37 pm

    You can use std::sort on vectorAll with the Compare function designed to take into account the contents of vectorSpecial:

    struct myCompareStruct
    {
        std::vector<Point2f> all;
        std::vector<Point2f> special;
        myCompareStruct(const std::vector<Point2f>& a, const std::vector<Point2f>& s)
            : all(a), special(s) 
        {
        }
        bool operator() (const Point2f& i, const Point2f& j) 
        { 
            //whatever the logic is
        }
    };
    
    std::vector<Point2f> all;
    std::vector<Point2f> special;
    //fill your vectors
    myCompareStruct compareObject(all,special);
    
    std::sort(special.begin(),special.end(),compareObject);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on Web application so far and has just got an
I am working on application for Ipad.in this application i have a UIButton on
I have an working application. Now I want to change the table names of
I have a working application using python and zeromq and I would like to
I am working on an application an have an issue about running shell command
I am new to wpf and i am working on first application i have
I am working on splitting out an existing, working application that I currently have
I have an application I have been working on and it can be slow
I am working on an application where I have to keep data sequenced, every
I'm working on dashboard application where I have to retrieve a set of records

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.