Skip to content

Commit b2fe7f3

Browse files
committed
Changed naming of functions to fit the Swift 3 style
Functions like nodeAtIndex(index: Int) are now nodeAt(index: Int)
1 parent bd5b4c0 commit b2fe7f3

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

Linked List/LinkedList.playground/Contents.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class LinkedList<T> {
4747
}
4848
}
4949

50-
public func nodeAtIndex(index: Int) -> Node? {
50+
public func nodeAt(index: Int) -> Node? {
5151
if index >= 0 {
5252
var node = head
5353
var i = index
@@ -61,7 +61,7 @@ public class LinkedList<T> {
6161
}
6262

6363
public subscript(index: Int) -> T {
64-
let node = nodeAtIndex(index: index)
64+
let node = nodeAt(index: index)
6565
assert(node != nil)
6666
return node!.value
6767
}
@@ -111,7 +111,7 @@ public class LinkedList<T> {
111111
head = nil
112112
}
113113

114-
public func removeNode(node: Node) -> T {
114+
public func remove(node: Node) -> T {
115115
let prev = node.previous
116116
let next = node.next
117117

@@ -129,13 +129,13 @@ public class LinkedList<T> {
129129

130130
public func removeLast() -> T {
131131
assert(!isEmpty)
132-
return removeNode(node: last!)
132+
return remove(node: last!)
133133
}
134134

135-
public func removeAtIndex(index: Int) -> T {
136-
let node = nodeAtIndex(index: index)
135+
public func removeAt(index: Int) -> T {
136+
let node = nodeAt(index: index)
137137
assert(node != nil)
138-
return removeNode(node: node!)
138+
return remove(node: node!)
139139
}
140140
}
141141

@@ -211,9 +211,9 @@ list.first!.next!.value // "World"
211211
list.last!.previous!.value // "Hello"
212212
list.last!.next // nil
213213

214-
list.nodeAtIndex(index: 0)!.value // "Hello"
215-
list.nodeAtIndex(index: 1)!.value // "World"
216-
list.nodeAtIndex(index: 2) // nil
214+
list.nodeAt(index: 0)!.value // "Hello"
215+
list.nodeAt(index: 1)!.value // "World"
216+
list.nodeAt(index: 2) // nil
217217

218218
list[0] // "Hello"
219219
list[1] // "World"
@@ -227,8 +227,8 @@ print(list)
227227

228228
list.reverse() // [World, Swift, Hello]
229229

230-
list.nodeAtIndex(index: 0)!.value = "Universe"
231-
list.nodeAtIndex(index: 1)!.value = "Swifty"
230+
list.nodeAt(index: 0)!.value = "Universe"
231+
list.nodeAt(index: 1)!.value = "Swifty"
232232
let m = list.map { s in s.characters.count }
233233
m // [8, 6, 5]
234234
let f = list.filter { s in s.characters.count > 5 }
@@ -237,7 +237,7 @@ f // [Universe, Swifty]
237237
//list.removeAll()
238238
//list.isEmpty
239239

240-
list.removeNode(node: list.first!) // "Hello"
240+
list.remove(node: list.first!) // "Hello"
241241
list.count // 2
242242
list[0] // "Swift"
243243
list[1] // "World"
@@ -246,5 +246,5 @@ list.removeLast() // "World"
246246
list.count // 1
247247
list[0] // "Swift"
248248

249-
list.removeAtIndex(index: 0) // "Swift"
249+
list.removeAt(index: 0) // "Swift"
250250
list.count // 0

Linked List/LinkedList.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class LinkedList<T> {
5050
}
5151
}
5252

53-
public func nodeAtIndex(index: Int) -> Node? {
53+
public func nodeAt(index: Int) -> Node? {
5454
if index >= 0 {
5555
var node = head
5656
var i = index
@@ -64,7 +64,7 @@ public class LinkedList<T> {
6464
}
6565

6666
public subscript(index: Int) -> T {
67-
let node = nodeAtIndex(index: index)
67+
let node = nodeAt(index: index)
6868
assert(node != nil)
6969
return node!.value
7070
}
@@ -114,7 +114,7 @@ public class LinkedList<T> {
114114
head = nil
115115
}
116116

117-
public func removeNode(node: Node) -> T {
117+
public func remove(node: Node) -> T {
118118
let prev = node.previous
119119
let next = node.next
120120

@@ -132,13 +132,13 @@ public class LinkedList<T> {
132132

133133
public func removeLast() -> T {
134134
assert(!isEmpty)
135-
return removeNode(node: last!)
135+
return remove(node: last!)
136136
}
137137

138-
public func removeAtIndex(index: Int) -> T {
139-
let node = nodeAtIndex(index: index)
138+
public func removeAt(index: Int) -> T {
139+
let node = nodeAt(index: index)
140140
assert(node != nil)
141-
return removeNode(node: node!)
141+
return remove(node: node!)
142142
}
143143
}
144144

0 commit comments

Comments
 (0)