Sign in to follow this  
saeedm

my compare function is broken!

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this