Пример #1
0
        private void Run()
        {
            int smallSize = 1000;
            int largeSize = smallSize * 10;

            ClubMember[] smallLinear = new ClubMember[smallSize];
            ClubMember[] largeLinear = new ClubMember[largeSize];

            ClubMember[] smallBinary = new ClubMember[smallSize];
            ClubMember[] largeBinary = new ClubMember[largeSize];

            FillArrays(ref smallLinear);
            FillArrays(ref largeLinear);
            FillArrays(ref smallBinary);
            FillArrays(ref largeBinary);

            switch (GetInput())
            {
            case 1: Exercise1(); break;

            case 2: Exercise2(); break;

            case 3: Exercise3(); break;

            case 4: Exercise4(smallLinear, largeLinear); break;

            case 5: Exercise5(smallBinary, largeBinary); break;

            case 6: Exercise6(); break;
            }
        }
Пример #2
0
        public void SearchLinear(IComparable[] arr)
        {
            Stopwatch  stopwatch = Stopwatch.StartNew();
            bool       check;
            ClubMember clubMember1 = (ClubMember)arr[rnd.Next(0, arr.Length - 1)];
            ClubMember clubMember2 = (ClubMember)arr[rnd.Next(0, arr.Length - 1)];
            ClubMember clubMember3 = (ClubMember)arr[rnd.Next(0, arr.Length - 1)];
            ClubMember found1      = null;
            ClubMember found2      = null;
            ClubMember found3      = null;

            Console.WriteLine(clubMember1.ToString());
            Console.WriteLine(clubMember2.ToString());
            Console.WriteLine(clubMember3.ToString());
            for (int i = 0; i < 1000; i++)
            {
                check = true;
                int j = 0;
                while (check && j < arr.Length)
                {
                    if (clubMember1.Equals(arr[j]))
                    {
                        check  = false;
                        found1 = (ClubMember)arr[j];
                    }
                    j++;
                }
                check = true;
                j     = 0;
                while (check && j < arr.Length)
                {
                    if (clubMember2.Equals(arr[j]))
                    {
                        check  = false;
                        found2 = (ClubMember)arr[j];
                    }
                    j++;
                }
                check = true;
                j     = 0;
                while (check && j < arr.Length)
                {
                    if (clubMember3.Equals(arr[j]))
                    {
                        check  = false;
                        found3 = (ClubMember)arr[j];
                    }
                    j++;
                }
            }
            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedMilliseconds + "ms");
            Console.WriteLine(found1.ToString());
            Console.WriteLine(found2.ToString());
            Console.WriteLine(found3.ToString() + "\n");
        }
