Exemplo n.º 1
0
        public void InsertionSortWorksAsExpected()
        {
            List <int> unsortedNumbers = new List <int>()
            {
                10, 9, 8, 7, 6, 5, 4, 3, 2, 1
            };
            List <int> expected = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };
            List <int> actual = MyInsertionSort.ISort(unsortedNumbers);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            MyList <int>    intList    = new MyList <int>();
            MyList <string> stringList = new MyList <string>();

            Console.WriteLine("CREATE LIST");

            intList.Add(1);
            intList.Add(2);
            intList.Add(3);
            intList.Add(4);
            intList.Add(5);

            Console.WriteLine("Add 1, 2, 3, 4, 5 to intList:");

            foreach (var item in intList)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            intList.Remove(2);
            Console.WriteLine("Delete 2 from intList:");
            foreach (var item in intList)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            bool f = intList.Contains(3);

            Console.WriteLine(f == true ? "List contain 3" : "List doesn't contain 3");

            Console.WriteLine("Add 0 first in intList:");
            intList.AppendFirst(0);
            foreach (var item in intList)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            Console.WriteLine("Reverse 0 1 3 4 5:");
            foreach (var item in intList.Reverse())
            {
                Console.Write(item + " ");
            }

            Console.WriteLine();

            intList.Clear();
            Console.ReadKey();
            Console.Clear();


            Console.WriteLine("CREATE BINARY TREE:");


            var binaryTree = new BinaryTree <int>();

            binaryTree.Add(8);
            binaryTree.Add(3);
            binaryTree.Add(10);
            binaryTree.Add(1);
            binaryTree.Add(6);
            binaryTree.Add(4);
            binaryTree.Add(7);
            binaryTree.Add(14);
            binaryTree.Add(18);

            binaryTree.PrintTree();

            Console.WriteLine(new string('-', 40));
            Console.WriteLine("Delete 3 from tree:");
            binaryTree.Remove(3);
            binaryTree.PrintTree();

            Console.WriteLine(new string('-', 40));
            Console.WriteLine("Delete 8 from tree:");
            binaryTree.Remove(8);
            binaryTree.PrintTree();

            Console.WriteLine(new string('-', 40));

            if (binaryTree.FindNode(10) == null)
            {
                Console.WriteLine("DON'T FIND 10 in tree");
            }
            else
            {
                Console.WriteLine("FIND 10 in tree");
            }

            Console.ReadKey();
            Console.Clear();


            Console.WriteLine("SORT:");
            foreach (var item in MyInsertionSort.MySort(new[] { -5, 25, 25, 5, 0, -1, 0, -50 }))
            {
                Console.Write(item + " ");
            }

            Console.ReadKey();
        }
Exemplo n.º 3
0
 public void CanInsertionSort <TIn>(TIn[] input, TIn[] expected) where TIn : IComparable <TIn>
 {
     MyInsertionSort.Sort(input);
     Assert.Equal(expected, input);
 }