static void Main(string[] args) { Console.WriteLine("CMP1124M - Algorithms and Complexity - Assignment 2 - CRO15592084"); Console.WriteLine("Which Array or String Array would you like to analyse?"); int selection = 0; Console.WriteLine("[1] Year_1.txt"); Console.WriteLine("[2] Month_1.txt"); Console.WriteLine("[3] Day_1.txt"); Console.WriteLine("[4] Time_1.txt"); Console.WriteLine("[5] Magnitude_1.txt"); Console.WriteLine("[6] Latitude_1.txt"); Console.WriteLine("[7] Longitude_1.txt"); Console.WriteLine("[8] Depth_1.txt"); Console.WriteLine("[9] Region_1.txt"); Console.WriteLine("[10] IRIS_ID_1.txt"); Console.WriteLine("[11] Timestamp_1.txt"); selection = Convert.ToInt32(Console.ReadLine()); int count = 0; switch (selection) { case 1: int[] year1 = new int[600]; foreach (string line in File.ReadAllLines("Year_1.txt")) { int temp = Convert.ToInt32(line); year1[count] = temp; count++; } SortingTools.InsertionSort(year1); break; case 2: string[] month1 = new string[600]; break; case 3: int[] day1 = new int[600]; foreach (string line in File.ReadAllLines("Day_1.txt")) { int temp = Convert.ToInt32(line); day1[count] = temp; count++; } SortingTools.InsertionSort(day1); break; case 4: string[] time1 = new string[600]; foreach (string line in File.ReadAllLines("time_1.txt")) { string temp = line; time1[count] = temp; count++; } SortingTools.BubbleSort(time1); break; case 5: float[] magnitude1 = new float[600]; foreach (string line in File.ReadAllLines("Magnitude_1.txt")) { string temp = line; magnitude1[count] = Convert.ToSingle(temp); count++; } SortingTools. break; case 6: float[] latitude1 = new float[600]; break; case 7: float[] longitude1 = new float[600]; break; case 8: float[] depth1 = new float[600]; break; case 9: string[] region1 = new string[600]; foreach (string line in File.ReadAllLines("Region_1.txt")) { string temp = line; region1[count] = temp; count++; } SortingTools.BubbleSort(region1); break; case 10: int[] iris1 = new int[600]; foreach (string line in File.ReadAllLines("IRIS_ID_1.txt")) { int temp = Convert.ToInt32(line); iris1[count] = temp; count++; } SortingTools.InsertionSort(iris1); break; case 11: int[] timestamp1 = new int[600]; break; default: Console.WriteLine("Invalid input, please try again."); break; } }
public static void Main(string[] args) { Console.Clear(); Console.WriteLine("CMP1124M - Algorithms and Complexity - Assignment 2 - CRO15592084"); Console.WriteLine("Select a file to analyse."); Console.WriteLine("[1] Year_1.txt"); Console.WriteLine("[2] Month_1.txt"); Console.WriteLine("[3] Day_1.txt"); Console.WriteLine("[4] Time_1.txt"); Console.WriteLine("[5] Magnitude_1.txt"); Console.WriteLine("[6] Latitude_1.txt"); Console.WriteLine("[7] Longitude_1.txt"); Console.WriteLine("[8] Depth_1.txt"); Console.WriteLine("[9] Region_1.txt"); Console.WriteLine("[10] IRIS_ID_1.txt"); Console.WriteLine("[11] Timestamp_1.txt"); int selection1 = 0; selection1 = Convert.ToInt32(Console.ReadLine()); int selection2 = 0; int count = 0; int searchInt = 0; float searchF = 0.0f; string searchStr = ""; foreach (string line in File.ReadAllLines("Year_1.txt")) { int temp = Convert.ToInt32(line); year1[count] = temp; count++; } count = 0; foreach (string line in File.ReadAllLines("Month_1.txt")) { string temp = line.Trim(); month1[count] = temp; count++; } count = 0; foreach (string line in File.ReadAllLines("Day_1.txt")) { int temp = Convert.ToInt32(line); day1[count] = temp; count++; } count = 0; foreach (string line in File.ReadAllLines("Time_1.txt")) { string temp = line; time1[count] = temp; count++; } count = 0; foreach (string line in File.ReadAllLines("Magnitude_1.txt")) { string temp = line; magnitude1[count] = Convert.ToSingle(temp); count++; } count = 0; foreach (string line in File.ReadAllLines("Latitude_1.txt")) { string temp = line; latitude1[count] = Convert.ToSingle(temp); count++; } count = 0; foreach (string line in File.ReadAllLines("Longitude_1.txt")) { string temp = line; longitude1[count] = Convert.ToSingle(temp); count++; } count = 0; foreach (string line in File.ReadAllLines("Depth_1.txt")) { string temp = line; depth1[count] = Convert.ToSingle(temp); count++; } count = 0; foreach (string line in File.ReadAllLines("Region_1.txt")) { string temp = line; region1[count] = temp; count++; } count = 0; foreach (string line in File.ReadAllLines("IRIS_ID_1.txt")) { int temp = Convert.ToInt32(line); iris1[count] = temp; count++; } count = 0; foreach (string line in File.ReadAllLines("Timestamp_1.txt")) { string temp = line; timestamp1[count] = Convert.ToInt32(temp); count++; } count = 0; switch (selection1) { case 1: Console.WriteLine("Would you like to search[1], sort [2], show highest and lowest values[3], or quit[4]?"); selection2 = Convert.ToInt32(Console.ReadLine()); switch (selection2) { case 1: Console.WriteLine("What would you like to search for in this array?"); searchInt = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Searching for {0}", searchInt); SearchTools.LinearSearch(year1, searchInt); Console.ReadKey(); break; case 2: Console.WriteLine("Sorting array, press any key to continue..."); Console.ReadKey(); SortingTools.InsertionSort(year1); Console.WriteLine("Press any key to display sorted array content:"); Console.ReadKey(); for (int i = 0; i < year1.Length; i++) { Console.WriteLine(year1[i]); } Console.ReadKey(); break; case 3: int min = year1.Min(); searchInt = year1[0]; Console.WriteLine("Searching for minimum value and all instances in the array."); SearchTools.LinearSearch(year1, searchInt); Console.ReadKey(); int max = year1.Max(); searchInt = max; Console.WriteLine("Searching for maximum value and all instances in the array."); SearchTools.LinearSearch(year1, searchInt); Console.ReadKey(); break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Invalid input, please try again."); break; } break; case 2: Console.WriteLine("Would you like to search[1], sort [2], show highest and lowest values[3], or quit[4]?"); selection2 = Convert.ToInt32(Console.ReadLine()); switch (selection2) { case 1: Console.WriteLine("What would you like to search for in this array?"); searchStr = Console.ReadLine(); Console.WriteLine("Searching for {0}", searchStr); SearchTools.MonthSearch(month1, searchStr); Console.ReadKey(); break; case 2: Console.WriteLine("Sorting array, press any key to continue..."); Console.ReadKey(); SortingTools.MonthSort(month1); Console.ReadKey(); break; case 3: searchStr = "January"; Console.WriteLine("Searching for minimum value and all instances in the array."); SearchTools.LinearSearch(month1, searchStr); Console.ReadKey(); searchStr = "December"; Console.WriteLine("Searching for maximum value and all instances in the array."); SearchTools.LinearSearch(month1, searchStr); Console.ReadKey(); break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Invalid input, please try again."); break; } break; case 3: Console.WriteLine("Would you like to search[1], sort [2], show highest and lowest values[3], or quit[4]?"); selection2 = Convert.ToInt32(Console.ReadLine()); switch (selection2) { case 1: Console.WriteLine("What would you like to search for in this array?"); searchInt = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Searching for {0}", searchInt); SearchTools.LinearSearch(day1, searchInt); Console.ReadKey(); break; case 2: Console.WriteLine("Sorting array, press any key to continue..."); Console.ReadKey(); SortingTools.InsertionSort(day1); Console.WriteLine("Press any key to display sorted array content:"); Console.ReadKey(); for (int i = 0; i < day1.Length; i++) { Console.WriteLine(day1[i]); } Console.ReadKey(); break; case 3: int min = day1.Min(); searchInt = min; Console.WriteLine("Searching for minimum value and all instances in the array."); SearchTools.LinearSearch(day1, searchInt); Console.ReadKey(); int max = day1.Max(); searchInt = max; Console.WriteLine("Searching for maximum value and all instances in the array."); SearchTools.LinearSearch(day1, searchInt); Console.ReadKey(); break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Invalid input, please try again."); break; } break; case 4: Console.WriteLine("Would you like to search[1], sort [2], show highest and lowest values[3], or quit[4]?"); selection2 = Convert.ToInt32(Console.ReadLine()); switch (selection2) { case 1: Console.WriteLine("What would you like to search for in this array?"); searchStr = Console.ReadLine(); Console.WriteLine("Searching for {0}", searchStr); SearchTools.LinearSearch(time1, searchStr); Console.ReadKey(); break; case 2: Console.WriteLine("Sorting array, press any key to continue..."); Console.ReadKey(); SortingTools.BubbleSort(time1); Console.ReadKey(); for (int i = 0; i < time1.Length; i++) { Console.WriteLine(time1[i]); } Console.ReadKey(); break; case 3: SortingTools.BubbleSort(time1); searchStr = time1[0]; Console.WriteLine("Searching for minimum value and all instances in the array."); SearchTools.LinearSearch(time1, searchStr); Console.ReadKey(); searchStr = time1[599]; Console.WriteLine("Searching for maximum value and all instances in the array."); SearchTools.LinearSearch(time1, searchStr); Console.ReadKey(); break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Invalid input, please try again."); break; } break; case 5: Console.WriteLine("Would you like to search[1], sort [2], show highest and lowest values[3], or quit[4]?"); selection2 = Convert.ToInt32(Console.ReadLine()); switch (selection2) { case 1: SortingTools.InsertionSort(magnitude1); Console.WriteLine("What would you like to search for in this array?"); searchF = Convert.ToSingle(Console.ReadLine()); Console.WriteLine("Searching for {0}", searchF); SearchTools.BinarySearch(magnitude1, searchF); Console.ReadKey(); break; case 2: Console.WriteLine("Sorting array, press any key to continue..."); Console.ReadKey(); SortingTools.InsertionSort(magnitude1); Console.WriteLine("Press any key to display sorted array content:"); Console.ReadKey(); for (int i = 0; i < magnitude1.Length; i++) { Console.WriteLine(magnitude1[i]); } Console.ReadKey(); break; case 3: SortingTools.InsertionSort(magnitude1); searchF = magnitude1[0]; Console.WriteLine("Searching for minimum value and all instances in the array."); SearchTools.BinarySearch(magnitude1, searchInt); Console.ReadKey(); searchF = magnitude1[599]; Console.WriteLine("Searching for maximum value and all instances in the array."); SearchTools.BinarySearch(magnitude1, searchInt); Console.ReadKey(); break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Invalid input, please try again."); break; } break; case 6: Console.WriteLine("Would you like to search[1], sort [2], show highest and lowest values[3], or quit[4]?"); selection2 = Convert.ToInt32(Console.ReadLine()); switch (selection2) { case 1: Console.WriteLine("What would you like to search for in this array?"); searchF = Convert.ToSingle(Console.ReadLine()); Console.WriteLine("Searching for {0}", searchF); SearchTools.BinarySearch(latitude1, searchF); Console.ReadKey(); break; case 2: Console.WriteLine("Sorting array, press any key to continue..."); Console.ReadKey(); SortingTools.InsertionSort(latitude1); Console.WriteLine("Press any key to display sorted array content:"); Console.ReadKey(); for (int i = 0; i < latitude1.Length; i++) { Console.WriteLine(latitude1[i]); } Console.ReadKey(); break; case 3: SortingTools.InsertionSort(latitude1); searchF = latitude1[0]; Console.WriteLine("Searching for minimum value and all instances in the array."); SearchTools.BinarySearch(latitude1, searchF); Console.ReadKey(); searchF = latitude1[599]; Console.WriteLine("Searching for maximum value and all instances in the array."); SearchTools.BinarySearch(latitude1, searchF); Console.ReadKey(); break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Invalid input, please try again."); break; } break; case 7: Console.WriteLine("Would you like to search[1], sort [2], show highest and lowest values[3], or quit[4]?"); selection2 = Convert.ToInt32(Console.ReadLine()); switch (selection2) { case 1: Console.WriteLine("What would you like to search for in this array?"); searchF = Convert.ToSingle(Console.ReadLine()); Console.WriteLine("Searching for {0}", searchF); SearchTools.BinarySearch(longitude1, searchF); Console.ReadKey(); break; case 2: Console.WriteLine("Sorting array, press any key to continue..."); Console.ReadKey(); SortingTools.InsertionSort(longitude1); Console.WriteLine("Press any key to display sorted array content:"); Console.ReadKey(); for (int i = 0; i < longitude1.Length; i++) { Console.WriteLine(longitude1[i]); } Console.ReadKey(); break; case 3: SortingTools.InsertionSort(longitude1); searchF = longitude1[0]; Console.WriteLine("Searching for minimum value and all instances in the array."); SearchTools.BinarySearch(longitude1, searchF); Console.ReadKey(); searchF = longitude1[599]; Console.WriteLine("Searching for maximum value and all instances in the array."); SearchTools.BinarySearch(longitude1, searchF); Console.ReadKey(); break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Invalid input, please try again."); break; } break; case 8: Console.WriteLine("Would you like to search[1], sort [2], show highest and lowest values[3], or quit[4]?"); selection2 = Convert.ToInt32(Console.ReadLine()); switch (selection2) { case 1: Console.WriteLine("What would you like to search for in this array?"); searchF = Convert.ToSingle(Console.ReadLine()); Console.WriteLine("Searching for {0}", searchF); SearchTools.BinarySearch(depth1, searchF); Console.ReadKey(); break; case 2: Console.WriteLine("Sorting array, press any key to continue..."); Console.ReadKey(); SortingTools.InsertionSort(depth1); Console.WriteLine("Press any key to display sorted array content:"); Console.ReadKey(); for (int i = 0; i < depth1.Length; i++) { Console.WriteLine(depth1[i]); } Console.ReadKey(); break; case 3: SortingTools.InsertionSort(depth1); searchF = depth1[0]; Console.WriteLine("Searching for minimum value and all instances in the array."); SearchTools.BinarySearch(depth1, searchF); Console.ReadKey(); searchF = depth1[599]; Console.WriteLine("Searching for maximum value and all instances in the array."); SearchTools.BinarySearch(depth1, searchF); Console.ReadKey(); break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Invalid input, please try again."); break; } break; case 9: Console.WriteLine("Would you like to search[1], sort [2], show highest and lowest values[3], or quit[4]?"); selection2 = Convert.ToInt32(Console.ReadLine()); switch (selection2) { case 1: Console.WriteLine("What would you like to search for in this array?"); searchStr = Console.ReadLine().ToUpper(); Console.WriteLine("Searching for {0}", searchStr); SearchTools.LinearSearch(region1, searchStr); Console.ReadKey(); break; case 2: Console.WriteLine("Sorting array, press any key to continue..."); Console.ReadKey(); SortingTools.BubbleSort(region1); Console.ReadKey(); for (int i = 0; i < region1.Length; i++) { Console.WriteLine(region1[i]); } Console.ReadKey(); break; case 3: SortingTools.BubbleSort(region1); searchStr = region1[0]; Console.WriteLine("Searching for minimum value and all instances in the array."); SearchTools.LinearSearch(region1, searchStr); Console.ReadKey(); searchStr = region1[599]; Console.WriteLine("Searching for maximum value and all instances in the array."); SearchTools.LinearSearch(region1, searchStr); Console.ReadKey(); break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Invalid input, please try again."); break; } break; case 10: Console.WriteLine("Would you like to search[1], sort [2], show highest and lowest values[3], or quit[4]?"); selection2 = Convert.ToInt32(Console.ReadLine()); switch (selection2) { case 1: Console.WriteLine("What would you like to search for in this array?"); searchInt = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Searching for {0}", searchInt); SearchTools.BinarySearch(iris1, searchInt); Console.ReadKey(); break; case 2: Console.WriteLine("Sorting array, press any key to continue..."); Console.ReadKey(); SortingTools.InsertionSort(iris1); Console.WriteLine("Press any key to display sorted array content:"); Console.ReadKey(); for (int i = 0; i < iris1.Length; i++) { Console.WriteLine(iris1[i]); } Console.ReadKey(); break; case 3: SortingTools.InsertionSort(iris1); searchInt = iris1[0]; Console.WriteLine("Searching for minimum value and all instances in the array."); SearchTools.BinarySearch(iris1, searchInt); Console.ReadKey(); searchInt = iris1[599]; Console.WriteLine("Searching for maximum value and all instances in the array."); SearchTools.BinarySearch(iris1, searchInt); Console.ReadKey(); break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Invalid input, please try again."); break; } break; case 11: Console.WriteLine("Would you like to search[1], sort [2], show highest and lowest values[3], or quit[4]?"); selection2 = Convert.ToInt32(Console.ReadLine()); switch (selection2) { case 1: Console.WriteLine("What would you like to search for in this array?"); searchInt = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Searching for {0}", searchInt); SearchTools.BinarySearch(timestamp1, searchInt); Console.ReadKey(); break; case 2: Console.WriteLine("Sorting array, press any key to continue..."); Console.ReadKey(); SortingTools.InsertionSort(timestamp1); Console.WriteLine("Press any key to display sorted array content:"); Console.ReadKey(); for (int i = 0; i < timestamp1.Length; i++) { Console.WriteLine(timestamp1[i]); } Console.ReadKey(); break; case 3: SortingTools.BubbleSort(day1); searchInt = timestamp1[0]; Console.WriteLine("Searching for minimum value and all instances in the array."); SearchTools.LinearSearch(timestamp1, searchInt); Console.ReadKey(); searchInt = timestamp1[599]; Console.WriteLine("Searching for maximum value and all instances in the array."); SearchTools.BinarySearch(timestamp1, searchInt); Console.ReadKey(); break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Invalid input, please try again."); break; } break; default: Console.WriteLine("Invalid input, please try again."); break; } }