-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.cs
70 lines (54 loc) · 1.53 KB
/
Node.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
namespace DataStructures
{
class Node
{
public Node Next = null;
public int Data;
public Node(int number)
{
Data = number;
}
public void AppendToTail(int number)
{
var end = new Node(number);
var node = this;
while (node.Next != null)
{
node = node.Next;
}
node.Next = end;
}
public Node DeleteNode(Node headNode, int number)
{
var node = headNode;
if (node.Data == number)
{
return headNode.Next;
}
while (node.Next != null)
{
if (node.Next.Data == number)
{
node.Next = node.Next.Next;
return headNode;
}
node = node.Next;
}
return headNode;
}
/*
* Example Main method code:
* Console.WriteLine(DateTime.Now.Millisecond);
var headNode = new Node(0);
for (var loopCounter = 1; loopCounter <= 100; loopCounter++)
{
headNode.AppendToTail(loopCounter);
}
Console.WriteLine(DateTime.Now.Millisecond);
Console.WriteLine(DateTime.Now.Millisecond);
headNode.DeleteNode(headNode, 100);
Console.WriteLine(DateTime.Now.Millisecond);
var dummy = Console.ReadLine();
*/
}
}