Пример #1
0
        public override bool Equals(object obj)
        {
            bool       allEqual = false;
            ClubMember cm       = (ClubMember)obj;

            if (this.Nr == cm.Nr && this.Fname == cm.Fname && this.Lname == cm.Lname && this.Age == cm.Age)
            {
                allEqual = true;
            }

            return(allEqual);
        }
Пример #2
0
        public bool Contains(object data)
        {
            bool       containsData = false;
            Node       pointer      = Head;
            ClubMember cm           = (ClubMember)data;

            while (containsData == false && pointer != null)
            {
                if (cm.Equals(pointer.Data))
                {
                    containsData = true;
                }
                pointer = pointer.Next;
            }

            return(containsData);
        }
Пример #3
0
        public int IndexOf(object data)
        {
            bool       containsData = false;
            Node       pointer      = Head;
            ClubMember cm           = (ClubMember)data;
            int        index        = 0;

            while (containsData == false && pointer != null)
            {
                if (cm.Equals(pointer.Data))
                {
                    containsData = true;
                }
                pointer = pointer.Next;
                index++;
            }

            return(index - 1);
        }
Пример #4
0
        public int CompareTo(object data)
        {
            int        result = 0;
            ClubMember cm     = (ClubMember)data;

            if (this.Nr > cm.Nr)
            {
                result = 1;
            }
            else if (this.Nr < cm.Nr)
            {
                result = -1;
            }
            else
            {
                result = 0;
            }

            return(result);
        }
Пример #5
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];

            FillArray(smallLinear);
            FillArray(largeLinear);
            FillArray(smallBinary);
            FillArray(largeBinary);

            SearchLinear(smallLinear);
            SearchLinear(largeLinear);

            Console.ReadKey();
        }
Пример #6
0
        public void SortByNumber()
        {
            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);
        }
Пример #7
0
        public void SortByFirstName()
        {
            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 (string.Compare(a.Fname, b.Fname) == 1)
                    {
                        Change(pointer, pointer.Next);
                        swapped = true;
                    }
                    pointer = pointer.Next;
                }
            } while (swapped == true);
        }
Пример #8
0
        private void SearchLinear(IComparable[] arr)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            Random rnd = new Random();

            ClubMember[] cmArr = (ClubMember[])arr;

            ClubMember cm1 = cmArr[rnd.Next(0, arr.Length - 1)];
            ClubMember cm2 = cmArr[rnd.Next(0, arr.Length - 1)];
            ClubMember cm3 = cmArr[rnd.Next(0, arr.Length - 1)];

            int index = 0;

            for (int i = 0; i < 1000; i++)
            {
                index = 0;
                while (cm1.Equals(arr[index]) == false)
                {
                    index++;
                }
                index = 0;
                while (cm2.Equals(arr[index]) == false)
                {
                    index++;
                }
                index = 0;
                while (cm3.Equals(arr[index]) == false)
                {
                    index++;
                }
            }
            sw.Stop();
            Console.WriteLine("Linear Search(" + arr.Length + "): " + sw.Elapsed);
        }