Skip to content

Instantly share code, notes, and snippets.

@rugbyprof
Created May 7, 2015 22:59
Show Gist options
  • Select an option

  • Save rugbyprof/9964e4e1a3748df39df7 to your computer and use it in GitHub Desktop.

Select an option

Save rugbyprof/9964e4e1a3748df39df7 to your computer and use it in GitHub Desktop.
Simple ordered list function in swift. I know, there is a "sorted" or "sort" method. Just playing and learning.
var nums = [44,55,33,43,56,54,87,67,12,34,32,89]
println(nums[4])
func OrderedList(Nums:[Int])->[Int]{
var ONums:[Int] = []
for val in Nums{
if ONums.count == 0 {
ONums.append(val)
}else{
var i = 0
while i < ONums.count && val > ONums[i] {
i++
}
ONums.insert(val, atIndex: i)
}
}
return ONums
}
println(OrderedList(nums))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment