Skip to content

Commit 00326bc

Browse files
linked-list: fix
1 parent a0f7606 commit 00326bc

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

exercises/practice/linked-list/.meta/Example.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
public class Deque<T>
22
{
3-
private Element head;
3+
private Element? head;
44

55
public void Push(T value)
66
{
@@ -10,7 +10,7 @@ public void Push(T value)
1010
}
1111
else
1212
{
13-
var last = head.Next;
13+
var last = head.Next!;
1414
var e = new Element(value, last, head);
1515
last.Prev = e;
1616
head.Next = e;
@@ -19,27 +19,27 @@ public void Push(T value)
1919

2020
public T Pop()
2121
{
22-
head = head.Next;
22+
head = head?.Next;
2323
return Shift();
2424
}
2525

2626
public void Unshift(T value)
2727
{
2828
Push(value);
29-
head = head.Next;
29+
head = head?.Next;
3030
}
3131

3232
public T Shift()
3333
{
34-
var value = head.Value;
35-
var last = head.Next;
34+
var value = head!.Value;
35+
var last = head.Next!;
3636

3737
if (last == head)
3838
head = null;
3939
else
4040
{
4141
last.Prev = head.Prev;
42-
head.Prev.Next = last;
42+
head.Prev!.Next = last;
4343
head = head.Prev;
4444
}
4545

@@ -49,10 +49,10 @@ public T Shift()
4949
private class Element
5050
{
5151
public readonly T Value;
52-
public Element Next;
53-
public Element Prev;
52+
public Element? Next;
53+
public Element? Prev;
5454

55-
public Element(T value, Element next = null, Element prev = null)
55+
public Element(T value, Element? next = null, Element? prev = null)
5656
{
5757
Value = value;
5858
Next = next ?? this;

0 commit comments

Comments
 (0)