• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jan 18th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def merge_sort(list):
2.     left = []
3.     right = []
4.     l = len(list)
5.     for i in range(0,l,1):
6.         if i < l/2:
7.             left.append(list[i])
8.         else:
9.             right.append(list[i])
10.     left = merge_sort(left)
11.     right = merge_sort(right)
12.     return merge(left,right)
13. def merge(left,right):
14.     result = []
15.     ll = len(left)
16.     rl = len(right)
17.     i = 0
18.     j = 0
19.     while i < ll and j < rl:
20.         if left[i] < right[i]:
21.             result.append(left[i])
22.             i += 1
23.         else:
24.             result.append(right[j])
25.             j += 1
26.     while i < ll:
27.         result.append(left[i])
28.         i += 1
29.     while j < rl:
30.         result.append(right[j])
31.         j += 1
32.     return result
33. list = [int(x) for x in input().split()]
34. print(merge_sort(list))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top