This is my Code:
std::priority_queue<SimpleCycle, std::vector<SimpleCycle>, SimpleCycle> pq; pq.push(cycle1); pq.push(cycle2); pq.push(cycle4); std::cout << pq.top().to_string() << std::endl; std::vector<SimpleCycle> pq2{ cycle1, cycle2, cycle4 }; std::make_heap(pq2.begin(), pq2.end(), SimpleCycle()); std::cout << pq2.front().to_string() << std::endl; Comparator for SimpleCycle is as follows:
const bool SimpleCycle::operator()(SimpleCycle& L, SimpleCycle& R) const { float a = L.avg_latency(); float b = R.avg_latency(); //Allow an error rate of 0.0000000001 //Ref. The Art of Computer Programming: Seminumerical algorithms(Page 128) return (b - a) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * (0.0000000001)); } The function avg_latency() return a float. But I get different output for the same same input cases. What is possibly wrong ?