# A priority queue with a vector of priorities

**URL:** <https://discourse.julialang.org/t/a-priority-queue-with-a-vector-of-priorities/24719>\
**Category:** General Usage\
**Created:** [May 29, 2019, 8:39am UTC](https://discourse.julialang.org/t/a-priority-queue-with-a-vector-of-priorities/24719 "2019-05-29T08:39:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [May 29, 2019, 8:39am UTC](https://discourse.julialang.org/t/a-priority-queue-with-a-vector-of-priorities/24719/1 "2019-05-29T08:39:33Z")

</div>

This is fairly straightforward. I need to create a structure with keys and priorities. Then, priority queue would be a good candidate. For my understanding, each pair in the default priority queue of Julia has only one key element and one priority element. What if I’d like to have two priorities, such that in case that the first priority is the same, then order it based on the second priority? Does Julia have a structure for this?

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [May 29, 2019, 8:45am UTC](https://discourse.julialang.org/t/a-priority-queue-with-a-vector-of-priorities/24719/2 "2019-05-29T08:45:33Z")

</div>

```julia
julia> using DataStructures

julia> q = PriorityQueue{String, Tuple{Int,Int}}()
PriorityQueue{String,Tuple{Int64,Int64},Base.Order.ForwardOrdering} with 0 entries

julia> enqueue!(q, "a", (1, 1))
PriorityQueue{String,Tuple{Int64,Int64},Base.Order.ForwardOrdering} with 1 entry:
  "a" => (1, 1)

julia> enqueue!(q, "b", (1, 2))
PriorityQueue{String,Tuple{Int64,Int64},Base.Order.ForwardOrdering} with 2 entries:
  "b" => (1, 2)
  "a" => (1, 1)

julia> enqueue!(q, "c", (2, 1))
PriorityQueue{String,Tuple{Int64,Int64},Base.Order.ForwardOrdering} with 3 entries:
  "c" => (2, 1)
  "b" => (1, 2)
  "a" => (1, 1)

```
