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); }
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); }
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); }
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); }
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(); }
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); }
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); }
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); }