added quick sort for duplicates and priority queue