-
-
Notifications
You must be signed in to change notification settings - Fork 426
/
Copy pathProgram.cs
71 lines (64 loc) · 1.99 KB
/
Program.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
71
// Install dotnet core clr see VS Code docs on how to setup VS Code so that you can debug C# applications.
// The Debug Visualizer does not support C# data extractors yet.
// If you want to visualize a value, it's `ToString` method must return supported json data.
// See the readme of the extension for supported json schemas.
#nullable enable
using System.Linq;
using Hediet.DebugVisualizer.ExtractedData;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
var list = new LinkedList<int>();
// visualize `list.Visualize()` here!
list.Append(1);
list.Append(2);
list.Append(3);
list.Append(4);
}
}
class LinkedList<T>
{
class Node
{
public Node(T value) { Value = value; }
public T Value { get; set; }
public Node? Next { get; set; }
}
private Node? Head { get; set; }
public void Append(T item)
{
if (this.Head == null)
{
this.Head = new Node(item);
}
else
{
var cur = this.Head;
while (cur.Next != null)
{
cur = cur.Next;
}
cur.Next = new Node(item);
}
}
public string Visualize()
{
var list = new Node(default(T)!) { Next = this.Head };
return GraphData.From(new[] { list }, (item, info) =>
{
info.Id = item == list ? "List" : string.Format("{0}", item.Value);
if (item == list)
{
info.Color = "orange";
}
if (item.Next != null)
info.AddEdge(item.Next!, label: item == list ? "head" : "next");
return info;
}).ToString();
}
}
}