publicclassGraph<T> { privateclassNode { public T Label { get; set; }
publicNode(T label) { Label = label; } }
privateDictionary<T, Node> nodes = new Dictionary<T, Node>();
privateDictionary<Node, List<Node>> adjacencyList = new Dictionary<Node, List<Node>>();
publicvoidAddNode(T label) { var node = new Node(label); if (!nodes.Keys.Contains(label)) { nodes.Add(label, node); } adjacencyList.Add(node, new List<Node>()); }
publicvoidRemoveNode(T label) { var result = nodes.TryGetValue(label, outvar node); if (!result) { return; }