//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {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; /// /// Instatiates the new node /// public Node() { dataNode = 0; leftNode = null; rightNode = null; dataTwo = ' '; } /// /// Instantiates the new node /// /// The ID number of the Node /// Left child (can be null) /// Right child (can be null) /// The letter representing the node public Node (int dNode, Node lNode, Node rNode, char d2Node) { dataNode = dNode; leftNode = lNode; rightNode = rNode; dataTwo = d2Node; } /// /// Node Accessor /// /// ID number of the node public int getData() { return dataNode; } /// /// Node accessor /// /// The right child of the node public Node returnRight() { return rightNode; } /// /// Node accessor /// /// The left child of the node public Node returnLeft() { return leftNode; } /// /// Node accessor /// /// The letter representing the node public char returnSecret() { return dataTwo; } /// /// Gets the size of the tree /// /// The node in the tree /// Tree size 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); } /// /// Gets the height of the tree /// /// The node of the tree /// Tree height 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)); } } }