diff --git a/sorts/odd_even_transposition_parallel.py b/sorts/odd_even_transposition_parallel.py index 4d2f37702..080c86af5 100644 --- a/sorts/odd_even_transposition_parallel.py +++ b/sorts/odd_even_transposition_parallel.py @@ -10,7 +10,7 @@ comparisons. They are synchronized with locks and message passing but other forms of synchronization could be used. """ -from multiprocessing import Process, Pipe, Lock +from multiprocessing import Lock, Pipe, Process # lock used to ensure that two processes do not access a pipe at the same time processLock = Lock() @@ -73,15 +73,11 @@ arr = the list to be sorted def OddEvenTransposition(arr): - processArray = [] - resultPipe = [] - # initialize the list of pipes where the values will be retrieved for _ in arr: resultPipe.append(Pipe()) - # creates the processes # the first and last process only have one neighbor so they are made outside # of the loop @@ -131,21 +127,15 @@ def OddEvenTransposition(arr): for p in range(0, len(resultPipe)): arr[p] = resultPipe[p][0].recv() processArray[p].join() - return arr # creates a reverse sorted list and sorts it def main(): - arr = [] - - for i in range(10, 0, -1): - arr.append(i) + arr = list(range(10, 0, -1)) print("Initial List") print(*arr) - - list = OddEvenTransposition(arr) - + arr = OddEvenTransposition(arr) print("Sorted List\n") print(*arr)