It sounds like you want a priority queue, which would typically be implemented using a heap.