implemented the optimal priority queue

now has O(n^2) time complexity in the number of nodes