Created
May 7, 2015 22:59
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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