From cf63c8dee89ef8e80477394b36b40ba6fbc29ced Mon Sep 17 00:00:00 2001 From: shtrichsheffera Date: Fri, 25 Sep 2015 22:07:53 +0300 Subject: [PATCH 1/2] Create lab5.py --- lab4/Kulakova/lab5.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lab4/Kulakova/lab5.py diff --git a/lab4/Kulakova/lab5.py b/lab4/Kulakova/lab5.py new file mode 100644 index 0000000..64b3a12 --- /dev/null +++ b/lab4/Kulakova/lab5.py @@ -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])) + 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) From a70ff96625f1e4121638ba176a126fde5ef164fa Mon Sep 17 00:00:00 2001 From: shtrichsheffera Date: Fri, 25 Sep 2015 22:10:14 +0300 Subject: [PATCH 2/2] Rename lab5.py to lab4.py --- lab4/Kulakova/{lab5.py => lab4.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lab4/Kulakova/{lab5.py => lab4.py} (100%) diff --git a/lab4/Kulakova/lab5.py b/lab4/Kulakova/lab4.py similarity index 100% rename from lab4/Kulakova/lab5.py rename to lab4/Kulakova/lab4.py