开发者

Question about Priority Queue's in Java

开发者 https://www.devze.com 2023-03-11 09:18 出处:网络
Is it possible to have a Priority Queue with the same key? so have entries like <100, buy> <100, sell>. then when I have entries with the same key when a buy and sell of that key exists, remove

Is it possible to have a Priority Queue with the same key?

so have entries like <100, buy> <100, sell>. then when I have entries with the same key when a buy and sell of that key exists, remove those entries. I am thinking it would work with like an if Statement

If <100, buy> && <100, sell>{ then remove those two entries from queue; }

Someth开发者_如何学运维ing like that.


Q. Is it possible to have a Priority Queue with the same key?

A. Yes it can, However please refer to comments under question there are efficient solutions suggested for your task.

Check slide number 3 for more detail,

http://ww3.algorithmdesign.net/handouts/Heap.pdf

Happy coding!

0

精彩评论

暂无评论...
验证码 换一张
取 消