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

The Archive Base Latest Questions

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

I have a std::list graph edges and i want to sort the edges based

  • 0

I have a std::list graph edges and i want to sort the edges based on their destination outdegree and then their indegree. But i am getting getting exception of invalid operator < during my comparison function below is my code. My list contains the pointers to the edges and
edges have destination nodes as their member.

bool compareEdges(const Edge  *e1,const Edge *e2){
if(e1->destination->outdegree < e2->destination->outdegree){
    return true;
}
else if(e1->destination->outdegree > e2->destination->outdegree){
    return false;
}
else if(e1->destination->indegree > e2->destination->indegree){
        return false;
    }
return true;

}

And here is the call to the sort function.

currentNode->edgeList.sort(compareEdges);

Please help me in removing this exception.

enter image description here

Thanks

  • 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-27T13:59:14+00:00Added an answer on May 27, 2026 at 1:59 pm

    Your comparator returns true when both relevant fields are equal. This is invalid, so it may well be what the sort implementation has detected via assert.

    You’re supposed to pass a “less than” predicate to sort: formally a “strict weak order”. Anything else is undefined behavior. It seems in this case you got lucky, and the implementation detects that it has got into an impossible situation due to inconsistent comparisons.

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

Sidebar

Related Questions

I have a linked list that I want to sort part of, eg: std::sort(someIterator,
I have a std::list of boost::shared_ptr<T> and I want to remove an item from
I have several std::vector , all of the same length. I want to sort
I have std::list<multimap<std::string,std::string>::iterator> > Now i have new element: multimap<std::string,std::string>::value_type aNewMmapValue(foo1,test) I want to
I have a std::list of Bananas , and I want to get rid of
i have the following method : string Company::cheap(list<Candidate*>& candidates) { candidates.sort(candidateSalaryCompare); for (std::list<Candidate*>::iterator iter
Sorry about the vague question title, but I have these typedefs here: typedef std::list<AnimationKeyframe>
I have a class Class which has a member std::list, I want to search
I have one std::list<> container and these threads: One writer thread which adds elements
I have some std::list<char> list_type Now I have to supply contents of the list

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.