Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,45 @@
func mergeSort<T:Comparable>(inout list:[T]) {
if list.count <= 1 {
return
}
func merge(var left:[T], var right:[T]) -> [T] {
var result = [T]()
while left.count != 0 && right.count != 0 {
if left[0] <= right[0] {
result.append(left.removeAtIndex(0))
} else {
result.append(right.removeAtIndex(0))
}
}
while left.count != 0 {
result.append(left.removeAtIndex(0))
}
while right.count != 0 {
result.append(right.removeAtIndex(0))
}
return result
}
var left = [T]()
var right = [T]()
let mid = list.count / 2
for i in 0..<mid {
left.append(list[i])
}
for i in mid..<list.count {
right.append(list[i])
}
mergeSort(&left)
mergeSort(&right)
list = merge(left, right)
}