Esempio n. 1
0
        public void SearchLinear(IComparable[] arr)
        {
            Stopwatch sw = new Stopwatch();

            sw.Restart();
            Random rnd = new Random();

            int        random = rnd.Next(0, arr.Length - 1);
            ClubMember cm1    = (ClubMember)arr[random];

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

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

            bool foundTheData = false;
            int  index        = 0;

            for (int i = 0; i < 1000; i++)
            {
                while (foundTheData == false)
                {
                    ClubMember cm = (ClubMember)arr[index];
                    if (cm.Equals(cm1))
                    {
                        foundTheData = true;
                    }
                    index++;
                }

                index        = 0;
                foundTheData = false;

                while (foundTheData == false)
                {
                    ClubMember cm = (ClubMember)arr[index];
                    if (cm.Equals(cm2))
                    {
                        foundTheData = true;
                    }
                    index++;
                }

                index        = 0;
                foundTheData = false;
                while (foundTheData == false)
                {
                    ClubMember cm = (ClubMember)arr[index];
                    if (cm.Equals(cm3))
                    {
                        foundTheData = true;
                    }
                    index++;
                }
                index        = 0;
                foundTheData = false;
            }
            Console.WriteLine("Linear stopwatch(" + arr.Length + ") " + sw.Elapsed);
        }
Esempio n. 2
0
        public bool Search(object data)
        {
            Node pointer = root;

            ClubMember cm        = (ClubMember)data;
            ClubMember pointerCm = (ClubMember)pointer.Data;
            string     cmFnLn    = cm.Fname + cm.Lname;

            bool foundTheData = false;

            while (foundTheData == false && pointer != null)
            {
                pointerCm = (ClubMember)pointer.Data;
                string pointerFnLn = pointerCm.Fname + pointerCm.Lname;

                if (cm.Equals(pointerCm))
                {
                    foundTheData = true;
                }
                else
                {
                    if (string.Compare(cmFnLn, pointerFnLn) == 1)
                    {
                        pointer = pointer.Right;
                    }
                    else
                    {
                        pointer = pointer.Left;
                    }
                }
            }

            return(foundTheData);
        }
Esempio n. 3
0
        public int IndexOf(object data)
        {
            ClubMember cm           = (ClubMember)data;
            int        counter      = 0;
            bool       foundTheData = false;
            Node       pointer      = Head;

            while (pointer != null && foundTheData == false)
            {
                foundTheData = cm.Equals(pointer.Data);

                pointer = pointer.Next;
                counter++;
            }

            return(counter - 1);
        }
Esempio n. 4
0
        public bool Contains(object data)
        {
            ClubMember cm = (ClubMember)data;

            bool foundTheData = false;
            Node pointer      = Head;

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

            return(foundTheData);
        }