Exemple #1
0
        static void Main(string[] args)
        {
            // Linked List Example
            LinkedList.LinkedList <int> list = new LinkedList.LinkedList <int>();

            list.push_back(123);
            list.push_back(456);
            list.push_back(789);

            int i = 1;

            foreach (int val in list)
            {
                Console.WriteLine($"{i}: {val}");
                i += 1;
            }

            Console.WriteLine(list);

            list.pop_back();
            Console.WriteLine(list);

            list.pop_back();
            Console.WriteLine(list);

            list.pop_back();
            Console.WriteLine(list);


            // Binary Tree Example
            BinaryTree.BinaryTree <int, int> tree = new BinaryTree.BinaryTree <int, int>();

            tree.insert(2, 123);
            tree.insert(1, 456);
            tree.insert(3, 789);

            tree.remove(2);

            tree.find(2);
            tree.find(1);
            tree.find(3);


            // Insertion Sort Example
            int[] arr = { 2, 7, 3, 11, 6 };

            MySort.InsertionSort(arr);
        }
Exemple #2
0
        public void TestInsertAndFind()
        {
            Assert.IsNull(tree.find(2));
            Assert.IsNull(tree.find(3));

            tree.insert(2, 123);

            Assert.AreEqual(tree.find(2).key, 2);
            Assert.AreEqual(tree.find(2).val, 123);

            tree.insert(2, 456);

            Assert.AreEqual(tree.find(2).key, 2);
            Assert.AreEqual(tree.find(2).val, 456);

            tree.insert(3, 456);

            Assert.AreEqual(tree.find(3).key, 3);
            Assert.AreEqual(tree.find(3).val, 456);
        }