@@ -47,7 +47,7 @@ public class LinkedList<T> {
47
47
}
48
48
}
49
49
50
- public func nodeAtIndex ( index: Int ) -> Node ? {
50
+ public func nodeAt ( index: Int ) -> Node ? {
51
51
if index >= 0 {
52
52
var node = head
53
53
var i = index
@@ -61,7 +61,7 @@ public class LinkedList<T> {
61
61
}
62
62
63
63
public subscript( index: Int ) -> T {
64
- let node = nodeAtIndex ( index: index)
64
+ let node = nodeAt ( index: index)
65
65
assert ( node != nil )
66
66
return node!. value
67
67
}
@@ -111,7 +111,7 @@ public class LinkedList<T> {
111
111
head = nil
112
112
}
113
113
114
- public func removeNode ( node: Node ) -> T {
114
+ public func remove ( node: Node ) -> T {
115
115
let prev = node. previous
116
116
let next = node. next
117
117
@@ -129,13 +129,13 @@ public class LinkedList<T> {
129
129
130
130
public func removeLast( ) -> T {
131
131
assert ( !isEmpty)
132
- return removeNode ( node: last!)
132
+ return remove ( node: last!)
133
133
}
134
134
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)
137
137
assert ( node != nil )
138
- return removeNode ( node: node!)
138
+ return remove ( node: node!)
139
139
}
140
140
}
141
141
@@ -211,9 +211,9 @@ list.first!.next!.value // "World"
211
211
list. last!. previous!. value // "Hello"
212
212
list. last!. next // nil
213
213
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
217
217
218
218
list [ 0 ] // "Hello"
219
219
list [ 1 ] // "World"
@@ -227,8 +227,8 @@ print(list)
227
227
228
228
list. reverse ( ) // [World, Swift, Hello]
229
229
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 "
232
232
let m = list. map { s in s. characters. count }
233
233
m // [8, 6, 5]
234
234
let f = list. filter { s in s. characters. count > 5 }
@@ -237,7 +237,7 @@ f // [Universe, Swifty]
237
237
//list.removeAll()
238
238
//list.isEmpty
239
239
240
- list. removeNode ( node: list. first!) // "Hello"
240
+ list. remove ( node: list. first!) // "Hello"
241
241
list. count // 2
242
242
list [ 0 ] // "Swift"
243
243
list [ 1 ] // "World"
@@ -246,5 +246,5 @@ list.removeLast() // "World"
246
246
list. count // 1
247
247
list [ 0 ] // "Swift"
248
248
249
- list. removeAtIndex ( index: 0 ) // "Swift"
249
+ list. removeAt ( index: 0 ) // "Swift"
250
250
list. count // 0
0 commit comments