Пример #3
0
        public override bool Equals(object obj)
        {
            ClubMember cM = (ClubMember)obj;

            if (Nr == cM.Nr && Fname.Equals(cM.Fname) && Lname.Equals(cM.Lname) && Age == cM.Age)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
        private void Exercise6()
        {
            Console.WriteLine("Exercise 6");
            ClubMember clubMember1 = new ClubMember(0, "Matt", "Peterson", 18);
            ClubMember clubMember2 = new ClubMember(1, "Matt", "Perry", 26);
            ClubMember clubMember3 = new ClubMember(2, "Anthony", "Peterson", 52);
            ClubMember clubMember4 = new ClubMember(3, "Carmelo", "Anthony", 30);

            BST.Insert(clubMember1);
            BST.Insert(clubMember2);
            BST.Insert(clubMember3);
            BST.Insert(clubMember4);
            Console.WriteLine(clubMember2.ToString() + " " + BST.Search(clubMember2).ToString());
            Console.ReadKey();
        }
Пример #5
0
        private static void Exercise2()
        {
            Console.WriteLine("Exercise 2");
            ClubMember clubMember1 = new ClubMember(0, "Matt", "Peterson", 18);
            ClubMember clubMember2 = new ClubMember(1, "Matt", "Perry", 26);
            ClubMember clubMember3 = new ClubMember(2, "Anthony", "Peterson", 52);
            ClubMember clubMember4 = new ClubMember(3, "Carmelo", "Anthony", 30);

            linkedList.Insert(clubMember1);
            linkedList.Insert(clubMember2);
            linkedList.Insert(clubMember4);
            PrintList();
            linkedList.Insert(1, clubMember3);
            PrintList();
            linkedList.Delete(2);
            PrintList();
        }
Пример #6
0
        private void Exercise3()
        {
            Console.WriteLine("Exercise 3");
            ClubMember clubMember1 = new ClubMember(0, "Matt", "Peterson", 18);
            ClubMember clubMember2 = new ClubMember(1, "Matt", "Perry", 26);
            ClubMember clubMember3 = new ClubMember(2, "Anthony", "Peterson", 52);
            ClubMember clubMember4 = new ClubMember(3, "Carmelo", "Anthony", 30);

            linkedList.Insert(clubMember2);
            linkedList.Insert(clubMember1);
            linkedList.Insert(clubMember4);
            linkedList.Insert(clubMember3);
            for (int i = 0; i < 10; i++)
            {
                linkedList.Insert(CMFactory.GetClubMember());
            }
            PrintList();
            linkedList.SortNr();
            PrintList();
        }
Пример #7
0
        public void SortNr()
        {
            Node pointer = Head;
            bool swapped = false;

            do
            {
                pointer = Head;
                swapped = false;
                while (pointer.Next != null)
                {
                    ClubMember a = (ClubMember)pointer.Data;
                    ClubMember b = (ClubMember)pointer.Next.Data;
                    if (a.Nr > b.Nr)
                    {
                        Change(pointer, pointer.Next);
                        swapped = true;
                    }
                    pointer = pointer.Next;
                }
            } while (swapped == true);
        }
Пример #8
0
        public int CompareTo(object obj)
        {
            int        Result = 0;
            ClubMember Other  = (ClubMember)obj;

            Result = Nr.CompareTo(Other.Nr);

            if (Result == 0)
            {
                Result = Fname.CompareTo(Other.Fname);
            }

            if (Result == 0)
            {
                Result = Lname.CompareTo(Other.Lname);
            }

            if (Result == 0)
            {
                Result = Age.CompareTo(Other.Age);
            }

            return(Result);
        }
Пример #9
0
        public void SearchBinary(IComparable[] arr)
        {
            Stopwatch  stopwatch = Stopwatch.StartNew();
            int        middle;
            int        min;
            int        max;
            ClubMember clubMember1 = (ClubMember)arr[rnd.Next(0, arr.Length - 1)];
            ClubMember clubMember2 = (ClubMember)arr[rnd.Next(0, arr.Length - 1)];
            ClubMember clubMember3 = (ClubMember)arr[rnd.Next(0, arr.Length - 1)];
            ClubMember found1      = null;
            ClubMember found2      = null;
            ClubMember found3      = null;

            Console.WriteLine(clubMember1.ToString());
            Console.WriteLine(clubMember2.ToString());
            Console.WriteLine(clubMember3.ToString());
            for (int i = 0; i < 1000; i++)
            {
                middle = arr.Length / 2;
                min    = 0;
                max    = arr.Length;
                while (found1 == null)
                {
                    if (clubMember1.CompareTo(arr[middle]) == 1)
                    {
                        min    = middle;
                        middle = middle + ((max - middle) / 2);
                    }
                    else if (clubMember1.CompareTo(arr[middle]) == -1)
                    {
                        max    = middle;
                        middle = min + ((middle - min) / 2);
                    }
                    else
                    {
                        found1 = (ClubMember)arr[middle];
                    }
                }
                middle = arr.Length / 2;
                min    = 0;
                max    = arr.Length;
                while (found2 == null)
                {
                    if (clubMember2.CompareTo(arr[middle]) == 1)
                    {
                        min    = middle;
                        middle = middle + ((max - middle) / 2);
                    }
                    else if (clubMember2.CompareTo(arr[middle]) == -1)
                    {
                        max    = middle;
                        middle = min + ((middle - min) / 2);
                    }
                    else
                    {
                        found2 = (ClubMember)arr[middle];
                    }
                }
                middle = arr.Length / 2;
                min    = 0;
                max    = arr.Length;
                while (found3 == null)
                {
                    if (clubMember3.CompareTo(arr[middle]) == 1)
                    {
                        min    = middle;
                        middle = middle + ((max - middle) / 2);
                    }
                    else if (clubMember3.CompareTo(arr[middle]) == -1)
                    {
                        max    = middle;
                        middle = min + ((middle - min) / 2);
                    }
                    else
                    {
                        found3 = (ClubMember)arr[middle];
                    }
                }
            }
            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedMilliseconds + "ms");
            Console.WriteLine(found1.ToString());
            Console.WriteLine(found2.ToString());
            Console.WriteLine(found3.ToString() + "\n");
        }