Using priority_queue

Nov 17, 2015 at 6:31pm
Hello, i have some objects that I would want to keep in a priority, my question is how to make them in order by a specific value from the object

how do I make Brick, to be in order by cost in the queue?
1
2
3
4
5
6
7
8
9
10
  class Brick
{
private:
	pair<unsigned int,unsigned int> coordinates;
	char sym;
	unsigned int cost;
	bool isChecked;
public:
//////


Thanks for the help!
Nov 17, 2015 at 6:40pm
You can sort your data and then put it in the queue.
Nov 17, 2015 at 6:46pm
C++ come with a priority_queue. Have a look at
http://www.cplusplus.com/reference/queue/priority_queue/
Nov 17, 2015 at 6:47pm
I see, but it's something that I can't do. I need to implement Uniform-Cost-Search, so I don't have all the data at once, and it depends on the nodes. The pseudo code says to use priority_queue, so that's what I am trying to do.
Nov 17, 2015 at 6:49pm
@Thomas1965 I read it, but I didn't understand how to force to make the comparison by a specific value.
Nov 17, 2015 at 6:50pm
The priority_queue by default uses < to compare the elements; if you overload < for your class to compare costs, then that is how they will be sorted.
Nov 17, 2015 at 6:51pm
thanks Zhuge
Topic archived. No new replies allowed.