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