YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
|
|
@ -1,17 +1,19 @@
|
|||
fun mergeSort(m):
|
||||
if m.len <= 1: return m
|
||||
let middle = floor m.len / 2
|
||||
fun mergesort(m):
|
||||
if m.lenght <= 1: return m
|
||||
let middle = floor m.lenght / 2
|
||||
let left = merge(m[:middle])
|
||||
let right = merge(m[middle-1:]);
|
||||
|
||||
fun merge(left, right):
|
||||
let result = []
|
||||
while not (left.isEmpty or right.isEmpty):
|
||||
while not (left.isempty or right.isempty):
|
||||
if left[1] <= right[1]:
|
||||
result ++ left.shift()
|
||||
result.push left.shift()
|
||||
else:
|
||||
result ++ right.shift()
|
||||
result ++ left ++ right
|
||||
result.push right.shift()
|
||||
result.push left.push right
|
||||
|
||||
let arr = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0]
|
||||
print mergesort arr
|
||||
|
||||
print mergeSort arr
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue