示例#1
0
文件: Node.cs 项目: bjpayne/CSCI312
        /**
         * 1. If the node is leaf and the current Trees' symbol matches return the data or null
         * 2. If the left node is not null then initialize a new set of left nodes and add the data to each. Set next to bin 0
         * 3. If the right node is not null then initialize a new set of right nodes and add the data to each. Set next to bin 1
         */
        public List <Boolean> Walk(Char symbol, List <Boolean> data)
        {
            if (RightNode == null && LeftNode == null)
            {
                return(symbol.Equals(NodeSymbol) ? data : null);
            }

            List <Boolean> left  = null;
            List <Boolean> right = null;

            if (LeftNode != null)
            {
                List <Boolean> leftNodes = new List <Boolean>();

                for (Int32 i = 0; i < data.Count; i++)
                {
                    leftNodes.Add(data[i]);
                }

                // Set to bin 0
                leftNodes.Add(false);

                left = LeftNode.Walk(symbol, leftNodes);
            }

            if (RightNode != null)
            {
                List <Boolean> rightNodes = new List <Boolean>();

                for (Int32 i = 0; i < data.Count; i++)
                {
                    rightNodes.Add(data[i]);
                }

                // Set to bin 1
                rightNodes.Add(true);

                right = RightNode.Walk(symbol, rightNodes);
            }

            // Left is not null then left else right
            return(left ?? right);
        }