Esempio n. 1
0
        /// <summary>
        /// counts the height of the tree recursiveley
        /// </summary>
        /// <param name="node"></param>
        /// <returns>int height</returns>
        public int height(IntNode node)
        {
            var result = 0;

            if (node != null)
            {
                result = Math.Max(height(node.leftLeaf), height(node.rightLeaf)) + 1;
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Prints the data of the node
        /// </summary>
        /// <param name="n"></param>
        public void display(IntNode n)
        {
            if (n == null)
            {
                return;
            }

            display(n.leftLeaf);
            Console.Write(" " + n.number);
            display(n.rightLeaf);
        }
Esempio n. 3
0
        /// <summary>
        /// Inserts new data into the tree
        /// </summary>
        /// <param name="d"></param>
        public void insert(int d)
        {
            if (isEmpty())
            {
                root = new IntNode(d);
            }
            else
            {
                root.insertData(ref root, d);
            }

            count++;
        }
Esempio n. 4
0
        /// <summary>
        /// takes in a node and data to be inserted and then inserts the node into
        /// the proper location based off the data.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="data"></param>
        public void insertData(ref IntNode node, int data)
        {
            if (node == null)
            {
                node = new IntNode(data);
            }
            else if (node.number < data)
            {
                insertData(ref node.rightLeaf, data);
            }

            else if (node.number > data)
            {
                insertData(ref node.leftLeaf, data);
            }
        }
Esempio n. 5
0
 public IntNode(int value)
 {
     number    = value;
     rightLeaf = null;
     leftLeaf  = null;
 }
Esempio n. 6
0
 public IntBinaryTree()
 {
     root  = null;
     count = 0;
 }