예제 #1
0
        private static Pair ReadMember()
        {
            Pair result;

            var val = peek();

            var intValue = (long)val - 48;

            if (intValue >= 0 && intValue < 10)
            {
                read(); // get the number off the queue
                result = new LeafNode(intValue);
            }
            else
            {
                result = ParsePair();
            }

            return(result);
        }
예제 #2
0
        public TreeNode Clone()
        {
            Pair newLeft, newRight;

            if (left is TreeNode)
            {
                newLeft = ((TreeNode)left).Clone();
            }
            else
            {
                newLeft = new LeafNode(((LeafNode)left).value);
            }

            if (right is TreeNode)
            {
                newRight = ((TreeNode)right).Clone();
            }
            else
            {
                newRight = new LeafNode(((LeafNode)right).value);
            }

            return(new TreeNode(newLeft, newRight));
        }