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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:27:44+00:00 2026-05-14T06:27:44+00:00

I have a list of Point objects, (each one with x,y properties) and would

  • 0

I have a list of Point objects, (each one with x,y properties) and would like to find the left-most and right-most points. I’ve been trying to do it with find_if, but i’m not sure its the way to go, because i can’t seem to pass a comparator instance. Is find_if the way to go? Seems not. So, is there an algorithm in <algorithm> to achieve this?

Thanks in advance.

#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

typedef struct Point{
        float x;
        float y;
} Point;

bool left(Point& p1,Point& p2)
{
        return p1.x < p2.x;

}
int main(){
        Point p1 ={-1,0};
        Point p2 ={1,0};
        Point p3 ={5,0};
        Point p4 ={7,0};

        list <Point> points;

        points.push_back(p1);
        points.push_back(p2);
        points.push_back(p3);
        points.push_back(p4);

        //Should return an interator to p1.
        find_if(points.begin(),points.end(),left);                                                  

        return 0;
}
  • 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-14T06:27:45+00:00Added an answer on May 14, 2026 at 6:27 am

    Use std::min_element and std::max_element instead.

    list<Point>::iterator left = std::min_element(points.begin(), points.end(), left);
    list<Point>::iterator right = std::max_element(points.begin(), points.end(), left);
    

    I would also change the signature of left to:

    bool left(const Point& p1, const Point& p2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have (in C#) a list of objects (each one containing a list) and
I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
I would like to create a list objects called Product (Listproducts) where Product includes
I'm getting returned a list with objects that have multiple attributes like so: results
Referencing the code below, I have a list of Error objects that has been
I want to annotate a list of objects (which each have a set of
I have a list of points as shown below points=[ [x0,y0,v0], [x1,y1,v1], [x2,y2,v2].......... [xn,yn,vn]]
I have a list of points moving in two dimensions ( x - and
I have a SharePoint external list that points to a 100,000 record SQL table.
I have a ViewModel class that contains a list of points, and I am

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.