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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:13:30+00:00 2026-05-27T20:13:30+00:00

I want to get highest co-ordinate ( x, y ) Following is the code

  • 0

I want to get highest co-ordinate ( x, y )
Following is the code i wrote, is this correct code.

#include <vector>
#include <algorithm>
#include <iostream>
#include <iterator>

struct item_t {
    int x;
    int y;
    item_t( int h, int w ) : x(h), y(w) {}
    friend std::ostream& operator<<(std::ostream& os, const item_t& gt) {
        os << "(" << gt.x << "," << gt.y << ")";
        return os;
    }
};
typedef std::vector<item_t> item_list_t;
typedef item_list_t::iterator item_list_itr_t;

struct compare_x_y {
    bool operator ()(const item_t& left, const item_t& right) const {
        return left.x < right.x && left.y < right.y;
    }
};


int main ( int argc, char **argv) { 
    item_list_t items;

    items.push_back(item_t(15, 176));
    items.push_back(item_t(65, 97));
    items.push_back(item_t(72, 43));
    items.push_back(item_t(102, 6));
    items.push_back(item_t(191, 189));
    items.push_back(item_t(90, 163));
    items.push_back(item_t(44, 168));
    items.push_back(item_t(39, 47));
    items.push_back(item_t(123, 37));

    std::make_heap (items.begin(),items.end(),compare_x_y());
    std::cout << "initial max heap   : " << "(" << items.front().x <<"," << items.front().y << ")" << std::endl;


}

Is it working for this input but not for other inputs.

  • 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-27T20:13:30+00:00Added an answer on May 27, 2026 at 8:13 pm

    Your comparison function is not a strict weak ordering, and thus using it will give undefined results.

    It isn’t a strict weak ordering because the equivalence relation is not transitive. For example, (2,2) is equivalent to (4,1), and (4,1) is equivalent to (3,3). But (2,2) is not equivalent to (3,3). (Two values are considered equivalent if neither is less than the other).

    You will need to provide another comparison function. Some examples:

    • Compare x, and then y if the x values were equal.
    • Compare the values of x+y for the two points.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the highest value of my array. This are the two
I want to get the highest attribute ID from my XML file. My code:
I have an array of ints. I want to get the second highest number
Basically, I want this: The highest voted answer 3 vote The others answer 1
I want to get the highest value but group by another field on the
I want to get the the highest scorer from the game center. How can
From a given double I want to get the next highest number according to
I want to get the value of the highest volume level of a WAV-file
I want get the time used for a case so I can create an
I want get all of the Geom objects that are related to a certain

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.