Skip to content

Commit 02b717e

Browse files
samarthsehgal97cclauss
authored andcommitted
Update odd_even_transposition_parallel.py (TheAlgorithms#1458)
* Update odd_even_transposition_parallel.py * arr = OddEvenTransposition(arr)
1 parent 74d96ab commit 02b717e

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

sorts/odd_even_transposition_parallel.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
They are synchronized with locks and message passing but other forms of
1111
synchronization could be used.
1212
"""
13-
from multiprocessing import Process, Pipe, Lock
13+
from multiprocessing import Lock, Pipe, Process
1414

1515
# lock used to ensure that two processes do not access a pipe at the same time
1616
processLock = Lock()
@@ -73,15 +73,11 @@ def oeProcess(position, value, LSend, RSend, LRcv, RRcv, resultPipe):
7373

7474

7575
def OddEvenTransposition(arr):
76-
7776
processArray = []
78-
7977
resultPipe = []
80-
8178
# initialize the list of pipes where the values will be retrieved
8279
for _ in arr:
8380
resultPipe.append(Pipe())
84-
8581
# creates the processes
8682
# the first and last process only have one neighbor so they are made outside
8783
# of the loop
@@ -131,21 +127,15 @@ def OddEvenTransposition(arr):
131127
for p in range(0, len(resultPipe)):
132128
arr[p] = resultPipe[p][0].recv()
133129
processArray[p].join()
134-
135130
return arr
136131

137132

138133
# creates a reverse sorted list and sorts it
139134
def main():
140-
arr = []
141-
142-
for i in range(10, 0, -1):
143-
arr.append(i)
135+
arr = list(range(10, 0, -1))
144136
print("Initial List")
145137
print(*arr)
146-
147-
list = OddEvenTransposition(arr)
148-
138+
arr = OddEvenTransposition(arr)
149139
print("Sorted List\n")
150140
print(*arr)
151141

0 commit comments

Comments
 (0)