Ejemplo n.º 1
0
        public string PrettyStringTree(RbNode node, TraversalOrder order)
        {
            string output;

            switch (order)
            {
            case TraversalOrder.PreOrder:
                output = PrettyStringTreePreOrder(Root);
                break;

            case TraversalOrder.InOrder:
                output = PrettyStringTreeInOrder(Root);
                break;

            case TraversalOrder.OutOrder:
                output = PrettyStringTreeOutOrder(Root);
                break;

            case TraversalOrder.PostOrder:
                output = PrettyStringTreePostOrder(Root);
                break;

            default:
                throw new ArgumentException($"Could not get pretty string for tree with Id={Id} because traversal order had unexpected value.");
            }

            return(output);
        }
Ejemplo n.º 2
0
 public bool ValidateTree(RbNode currentNode)
 {
     if (currentNode == null)
     {
         return(true);
     }
     return(ValidateTree(this.Root.Left) && this.Root.ValidateNode() && ValidateTree(this.Root.Right));
 }
Ejemplo n.º 3
0
        public string PrettyStringTreeOutOrder(RbNode currentNode)
        {
            var output = "";

            if (currentNode == null)
            {
                return("");
            }
            output += PrettyStringTreeOutOrder(currentNode.Right);
            output += currentNode.ToPrettyString() + "\n";
            output += PrettyStringTreeOutOrder(currentNode.Left);
            return(output);
        }
Ejemplo n.º 4
0
 public RedBlackTree(int key = 0, RbNode newRoot = null)
 {
     Id = Guid.NewGuid();
     if (newRoot == null)
     {
         newRoot = new RbNode
         {
             IsRoot = true
         };
     }
     this.Root = newRoot;
     Root.Key  = key;
 }
Ejemplo n.º 5
0
 public void DisplayTree(RbNode node, TraversalOrder order)
 {
     Console.WriteLine(PrettyStringTree(node, order));
 }