/// <summary> /// 幅優先探索 /// </summary> /// <param name="target"></param> /// <returns></returns> public Node <T> BreadthFirstSearch(T target) { int count = 0; var queue = new SelfQueue <Node <T> >(); queue.Enqueue(_root); while (queue.Count > 0) { count++; var node = queue.Dequeue(); if (node.Value.Equals(target)) { Console.WriteLine($"幅優先探索:{count}"); return(node); } if (node.Children.Count > 0) { foreach (var child in node.Children) { queue.Enqueue(child); } } } return(null); }
public void EnqueueTest(T[] inputs) { var queue = new SelfQueue <T>(); foreach (var input in inputs) { queue.Enqueue(input); } Assert.AreEqual(inputs.Length, queue.Count); Console.WriteLine($"入力:{inputs.Length}, 出力:{queue.Count}"); }
public void DequeueTest(T[] inputs) { var queue = new SelfQueue <T>(); foreach (var input in inputs) { queue.Enqueue(input); } foreach (var input in inputs) { var item = queue.Dequeue(); Assert.AreEqual(input, item); Console.WriteLine($"{input},{item}"); } }
public void DequeueException(T[] inputs) { var queue = new SelfQueue <T>(); foreach (var input in inputs) { queue.Enqueue(input); } foreach (var input in inputs) { queue.Dequeue(); } Assert.That(() => { queue.Dequeue(); }, Throws.Exception.With.Message.EqualTo("できゅーしすぎなのおおおおおお")); }