コード例 #1
0
        public static void testSearchMethod(int seed)
        {
            List <Student> students = RandomStudentGenerator.GenerateStudents(seed, 10);

            Shuffle(ref students);
            MyDataTree dataTree = new MyDataTree();

            foreach (Student student in students)
            {
                dataTree.add(student);
            }

            Random  random        = new Random();
            Student studentToFind = students[random.Next(students.Count)];

            Console.WriteLine("\n\nStudent to find: " + studentToFind.toString());

            Student foundStudent = SearchTest(dataTree, studentToFind);

            if (foundStudent == null)
            {
                Console.WriteLine("Student not found in tree");
            }
            else
            {
                Console.WriteLine("Student was found in tree: " + foundStudent.toString());
            }
        }
コード例 #2
0
        public static void testSearchTimes(int seed)
        {
            Console.WriteLine("RED-BLACK tree search times\n");
            int[] numElementsArray = { 12800, 25600, 51200, 102400, 204800, 409600 };
            foreach (int numberOfElements in numElementsArray)
            {
                List <Student> students      = RandomStudentGenerator.GenerateStudents(seed, numberOfElements);
                Student        studentToFind = students[new Random().Next(students.Count)];
                MyDataTree     dataTree      = new MyDataTree();
                Shuffle(ref students);
                foreach (Student stud in students)
                {
                    dataTree.add(stud);
                }

                var watch = System.Diagnostics.Stopwatch.StartNew();
                SearchTest(dataTree, studentToFind);
                watch.Stop();
                Console.Write("\nNumber of elements: {0}, Runtime(ms): {1}, Ticks: {2}", numberOfElements, watch.Elapsed, watch.ElapsedTicks);
            }
        }