I'm trying to implement a std::priority_queue, but the literature is quite fuzzy, and I don't understand some of the things I need to do.
I have a class called Paths, which contains, as its base object, a std::list <unsigned int>, which describes a certain path on a graph theoretic tree, with each node identified by an unsigned int. Each Path object has a function .getLength(), which returns the weight of the path, where each edge between nodes has a different weight / length.
I then have a list of Path objects, called list <Paths> finallist, which contains numerous Path objects as well as lots of other methods.
I'd like to copy the list of Path objects into a priority queue, probably using a std::vector as base container ( as we need random access, so the list won't do ), such that the queue maintains the different Path objects ordered with respect to their .getLength() attribute ( which returns a double ), with shortest paths first.
An integer queue seems very easy, and I've even seen examples where people use
to sort their class objects, but these only have a single member in their private space, which the queue seems happy to sort by with no additional instructions. I'd like to sort by the value returned by .getLength().Code:
priority_queue <myClass> pq;
Any help or pointers in the right direction would be hugely appreciated.
Thank you very much,