源代码:
//
//排序.swift
//
// Created by chenzhen on 16/8/12.
// From 大连东软信息学院
// Copyright © 2016年 zhen7216. All rights reserved.
//
import Foundation
func sort(inout arr:[Int]) {
let n = arr.count
for i in 0 ..< n {
for j in i ..< n - 1 {
if arr[i] > arr[j + 1] {
let temp = arr[i]
arr[i] = arr[j + 1]
arr[j + 1] = temp
}
}
}
}
var Arr: [Int] = [1, 3, 2, 4, 5, 7, 6,74,32,56,34]
sort(&Arr)
print(Arr)
运行结果: