Jump to content
  • Advertisement
Sign in to follow this  
saeedm

my compare function is broken!

This topic is 3761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is my compare function for my heap commands, std::make_heap, etc. bool compareDist(Vertex * a, Vertex * b) { return (a->getDist() < b->getDist()); } and its used in here: make_heap(vertexVector.begin(), vertexVector.end(), compareDist); It should sort the Vertex pointers in my heap by their getDist() values, but instead its almost random. Heres the output of vertexVector before running make_heap: (the format is: vertexnumber=dist) 1=2147483647 2=1 3=21 4=2147483647 5=2147483647 6=2147483647 7=2147483647 And after and running make_heap: 7=2147483647 5=2147483647 6=2147483647 4=2147483647 2=1 1=2147483647 3=21 I tried sort_heap too: 2=1 4=2147483647 5=2147483647 7=2147483647 6=2147483647 3=21 1=2147483647 Thanks for any help

Share this post


Link to post
Share on other sites
Advertisement
Heaps are not organized the way you think they are. (Consult a good reference on the topic for the details :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!