using System.Collections.Generic;
public string Label { get; }
public Node[] Children { get; }
public Node(string label, Node child)
Children = new [] { child };
public Node(string label, Node[] children = null)
Children = children ?? new Node[0];
public static void Main()
var graphRoot = new Node("A", new [] {
BreadthFirstSearch(graphRoot);
DepthFirstSearch(graphRoot);
static void BreadthFirstSearch(Node root)
var queue = new Queue<Node>();
while (queue.Count != 0) {
var current = queue.Dequeue();
Console.Write(current.Label + " ");
foreach (var child in current.Children) {
static void DepthFirstSearch(Node root)
var stack = new Stack<Node>();
while (stack.Count != 0) {
var current = stack.Pop();
Console.Write(current.Label + " ");
foreach (var child in current.Children) {