File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -282,7 +282,7 @@ linkedList.count // 4
282
282
linkedList [ 0 ] // 1
283
283
284
284
// Infer the type from the array
285
- let listArrayLiteral2 : LinkedList ? = [ " Swift " , " Algorithm " , " Club " ]
286
- listArrayLiteral2? . count // 3
287
- listArrayLiteral2 ? [ 0 ] // "Swift"
288
- listArrayLiteral2? . removeLast ( ) // "Club"
285
+ let listArrayLiteral2 : LinkedList = [ " Swift " , " Algorithm " , " Club " ]
286
+ listArrayLiteral2. count // 3
287
+ listArrayLiteral2 [ 0 ] // "Swift"
288
+ listArrayLiteral2. removeLast ( ) // "Club"
Original file line number Diff line number Diff line change @@ -71,7 +71,8 @@ public final class LinkedList<T> {
71
71
self . append ( newNode)
72
72
}
73
73
74
- public func append( _ newNode: Node ) {
74
+ public func append( _ node: Node ) {
75
+ let newNode = Node ( value: node. value)
75
76
if let lastNode = last {
76
77
newNode. previous = lastNode
77
78
lastNode. next = newNode
@@ -102,9 +103,9 @@ public final class LinkedList<T> {
102
103
self . insert ( newNode, atIndex: index)
103
104
}
104
105
105
- public func insert( _ newNode : Node , atIndex index: Int ) {
106
+ public func insert( _ node : Node , atIndex index: Int ) {
106
107
let ( prev, next) = nodesBeforeAndAfter ( index: index)
107
-
108
+ let newNode = Node ( value : node . value )
108
109
newNode. previous = prev
109
110
newNode. next = next
110
111
prev? . next = newNode
You can’t perform that action at this time.
0 commit comments