Beispiel #1
0
        private static void create_xml_ser_file()
        {
            var text   = File.ReadAllText("input.txt");
            var tree   = new BinaryTree <ID>();
            var parser = new FileParser(text);

            foreach (ID currId in parser)
            {
                tree.AddElement(currId);
            }
            tree.OutputTree(5);
            Console.ReadKey(true);

            XmlSerializer xml_serializer = new XmlSerializer(
                typeof(BinaryTree <ID>),
                new Type[]
            {
                typeof(ID),
                typeof(Class),
                typeof(Vars),
                typeof(Method),
                typeof(Constant),
                typeof(Vars[])
            });

            using (Stream f_stream = new FileStream("input_xml_ser.xml", FileMode.Create, FileAccess.Write, FileShare.None))
            {
                xml_serializer.Serialize(f_stream, tree);
            }
        }
Beispiel #2
0
        private static void Main()
        {
            var text   = File.ReadAllText("input.txt");
            var tree   = new BinaryTree <ID>();
            var parser = new FileParser(text);

            foreach (ID currId in parser)
            {
                tree.AddElement(currId);
            }
            tree.OutputTree(5);
            Console.ReadKey(true);
        }
        public void BinaryTree_CustomTypeCustomComparer_ExpetedResult()
        {
            Point p1 = new Point()
            {
                x = 7, y = 10, z = 10
            };
            Point p2 = new Point()
            {
                x = 4, y = 5, z = 5
            };
            Point p3 = new Point()
            {
                x = 5, y = 3, z = 2
            };
            Point p4 = new Point()
            {
                x = 9, y = 4, z = 6
            };
            Point p5 = new Point()
            {
                x = 7, y = 13, z = 15
            };
            Point p6 = new Point()
            {
                x = 2, y = 22, z = 18
            };
            Point p7 = new Point()
            {
                x = 13, y = 9, z = 9
            };

            PointComparer      comp = new PointComparer();
            BinaryTree <Point> tree = new BinaryTree <Point>(comp.Compare);

            tree.AddElement(p1);
            tree.AddElement(p2);
            tree.AddElement(p3);
            tree.AddElement(p4);
            tree.AddElement(p5);
            tree.AddElement(p6);
            tree.AddElement(p7);

            Point[] expected = { p3, p2, p4, p1, p7, p5, p6 };

            Point[] actual = new Point[expected.Length];
            int     i      = 0;

            foreach (Point point in tree.InorderTraversal())
            {
                actual[i++] = point;
            }

            Assert.AreEqual(expected, actual);
        }
        private void buttonOpenB_Click(object sender, EventArgs e)
        {
            if (ofdB.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            b = forBinaryTree.ReadFromFile(ofdB.FileName);

            for (int i = 0; i < b.Length; i++)
            {
                textBoxB.Text += b[i] + "\r\n";
            }

            tree = new BinaryTree();
            for (int i = 0; i < textBoxB.Lines.Length; i++)
            {
                tree.AddElement(textBoxB.Lines[i]);
            }
        }
Beispiel #5
0
        private static void create_b_ser_file()
        {
            var text   = File.ReadAllText("input.txt");
            var tree   = new BinaryTree <ID>();
            var parser = new FileParser(text);

            foreach (ID currId in parser)
            {
                tree.AddElement(currId);
            }
            tree.OutputTree(5);
            Console.ReadKey(true);

            BinaryFormatter bin_serializer = new BinaryFormatter();

            using (Stream f_stream = new FileStream("input_b_ser.dat", FileMode.Create, FileAccess.Write, FileShare.None))
            {
                bin_serializer.Serialize(f_stream, tree);
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var binaryTree = new BinaryTree <char>();

            binaryTree.AddElement('f');
            binaryTree.AddElement('b');
            binaryTree.AddElement('a');
            binaryTree.AddElement('d');
            binaryTree.AddElement('c');
            binaryTree.AddElement('e');
            binaryTree.AddElement('i');
            binaryTree.AddElement('h');
            binaryTree.AddElement('k');
            binaryTree.AddElement('j');
            binaryTree.AddElement('g');
            binaryTree.Traversal = Traversals.PostOrderTraversal;
            Console.WriteLine(string.Join(",", binaryTree));
            Console.WriteLine(binaryTree.Count);
            Console.Read();
        }