@@ -13,7 +13,7 @@ public class LinkedListNode<T> {
13
13
public class LinkedList < T> {
14
14
public typealias Node = LinkedListNode < T >
15
15
16
- private var head : Node ?
16
+ fileprivate var head : Node ?
17
17
18
18
public var isEmpty : Bool {
19
19
return head == nil
@@ -61,7 +61,7 @@ public class LinkedList<T> {
61
61
}
62
62
63
63
public subscript( index: Int ) -> T {
64
- let node = nodeAtIndex ( index)
64
+ let node = nodeAtIndex ( index: index )
65
65
assert ( node != nil )
66
66
return node!. value
67
67
}
@@ -94,7 +94,7 @@ public class LinkedList<T> {
94
94
}
95
95
96
96
public func insert( value: T , atIndex index: Int ) {
97
- let ( prev, next) = nodesBeforeAndAfter ( index)
97
+ let ( prev, next) = nodesBeforeAndAfter ( index: index )
98
98
99
99
let newNode = Node ( value: value)
100
100
newNode. previous = prev
@@ -129,13 +129,13 @@ public class LinkedList<T> {
129
129
130
130
public func removeLast( ) -> T {
131
131
assert ( !isEmpty)
132
- return removeNode ( last!)
132
+ return removeNode ( node : last!)
133
133
}
134
134
135
135
public func removeAtIndex( index: Int ) -> T {
136
- let node = nodeAtIndex ( index)
136
+ let node = nodeAtIndex ( index: index )
137
137
assert ( node != nil )
138
- return removeNode ( node!)
138
+ return removeNode ( node: node !)
139
139
}
140
140
}
141
141
@@ -164,22 +164,22 @@ extension LinkedList {
164
164
}
165
165
166
166
extension LinkedList {
167
- public func map< U> ( transform: T -> U ) -> LinkedList < U > {
167
+ public func map< U> ( transform: ( T ) -> U ) -> LinkedList < U > {
168
168
let result = LinkedList < U > ( )
169
169
var node = head
170
170
while node != nil {
171
- result. append ( transform ( node!. value) )
171
+ result. append ( value : transform ( node!. value) )
172
172
node = node!. next
173
173
}
174
174
return result
175
175
}
176
176
177
- public func filter( predicate: T -> Bool ) -> LinkedList < T > {
177
+ public func filter( predicate: ( T ) -> Bool ) -> LinkedList < T > {
178
178
let result = LinkedList < T > ( )
179
179
var node = head
180
180
while node != nil {
181
181
if predicate ( node!. value) {
182
- result. append ( node!. value)
182
+ result. append ( value : node!. value)
183
183
}
184
184
node = node!. next
185
185
}
@@ -195,13 +195,13 @@ list.isEmpty // true
195
195
list. first // nil
196
196
list. last // nil
197
197
198
- list. append ( " Hello " )
198
+ list. append ( value : " Hello " )
199
199
list. isEmpty
200
200
list. first!. value // "Hello"
201
201
list. last!. value // "Hello"
202
202
list. count // 1
203
203
204
- list. append ( " World " )
204
+ list. append ( value : " World " )
205
205
list. first!. value // "Hello"
206
206
list. last!. value // "World"
207
207
list. count // 2
@@ -211,24 +211,24 @@ list.first!.next!.value // "World"
211
211
list. last!. previous!. value // "Hello"
212
212
list. last!. next // nil
213
213
214
- list. nodeAtIndex ( 0 ) !. value // "Hello"
215
- list. nodeAtIndex ( 1 ) !. value // "World"
216
- list. nodeAtIndex ( 2 ) // nil
214
+ list. nodeAtIndex ( index : 0 ) !. value // "Hello"
215
+ list. nodeAtIndex ( index : 1 ) !. value // "World"
216
+ list. nodeAtIndex ( index : 2 ) // nil
217
217
218
218
list [ 0 ] // "Hello"
219
219
list [ 1 ] // "World"
220
220
//list[2] // crash!
221
221
222
- list. insert ( " Swift " , atIndex: 1 )
222
+ list. insert ( value : " Swift " , atIndex: 1 )
223
223
list [ 0 ]
224
224
list [ 1 ]
225
225
list [ 2 ]
226
226
print ( list)
227
227
228
228
list. reverse ( ) // [World, Swift, Hello]
229
229
230
- list. nodeAtIndex ( 0 ) !. value = " Universe "
231
- list. nodeAtIndex ( 1 ) !. value = " Swifty "
230
+ list. nodeAtIndex ( index : 0 ) !. value = " Universe "
231
+ list. nodeAtIndex ( 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 ( list. first!) // "Hello"
240
+ list. removeNode ( 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 ( 0 ) // "Swift"
249
+ list. removeAtIndex ( index : 0 ) // "Swift"
250
250
list. count // 0
0 commit comments