We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2235f22 commit 09bfe65Copy full SHA for 09bfe65
PriorityQueueChpt/priorityQ_Sort.py
@@ -0,0 +1,15 @@
1
+from collections import heapq
2
+from LinkedLists import PositionalList
3
+import PriorityQueue
4
+def pq_sort(C):
5
+ """Sort a collection of elements stored in a Positional List"""
6
+ n= len(C)
7
+ P= PriorityQueue()
8
+
9
+ for i in range(n):
10
+ element= C.delete(C.first())
11
+ P.add(element, element) #use element as key and value
12
13
+ for j in range(n):
14
+ (k,v)= P.remove_min()
15
+ C.add_last(v) #store smallest remaining element in C
0 commit comments