Esempio n. 1
0
        public void AddChild(Node child)
        {
            if (child.Grade > this.Grade)
            {
                if (this.Right == null)
                {
                    child.Parent = this;
                    this.Right = child;
                    return;
                }

                this.Right.AddChild(child);
                return;
            }

            if (child.Grade < this.Grade)
            {
                if (this.Left == null)
                {
                    child.Parent = this;
                    this.Left = child;
                    return;
                }

                this.Left.AddChild(child);
            }
        }
Esempio n. 2
0
        public Node Create()
        {
            var root = new Node(_grades[0]);
            for (int i = 1; i < _grades.Length; i++)
            {
                Node node1 = new Node(_grades[i]);
                root.AddChild(node1);
            }

            return root;
        }
Esempio n. 3
0
        public void PrintPreOrder(Node root)
        {
            Console.WriteLine(root.Grade);

            if (root.Left != null)
            {
                PrintPreOrder(root.Left);
            }

            if (root.Right != null)
            {
                PrintPreOrder(root.Right);
            }
        }