public void PrintPreOrder() { var tree = new SimpleTree <int>(2); Enumerable.Range(1, 5).ToList().ForEach(s => tree.AddNode(s)); var output = tree.PrintPreorder(); }
public void ListDepths() { // Arrange var tree = new SimpleTree <int>(2); tree.AddNode(11) .AddNode(21).AddNode(22) .AddNode(31).AddNode(32).AddNode(33).AddNode(34) .AddNode(41).AddNode(42).AddNode(43).AddNode(44); //.AddNode(45).AddNode(46).AddNode(47).AddNode(48); var output = new List <LinkedList <int> >(); var currentLimitLeafs = 1; var currentLinkedList = new LinkedList <int>(); var auxDs = new Queue <SimpleTree <int> .Node>(); void AddVisitedNode(SimpleTree <int> .Node node) { auxDs.Enqueue(node); currentLinkedList.AddLast(node.Value); if (currentLinkedList.Count == currentLimitLeafs) { currentLimitLeafs *= 2; output.Add(currentLinkedList); currentLinkedList = new LinkedList <int>(); } } // Do root manualy AddVisitedNode(tree.Root); while (auxDs.TryDequeue(out SimpleTree <int> .Node currentNode)) { // Left if (currentNode.Childrens[0] != null) { AddVisitedNode(currentNode.Childrens[0]); } // Right if (currentNode.Childrens[1] != null) { AddVisitedNode(currentNode.Childrens[1]); } } // Handling imcomplete trees if (currentLinkedList.Count > 0) { output.Add(currentLinkedList); } }
public void AddNode() { var tree = new SimpleTree <int>(3); Enumerable.Range(1, 100).ToList().ForEach(s => tree.AddNode(s)); }