static void SearchHashADT(HashADT hash) { Random rnd = new Random(); ClubMember[] clubmemberstofind = new ClubMember[] { CMFactory.GetClubMember(), CMFactory.GetClubMember(), CMFactory.GetClubMember() }; for (int i = 0; i < 1000; i++) { foreach (var item in clubmemberstofind) { if (hash.IndexInUse(hash.GetIndex(item)) == false) { return; } hash.GetElement(hash.Search(item)); } } }
static void Main(string[] args) { #region Setup 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]; BinarySearchTree <ClubMember> SmallCmTree = new BinarySearchTree <ClubMember>(); BinarySearchTree <ClubMember> LargeCmTree = new BinarySearchTree <ClubMember>(); HashADT smallHashADT = new HashADT(smallSize); HashADT largeHashADT = new HashADT(largeSize); for (int i = 0; i < smallSize; i++) { smallLinear[i] = CMFactory.GetClubMember(); smallBinary[i] = CMFactory.GetClubMember(); SmallCmTree.Insert(CMFactory.GetClubMember()); smallHashADT.Insert(CMFactory.GetClubMember()); } for (int i = 0; i < largeSize; i++) { largeLinear[i] = CMFactory.GetClubMember(); largeBinary[i] = CMFactory.GetClubMember(); LargeCmTree.Insert(CMFactory.GetClubMember()); largeHashADT.Insert(CMFactory.GetClubMember()); } #endregion System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); #region Linear search Console.WriteLine("Linear Searching:"); Console.WriteLine("Searching small array:"); SearchLinear(smallLinear); Console.WriteLine(sw.Elapsed); Console.WriteLine("Searching large array:"); sw.Restart(); SearchLinear(largeLinear); Console.WriteLine(sw.Elapsed); #endregion #region Binary Search Console.WriteLine(); Console.WriteLine("Sorting small array:"); sw.Restart(); InsertionSort(smallBinary); Console.WriteLine(sw.Elapsed); Console.WriteLine(); Console.WriteLine("Searching small binary"); sw.Restart(); SearchBinary(smallBinary); Console.WriteLine(sw.Elapsed); Console.WriteLine(); Console.WriteLine("Sorting large array:"); sw.Restart(); InsertionSort(largeBinary); Console.WriteLine(sw.Elapsed); Console.WriteLine(); Console.WriteLine("Searching large binary"); sw.Restart(); SearchBinary(largeBinary); Console.WriteLine(sw.Elapsed); #endregion #region Binary Search Tree Console.WriteLine(); Console.WriteLine("Searching small binary tree"); sw.Restart(); SearchBST(SmallCmTree); Console.WriteLine(sw.Elapsed); Console.WriteLine(); Console.WriteLine("Searching large binary tree"); sw.Restart(); SearchBST(LargeCmTree); Console.WriteLine(sw.Elapsed); #endregion #region HashADTs Console.WriteLine("HashADT"); Console.WriteLine("Searching small Hash ADT"); sw.Restart(); SearchHashADT(smallHashADT); Console.WriteLine(sw.Elapsed); Console.WriteLine(); Console.WriteLine("Searching large Hash ADT"); sw.Restart(); SearchHashADT(largeHashADT); Console.WriteLine(sw.Elapsed); #endregion sw.Stop(); Console.ReadKey(); }