-
Notifications
You must be signed in to change notification settings - Fork 20
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
Кулакова 4 #53
base: master
Are you sure you want to change the base?
Кулакова 4 #53
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import sys | ||
k = 11 | ||
|
||
def insertion_sort(arr): | ||
for i in range(0, len(arr)): | ||
j = i - 1 | ||
while (j >= 0) and (arr[j] > arr[j+1]): | ||
arr[j], arr[j + 1] = arr[j + 1], arr[j] | ||
j -= 1 | ||
return arr | ||
|
||
def merge (larr, rarr): | ||
left = 0 | ||
right = 0 | ||
full = [0 for i in range (len(larr) + len(rarr))] | ||
while (len(larr) > left) and (len(rarr) > right): | ||
if larr[left] < rarr[right]: | ||
full[right + left] = larr[left] | ||
left += 1 | ||
else: | ||
full[right + left] = rarr[right] | ||
right += 1 | ||
while left < len(larr): | ||
full[left + right] = larr[left] | ||
left += 1 | ||
while right < len(rarr): | ||
full[left + right] = rarr[right] | ||
right += 1 | ||
return full | ||
|
||
def full_sort (arr): | ||
if len(arr) >= k: | ||
arr = merge(full_sort(arr[0:int(len(arr)/2)]), full_sort(arr[int(len(arr)/2):len(arr)+1])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sublist в python создаёт копию list, а не view, это замедляет ваш код. Тонкость языка, править сейчас не надо, просто учтите на будущее |
||
else: | ||
arr = insertion_sort(arr) | ||
return arr | ||
|
||
arr = sys.stdin.readline().split(' ') | ||
for i in range(0,len(arr)): | ||
arr[i] = int(arr[i]) | ||
arr = full_sort(arr) | ||
print (arr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. output по спецификации ожидался немного другой |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это bubble sort, а не insertion, поправьте, пожалуйста