Esempio n. 1
0
        public void TestMethod1()
        {
            var node1 = new TreeNode(7);
            var node2 = new TreeNode(3);
            var node3 = new TreeNode(15);
            var node4 = new TreeNode(9);
            var node5 = new TreeNode(20);

            node1.Left  = node2;
            node1.Right = node3;
            node3.Left  = node4;
            node3.Right = node5;

            var iterator = new BinarySearchTreeIterator(node1);

            Assert.AreEqual(iterator.Next(), 3);        // return 3
            Assert.AreEqual(iterator.Next(), 7);        // return 7
            Assert.AreEqual(iterator.HasNext(), true);  // return true
            Assert.AreEqual(iterator.Next(), 9);        // return 9
            Assert.AreEqual(iterator.HasNext(), true);  // return true
            Assert.AreEqual(iterator.Next(), 15);       // return 15
            Assert.AreEqual(iterator.HasNext(), true);  // return true
            Assert.AreEqual(iterator.Next(), 20);       // return 20
            Assert.AreEqual(iterator.HasNext(), false); // return false
        }
Esempio n. 2
0
        void SortSymbolTable()
        {
            BinarySearchTreeIterator <Identifier> identifierIterator = Identifiers.CreateIterator();
            BinarySearchTreeIterator <Constant>   constantIterator   = Constants.CreateIterator();

            int index;

            index = 0;
            while (identifierIterator.Valid)
            {
                Identifier identifier = identifierIterator.CurrentElement;

                identifier.PositionOfIdentifier = index;
                index += 1;

                identifierIterator.Next();
            }

            index = 0;
            while (constantIterator.Valid)
            {
                Constant constant = constantIterator.CurrentElement;

                constant.PositionOfIdentifier = index;
                index += 1;

                constantIterator.Next();
            }
        }
Esempio n. 3
0
        static void PrintIdentifiers(BinarySearchTree <Identifier> identifiers)
        {
            BinarySearchTreeIterator <Identifier> iterator = identifiers.CreateIterator();

            Console.WriteLine("===> The symbols table for identifiers:");

            while (iterator.Valid)
            {
                Console.WriteLine(iterator.CurrentElement);
                iterator.Next();
            }
        }
Esempio n. 4
0
        static void PrintConstants(BinarySearchTree <Constant> constants)
        {
            BinarySearchTreeIterator <Constant> iterator = constants.CreateIterator();

            Console.WriteLine("===> The symbols table for constants:");

            while (iterator.Valid)
            {
                Console.WriteLine(iterator.CurrentElement);
                iterator.Next();
            }
        }