priority queue implementation based on sort an array to ensure the smallest first