@@ -13,7 +13,7 @@ public class LinkedListNode<T> {
1313public class LinkedList < T> {
1414 public typealias Node = LinkedListNode < T >
1515
16- private var head : Node ?
16+ fileprivate var head : Node ?
1717
1818 public var isEmpty : Bool {
1919 return head == nil
@@ -61,7 +61,7 @@ public class LinkedList<T> {
6161 }
6262
6363 public subscript( index: Int ) -> T {
64- let node = nodeAtIndex ( index)
64+ let node = nodeAtIndex ( index: index )
6565 assert ( node != nil )
6666 return node!. value
6767 }
@@ -94,7 +94,7 @@ public class LinkedList<T> {
9494 }
9595
9696 public func insert( value: T , atIndex index: Int ) {
97- let ( prev, next) = nodesBeforeAndAfter ( index)
97+ let ( prev, next) = nodesBeforeAndAfter ( index: index )
9898
9999 let newNode = Node ( value: value)
100100 newNode. previous = prev
@@ -129,13 +129,13 @@ public class LinkedList<T> {
129129
130130 public func removeLast( ) -> T {
131131 assert ( !isEmpty)
132- return removeNode ( last!)
132+ return removeNode ( node : last!)
133133 }
134134
135135 public func removeAtIndex( index: Int ) -> T {
136- let node = nodeAtIndex ( index)
136+ let node = nodeAtIndex ( index: index )
137137 assert ( node != nil )
138- return removeNode ( node!)
138+ return removeNode ( node: node !)
139139 }
140140}
141141
@@ -164,22 +164,22 @@ extension LinkedList {
164164}
165165
166166extension LinkedList {
167- public func map< U> ( transform: T -> U ) -> LinkedList < U > {
167+ public func map< U> ( transform: ( T ) -> U ) -> LinkedList < U > {
168168 let result = LinkedList < U > ( )
169169 var node = head
170170 while node != nil {
171- result. append ( transform ( node!. value) )
171+ result. append ( value : transform ( node!. value) )
172172 node = node!. next
173173 }
174174 return result
175175 }
176176
177- public func filter( predicate: T -> Bool ) -> LinkedList < T > {
177+ public func filter( predicate: ( T ) -> Bool ) -> LinkedList < T > {
178178 let result = LinkedList < T > ( )
179179 var node = head
180180 while node != nil {
181181 if predicate ( node!. value) {
182- result. append ( node!. value)
182+ result. append ( value : node!. value)
183183 }
184184 node = node!. next
185185 }
@@ -195,13 +195,13 @@ list.isEmpty // true
195195list. first // nil
196196list. last // nil
197197
198- list. append ( " Hello " )
198+ list. append ( value : " Hello " )
199199list. isEmpty
200200list. first!. value // "Hello"
201201list. last!. value // "Hello"
202202list. count // 1
203203
204- list. append ( " World " )
204+ list. append ( value : " World " )
205205list. first!. value // "Hello"
206206list. last!. value // "World"
207207list. count // 2
@@ -211,24 +211,24 @@ list.first!.next!.value // "World"
211211list. last!. previous!. value // "Hello"
212212list. last!. next // nil
213213
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
217217
218218list [ 0 ] // "Hello"
219219list [ 1 ] // "World"
220220//list[2] // crash!
221221
222- list. insert ( " Swift " , atIndex: 1 )
222+ list. insert ( value : " Swift " , atIndex: 1 )
223223list [ 0 ]
224224list [ 1 ]
225225list [ 2 ]
226226print ( list)
227227
228228list. reverse ( ) // [World, Swift, Hello]
229229
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 "
232232let m = list. map { s in s. characters. count }
233233m // [8, 6, 5]
234234let 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 ( list. first!) // "Hello"
240+ list. removeNode ( node : list. first!) // "Hello"
241241list. count // 2
242242list [ 0 ] // "Swift"
243243list [ 1 ] // "World"
@@ -246,5 +246,5 @@ list.removeLast() // "World"
246246list. count // 1
247247list [ 0 ] // "Swift"
248248
249- list. removeAtIndex ( 0 ) // "Swift"
249+ list. removeAtIndex ( index : 0 ) // "Swift"
250250list. count // 0
0 commit comments