c++ - Callback function not being called for pqueue class -



c++ - Callback function not being called for pqueue class -

i have templatized pqueue, has function, dequeue:

template <typename valtype> valtype pqueue<valtype>::dequeuemax(int(cmp(valtype one, valtype two))) { if (isempty()) error("tried dequeue max empty pqueue!"); int maxindex = 0; // assume first element largest until proven otherwise valtype maxvalue = entries[0]; (int = 1; < entries.size(); i++) { cout << "the larger 1 is: " << entries[i] << endl; if (entries[i] > maxvalue) { maxvalue = entries[i]; maxindex = i; } } entries.removeat(maxindex); // remove entry vector homecoming maxvalue; }

the constructor pqueue this: pqueue(int (cmpfn)(valtype, valtype) = operatorcmp);

everything else looks working normally.

i trying enqueue struct called arct, works fine:

set<arct *>::iterator iter = location_node->outgoing.iterator(); while (iter.hasnext()) { arct *arc = iter.next(); priority_queue.enqueue(arc); }

and trying dequeue maximum shortest distance, defined arc->distance, callback function in .cpp file:

int arccmp(arct *a1, arct *a2) { cout << "compare" << endl; if (a1->distance == a2->distance) homecoming 0; if (a1->distance < a2->distance) homecoming 1; if (a1->distance > a2->distance) homecoming -1; };

the phone call looks this: arct *arc = priority_queue.dequeuemax(arccmp);

however, ignores callback function (i've tried debug using cout) , prints lastly 1 inserted. going on here? how can work?

c++

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -