C中的伙计将节点推入优先级队列中,我们不得不重载<运算符。有没有类似于python优先队列中的东西?在Python中重载优先级队列的比较器
用Ce.g:
struct node
{
int city , weight
}
bool operator < (node a, node b)
{
return a.weight > b.weight;
}
int main()
{
node a,b,c;
priority_queue <node> pq;
pq.push(a);pq.push(b);pq.push(c);
return 0;
}
是否有在Python定义优先队列中的任何类似的方法;如果需要帮助,我无法将python.org文档的头部或尾部作为优先级队列。我在stackoverflow上看到了一些解释,需要更多解释。谢谢。
你甚至试图谷歌这个? – Marcin 2012-04-06 15:15:55
这不是C,我想我问了一个有效的问题;没有必要投降我。 – 2012-04-07 01:42:00