Вопрос

Does the Priority Queue data structure follow the set theory in terms of the uniqueness of its elements in its content?

I mean you cannot put a duplicate of an entity in the priority queue. -whereas you can put many duplicates of same value in a queue:

    Queue<int> q = new Queue<int>();
    q.Enqueue(5);
    q.Enqueue(5);
    q.Enqueue(3);

Can yo confirm if this is correct or incorrect, please? Thanks

Это было полезно?

Решение

Depends on the implementation, but most priority queues that I've seen allow duplicate keys/priorities. Note that if a priority queue enforces unique keys, that probably means that priorities, not values, will be unique.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top