Create an empty array, then insert (Priority Queue)

You definitely do not need to define your own type to do this. You can use a Vector{Any} which can hold any kind of object.

julia> A = [] # Vector{Any} by default
Any[]

julia> insert!(A, 1, ("toto",))
1-element Vector{Any}:
 ("toto",)

julia> insert!(A, 1, ("titi", 1.0))
2-element Vector{Any}:
 ("titi", 1.0)
 ("toto",)

The Vector data structure is a contiguous one-dimensional array, but you can add and remove items at the front and back, so it works in terms of API for what you want. On modern hardware, a contiguous array is hard to beat and it’s very hard to find a use case where a linked list is better, even for operations that are in principle O(n) for a vector and O(1) for a linked list: Bjarne Stroustrup: Why you should avoid Linked Lists - YouTube.

5 Likes