Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
42 changes: 42 additions & 0 deletions lab4/Kulakova/lab4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys
k = 11

def insertion_sort(arr):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это bubble sort, а не insertion, поправьте, пожалуйста

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]))
Copy link
Owner

Choose a reason for hiding this comment

The 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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output по спецификации ожидался немного другой