What's faster: inserting into a priority queue, or sorting retrospectively?

前端 未结 10 1465
闹比i
闹比i 2020-12-12 16:58

What\'s faster: inserting into a priority queue, or sorting retrospectively?

I am generating some items that I need to be sorted at the end. I was wondering, what is

10条回答
  •  情话喂你
    2020-12-12 17:11

    Why not use a binary search tree? Then the elements are sorted at all times and the insertion costs are equal to the priority queue. Read about RedBlack balanced trees here

提交回复
热议问题