Skip to content

Commit 09bfe65

Browse files
committed
Create priorityQ_Sort.py
1 parent 2235f22 commit 09bfe65

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)