public int SequentialSearch(double searchValue) { int foundIndex = -1; for (int i = 0; i < Books.GetCount(); i++) { if (myBooks[i].Equals(searchValue)) { foundIndex = i; } } return(foundIndex); }
// this method just initializes the myBooks array, as well // as the starting book count public Books[] GetAllBooks() { Books[] myBooks = new Books[200]; Books.SetCount(0); StreamReader inFile = new StreamReader(fileName); string[] input = File.ReadAllLines(fileName); foreach (string line in input) { string[] bookInfo = line.Split('#'); myBooks[Books.GetCount()] = new Books(double.Parse(bookInfo[0]), bookInfo[1], bookInfo[2], bookInfo[3], double.Parse(bookInfo[4]), double.Parse(bookInfo[5])); Books.IncCount(); } inFile.Close(); return(myBooks); }
public void SortArray() { for (int i = 0; i < Books.GetCount() - 1; i++) { int minIndex = i; for (int j = i + 1; j < Books.GetCount(); j++) { if (myBooks[minIndex].CompareTo(myBooks[j]) > 0) { minIndex = j; } } if (minIndex != i) { Swap(i, minIndex); } } }