Skip to content

Update bitonic_sort with type hints, doctest, snake_case names #4016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 9, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions sorts/bitonic_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def compAndSwap(a, i, j, dire):
# The sequence to be sorted starts at index position low,
# the parameter cnt is the number of elements to be sorted.
def bitonic_merge(a, low, cnt, dire):
if cnt > 1:
if cnt > 1:
k = int(cnt / 2)
for i in range(low, low + k):
compAndSwap(a, i, i + k, dire)
Expand Down Expand Up @@ -45,14 +45,12 @@ def sort(a, N, up):

if __name__ == "__main__":

a = []

n = int(input().strip())
for i in range(n):
a.append(int(input().strip()))
user_input = input("Enter numbers separated by a comma:\n").strip()
unsorted = [int(item) for item in user_input.split(",")]

up = 1

sort(a, n, up)
print("\n\nSorted array is")
for i in range(n):
print("%d" % a[i])
sort(unsorted,len(unsorted), up)
print("\nSorted array is")
print(*unsorted, sep=",")