public void CheckOtherNodesAlsoChange() { StringTree stringTree = new StringTree(new Node("4")); stringTree.Add(new Node("3"), stringTree.Root); stringTree.Add(new Node("7"), stringTree.Root); stringTree.Add(new Node("15"), stringTree.Root); Program.FizzBuzzTree(stringTree); Assert.Equal("FizzBuzz", stringTree.Root.LeftChild.LeftChild.Value); }
/// <summary> /// Initializes a new instance of the <see cref="T:NavtelecomProtocol.PacketProcessors.NtcbPacketProcessor" /> class. /// </summary> /// <param name="bodyProcessors">Instances of <see cref="T:NavtelecomProtocol.PacketProcessors.Ntcb.IBodyProcessor" />.</param> public NtcbPacketProcessor(IEnumerable <INtcbBodyProcessor> bodyProcessors) { foreach (var bodyProcessor in bodyProcessors) { _bodyProcessors.Add(bodyProcessor.MessageIdentifier, bodyProcessor); } }
static void PreOrderFizzBuzz(Node root, StringTree newTree) { if (root.IntValue % 3 == 0 && root.IntValue % 5 == 0) { newTree.Add(root, "FizzBuzz", root.IntValue); } else if (root.IntValue % 3 == 0) { newTree.Add(root, "Fizz", root.IntValue); } else if (root.IntValue % 5 == 0) { newTree.Add(root, "Buzz", root.IntValue); } else { newTree.Add(root, root.IntValue.ToString(), root.IntValue); } PreOrderFizzBuzz(root.LeftChild, newTree); PreOrderFizzBuzz(root.RightChild, newTree); }
static void Main(string[] args) { StringTree stringTree = new StringTree(new Node("3")); stringTree.Add(new Node("5"), stringTree.Root); stringTree.Add(new Node("2"), stringTree.Root); stringTree.Add(new Node("4"), stringTree.Root); stringTree.Add(new Node("10"), stringTree.Root); stringTree.Add(new Node("9"), stringTree.Root); stringTree.Add(new Node("22"), stringTree.Root); stringTree.Add(new Node("15"), stringTree.Root); stringTree.BreadthFirst(stringTree.Root); Console.WriteLine("-----"); FizzBuzzTree(stringTree); stringTree.BreadthFirst(stringTree.Root); }