A The binary search tree is always ordered and will always remain in order if new elements are inserted.
The main advantage of binary search trees over other data structures is that related sorting algorithms and search algorithms such as traversal in order can be very efficient.
And it is your turn of priorities. In a possible implementation, the elements with the lowest priority will receive the highest number, and the highest priorities will receive the lowest number. If these elements are inserted into the BST and you read it inorder , then you have the order in which the queue should be processed.
To process the queue, you “pop” the first item in the tree, and the rest will be automatically ordered by BST.
The only thing you need to take care of is the correct insertion of new elements into the tree and what happens if the first one is deleted.
Your methods will be mapped to the tree, add inserts a new element in the right place and if necessary modifies the tree, for example, size returns the size of the tree, inorder will cross the tree.
Hope this made it clearer.
slhck source share