Skip to content

Commit a3d0d8f

Browse files
authored
Merge pull request #1 from raywenderlich/master
update fork
2 parents 5b8c263 + dca1e2c commit a3d0d8f

File tree

36 files changed

+1089
-1070
lines changed

36 files changed

+1089
-1070
lines changed

Binary Tree/BinaryTree.playground/Contents.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,26 @@ tree.count // 12
5353

5454

5555
extension BinaryTree {
56-
public func traverseInOrder(@noescape process: T -> Void) {
56+
public func traverseInOrder(process: (T) -> Void) {
5757
if case let .Node(left, value, right) = self {
58-
left.traverseInOrder(process)
58+
left.traverseInOrder(process: process)
5959
process(value)
60-
right.traverseInOrder(process)
60+
right.traverseInOrder(process: process)
6161
}
6262
}
6363

64-
public func traversePreOrder(@noescape process: T -> Void) {
64+
public func traversePreOrder(process: (T) -> Void) {
6565
if case let .Node(left, value, right) = self {
6666
process(value)
67-
left.traversePreOrder(process)
68-
right.traversePreOrder(process)
67+
left.traversePreOrder(process: process)
68+
right.traversePreOrder(process: process)
6969
}
7070
}
7171

72-
public func traversePostOrder(@noescape process: T -> Void) {
72+
public func traversePostOrder(process: (T) -> Void) {
7373
if case let .Node(left, value, right) = self {
74-
left.traversePostOrder(process)
75-
right.traversePostOrder(process)
74+
left.traversePostOrder(process: process)
75+
right.traversePostOrder(process: process)
7676
process(value)
7777
}
7878
}

Binary Tree/README.markdown

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,26 @@ Something you often need to do with trees is traverse them, i.e. look at all the
111111
Here is how you'd implement that:
112112

113113
```swift
114-
public func traverseInOrder(@noescape process: T -> Void) {
114+
public func traverseInOrder(process: (T) -> Void) {
115115
if case let .Node(left, value, right) = self {
116-
left.traverseInOrder(process)
116+
left.traverseInOrder(process: process)
117117
process(value)
118-
right.traverseInOrder(process)
118+
right.traverseInOrder(process: process)
119119
}
120120
}
121121

122-
public func traversePreOrder(@noescape process: T -> Void) {
122+
public func traversePreOrder(process: (T) -> Void) {
123123
if case let .Node(left, value, right) = self {
124124
process(value)
125-
left.traversePreOrder(process)
126-
right.traversePreOrder(process)
125+
left.traversePreOrder(process: process)
126+
right.traversePreOrder(process: process)
127127
}
128128
}
129129

130-
public func traversePostOrder(@noescape process: T -> Void) {
130+
public func traversePostOrder(process: (T) -> Void) {
131131
if case let .Node(left, value, right) = self {
132-
left.traversePostOrder(process)
133-
right.traversePostOrder(process)
132+
left.traversePostOrder(process: process)
133+
right.traversePostOrder(process: process)
134134
process(value)
135135
}
136136
}

Bounded Priority Queue/BoundedPriorityQueue.playground/Sources/BoundedPriorityQueue.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class BoundedPriorityQueue<T: Comparable> {
1212
private typealias Node = LinkedListNode<T>
1313

1414
private(set) public var count = 0
15-
private var head: Node?
15+
fileprivate var head: Node?
1616
private var tail: Node?
1717
private var maxElements: Int
1818

@@ -28,7 +28,7 @@ public class BoundedPriorityQueue<T: Comparable> {
2828
return head?.value
2929
}
3030

31-
public func enqueue(value: T) {
31+
public func enqueue(_ value: T) {
3232
if let node = insert(value, after: findInsertionPoint(value)) {
3333
// If the newly inserted node is the last one in the list, then update
3434
// the tail pointer.
@@ -44,7 +44,7 @@ public class BoundedPriorityQueue<T: Comparable> {
4444
}
4545
}
4646

47-
private func insert(value: T, after: Node?) -> Node? {
47+
private func insert(_ value: T, after: Node?) -> Node? {
4848
if let previous = after {
4949

5050
// If the queue is full and we have to insert at the end of the list,
@@ -78,11 +78,11 @@ public class BoundedPriorityQueue<T: Comparable> {
7878

7979
/* Find the node after which to insert the new value. If this returns nil,
8080
the new value should be inserted at the head of the list. */
81-
private func findInsertionPoint(value: T) -> Node? {
81+
private func findInsertionPoint(_ value: T) -> Node? {
8282
var node = head
8383
var prev: Node? = nil
8484

85-
while let current = node where value < current.value {
85+
while let current = node, value < current.value {
8686
prev = node
8787
node = current.next
8888
}

Bounded Priority Queue/README.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class BoundedPriorityQueue<T: Comparable> {
3535
private typealias Node = LinkedListNode<T>
3636

3737
private(set) public var count = 0
38-
private var head: Node?
38+
fileprivate var head: Node?
3939
private var tail: Node?
4040
private var maxElements: Int
4141

@@ -55,7 +55,7 @@ public class BoundedPriorityQueue<T: Comparable> {
5555
The `BoundedPriorityQueue` class contains a doubly linked list of `LinkedListNode` objects. Nothing special here yet. The fun stuff happens in the `enqueue()` method:
5656

5757
```swift
58-
public func enqueue(value: T) {
58+
public func enqueue(_ value: T) {
5959
if let node = insert(value, after: findInsertionPoint(value)) {
6060
// If the newly inserted node is the last one in the list, then update
6161
// the tail pointer.
@@ -71,7 +71,7 @@ public func enqueue(value: T) {
7171
}
7272
}
7373

74-
private func insert(value: T, after: Node?) -> Node? {
74+
private func insert(_ value: T, after: Node?) -> Node? {
7575
if let previous = after {
7676

7777
// If the queue is full and we have to insert at the end of the list,
@@ -105,7 +105,7 @@ private func insert(value: T, after: Node?) -> Node? {
105105

106106
/* Find the node after which to insert the new value. If this returns nil,
107107
the new value should be inserted at the head of the list. */
108-
private func findInsertionPoint(value: T) -> Node? {
108+
private func findInsertionPoint(_ value: T) -> Node? {
109109
var node = head
110110
var prev: Node? = nil
111111

Fizz Buzz/FizzBuzz.playground/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
func fizzBuzz(numberOfTurns: Int) {
1+
func fizzBuzz(_ numberOfTurns: Int) {
22
for i in 1...numberOfTurns {
33
var result = ""
44

Fizz Buzz/FizzBuzz.playground/playground.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Fizz Buzz/FizzBuzz.playground/timeline.xctimeline

Lines changed: 0 additions & 6 deletions
This file was deleted.

Fizz Buzz/FizzBuzz.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
func fizzBuzz(numberOfTurns: Int) {
1+
func fizzBuzz(_ numberOfTurns: Int) {
22
for i in 1...numberOfTurns {
33
var result = ""
44

Fizz Buzz/README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Finding numbers divisible by five:
5858
Here is a simple implementation in Swift:
5959

6060
```swift
61-
func fizzBuzz(numberOfTurns: Int) {
61+
func fizzBuzz(_ numberOfTurns: Int) {
6262
for i in 1...numberOfTurns {
6363
var result = ""
6464

GCD/GCD.playground/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//: Playground - noun: a place where people can play
22

33
// Recursive version
4-
func gcd(a: Int, _ b: Int) -> Int {
4+
func gcd(_ a: Int, _ b: Int) -> Int {
55
let r = a % b
66
if r != 0 {
77
return gcd(b, r)
@@ -26,7 +26,7 @@ func gcd(m: Int, _ n: Int) -> Int {
2626
}
2727
*/
2828

29-
func lcm(m: Int, _ n: Int) -> Int {
29+
func lcm(_ m: Int, _ n: Int) -> Int {
3030
return m*n / gcd(m, n)
3131
}
3232

0 commit comments

Comments
 (0)