File tree Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -42,10 +42,10 @@ public final class LinkedList<T> {
42
42
43
43
/// Computed property to iterate through the linked list and return the last node in the list (if any)
44
44
public var last : Node ? {
45
- guard let head = head else {
45
+ guard var node = head else {
46
46
return nil
47
47
}
48
- var node = head
48
+
49
49
while let next = node. next {
50
50
node = next
51
51
}
@@ -54,10 +54,10 @@ public final class LinkedList<T> {
54
54
55
55
/// Computed property to iterate through the linked list and return the total number of nodes
56
56
public var count : Int {
57
- guard let head = head else {
57
+ guard var node = head else {
58
58
return 0
59
59
}
60
- var node = head
60
+
61
61
var count = 1
62
62
while let next = node. next {
63
63
node = next
Original file line number Diff line number Diff line change @@ -25,21 +25,21 @@ public final class LinkedList<T> {
25
25
}
26
26
27
27
public var last : Node ? {
28
- if var node = head {
29
- while let next = node. next {
30
- node = next
31
- }
32
- return node
33
- } else {
28
+ guard var node = head else {
34
29
return nil
35
30
}
31
+
32
+ while let next = node. next {
33
+ node = next
34
+ }
35
+ return node
36
36
}
37
37
38
38
public var count : Int {
39
- guard let head = head else {
39
+ guard var node = head else {
40
40
return 0
41
41
}
42
- var node = head
42
+
43
43
var count = 1
44
44
while let next = node. next {
45
45
node = next
You can’t perform that action at this time.
0 commit comments