/// <summary> /// To join the current instance of Record collection to another instance /// </summary> /// <param name="target">Target array you wish to combine with the source</param> public void JoinArrays(RecordCollection target) { //loops through each record in the target and adds it to the current records. for (int i = 0; i < target.Records.currentCapacity; i++) { Records.AddRecord(target.Records[i]); } SortAlgorithms.HeapSort(this, c => c.Timestamp); }
/// <summary> /// The operation menu contains all the operations that you can perform on a given field /// </summary> /// <typeparam name="T">To reduce redundancy, I've specified a generic type method to ensure properties of the SesmicRecord /// such as int, double, TimeSpan are inferred by the compiler</typeparam> /// <param name="region">region data to operate on</param> /// <param name="propertyField">A selected property (column) to perform the required operations on</param> static private void OperationMenu <T>(RecordCollection region, Func <SeismicRecord, T> propertyField) where T : IComparable { int userInput; do { Console.WriteLine("Which of the following you want to perform?" + "\n1)Heap Sort and display corresponding values" + "\n2)Binary Search by a field" + "\n3)Find Max and minimum value" + "\n4)Go back!"); userInput = short.Parse(Console.ReadLine()); //paramName; a name of currently passed propertField parameter i.e. month => month.Month is month string paramName = propertyField.Method.GetParameters()[0].Name; switch (userInput) { case 1: //sort in the chosen order Console.WriteLine("1)Ascending" + "\n2)Descending"); int sortInput = short.Parse(Console.ReadLine()); switch (sortInput) { //sets the region's desired sort order before sorting case 1: region.SortOrder = true; break; case 2: region.SortOrder = false; break; default: Console.WriteLine("No such sorting option exists!"); break; } //when order is set, sort the region records by the property SortAlgorithms.HeapSort(region, propertyField); region.Records.ListRecords(); //list the records when it's sorted Console.WriteLine("There are currently: {0} records\n", region.Records.currentCapacity); break; case 2: //how the found records to be displayed Console.WriteLine("1)Display corresponding values" + "\n2)Display only selected field"); int searchInput = short.Parse(Console.ReadLine()); switch (searchInput) { //sets the decision on how to display the records case 1: region.CorrespondingFields = true; break; case 2: region.CorrespondingFields = false; break; default: Console.WriteLine("No such sorting option exists!"); break; } Console.WriteLine($"Enter your search value for {paramName}:"); region.SortOrder = true; SortAlgorithms.HeapSort(region, propertyField); //calls a generic method for the users input TypeSafeSearch(region, propertyField); break; case 3: //the static method for finding minimum maximum for current field MinMax.FindMinMax(ref region, propertyField); break; case 4: break; default: Console.WriteLine("Such operation doesn't exist!"); break; } } while (userInput != 4); //loops until the input is a correct case or intention to quit }