1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| /// 交换两个对象的值
///
/// - Parameters:
/// - aValue: 对象a
/// - bValue: 对象b
func swapValues<T>(_ aValue: inout T, _ bValue: inout T) {
let temp = aValue
aValue = bValue
bValue = temp
}
/// 栈模板
struct QStack<T> {
var items = [T]()
mutating func push(_ item: T) {
items.append(item)
}
mutating func pop() -> T {
return self.items.removeLast()
}
func isEmpty() -> Bool {
return (0 == self.items.count)
}
var count: Int {
return self.items.count
}
subscript(i: Int) -> T {
return self.items[i]
}
}
|