//---------------------------------------------------------------------------------------------------------------------------------------------------
// <copyright file="Node.cs" company="DarkWynter Studios">
//     Copyright (C)2007 DarkWynter Studios.  All rights reserved.
// </copyright>
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------

namespace DarkWynter.Engine.Compiler
{
    #region Using Statements
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    #endregion

    public class Node
    {
        private char dataTwo;
        private int dataNode;
        private Node leftNode;
        private Node rightNode;

        /// <summary>
        /// Instatiates the new node
        /// </summary>
        public Node()
        {
            dataNode = 0;
            leftNode = null;
            rightNode = null;
            dataTwo = ' ';
        }
        /// <summary>
        /// Instantiates the new node
        /// </summary>
        /// <param name="dNode">The ID number of the Node</param>
        /// <param name="lNode">Left child (can be null)</param>
        /// <param name="rNode">Right child (can be null)</param>
        /// <param name="d2Node">The letter representing the node</param>
        public Node (int dNode, Node lNode, Node rNode, char d2Node)
        {
            dataNode = dNode;
            leftNode = lNode;
            rightNode = rNode;
            dataTwo = d2Node;
        }
        /// <summary>
        /// Node Accessor 
        /// </summary>
        /// <returns>ID number of the node</returns>
        public int getData()
        {
            return dataNode;
        }
        /// <summary>
        /// Node accessor
        /// </summary>
        /// <returns>The right child of the node</returns>
        public Node returnRight()
        {
            return rightNode;
        }
        /// <summary>
        /// Node accessor
        /// </summary>
        /// <returns>The left child of the node</returns>
        public Node returnLeft()
        {
            return leftNode;
        }
        /// <summary>
        /// Node accessor
        /// </summary>
        /// <returns>The letter representing the node</returns>
        public char returnSecret()
        {
            return dataTwo;
        }
        /// <summary>
        /// Gets the size of the tree
        /// </summary>
        /// <param name="node">The node in the tree</param>
        /// <returns>Tree size</returns>
        public static int getSize(Node node)
        {  
            if (node == null)
                return 0;
            else if (node.leftNode == null && node.rightNode == null)
                return 1;
            else return 1 + getSize(node.rightNode) + getSize(node.leftNode);
        }
        /// <summary>
        /// Gets the height of the tree
        /// </summary>
        /// <param name="node">The node of the tree</param>
        /// <returns>Tree height</returns>
        public static int getHeight(Node node)
        {
            if (node == null)
                return 0;
            else if (node.leftNode == null && node.rightNode == null)
                return 1;
            else return 1 + Math.Max(getHeight(node.rightNode), getHeight(node.leftNode));
        }
    }
}