Demo entry 6647887

BubbleSort

   

Submitted by anonymous on Oct 22, 2017 at 05:57
Language: Swift. Code size: 474 Bytes.

//插入排序 从小到大
func insertSort(myArray:[Int]) -> [Int] {
    var newArray = myArray
    for i in 1..<newArray.count{    //1 2 3 4
        for j in 0...i{     //0 1 || 0 1 2
            
            if newArray[i] > newArray[j]{
                var temp = newArray[j]
                newArray[j] = newArray[i]
                newArray[i] = temp
            }
        }
        
    }
    return newArray
}
newArray = insertSort(myArray: myArray)
print(newArray)

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).