2019-06-07 15:38:43 +00:00
|
|
|
"""
|
|
|
|
This is a non-parallelized implementation of odd-even transpostiion sort.
|
|
|
|
|
|
|
|
Normally the swaps in each set happen simultaneously, without that the algorithm
|
|
|
|
is no better than bubble sort.
|
|
|
|
"""
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
2019-06-07 15:38:43 +00:00
|
|
|
def OddEvenTransposition(arr):
|
|
|
|
for i in range(0, len(arr)):
|
|
|
|
for i in range(i % 2, len(arr) - 1, 2):
|
|
|
|
if arr[i + 1] < arr[i]:
|
|
|
|
arr[i], arr[i + 1] = arr[i + 1], arr[i]
|
|
|
|
print(*arr)
|
|
|
|
|
|
|
|
return arr
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
|
|
|
# creates a list and sorts it
|
2019-06-07 15:38:43 +00:00
|
|
|
def main():
|
|
|
|
list = []
|
|
|
|
|
|
|
|
for i in range(10, 0, -1):
|
|
|
|
list.append(i)
|
|
|
|
print("Initial List")
|
|
|
|
print(*list)
|
|
|
|
|
|
|
|
list = OddEvenTransposition(list)
|
|
|
|
|
|
|
|
print("Sorted List\n")
|
|
|
|
print(*list)
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
2019-06-07 15:38:43 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|