static void Main(String[] args) { var col = GetUnorderedCollection(); Console.WriteLine("排序前集合有序:" + IsSorted(col)); //var sort = new BubbleSort<Int32>(); //var sort = new SelectionSort<Int32>(); var sort = new InsertionSort <Int32>(); sort.Sort(col); Console.WriteLine("排序后集合有序:" + IsSorted(col)); Console.WriteLine("排序结果:"); PrintCollection(col); Console.WriteLine("按下任意键退出..."); Console.ReadKey(); }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> static void Main(string[] args) { Console.WriteLine("1: Anagram Detection"); Console.WriteLine("2: Prime Numbers between 0-1000"); Console.WriteLine("3: Prime Numbers that are Anagram or Palindrome (0-1000)"); Console.WriteLine("4: Utility Class"); Console.WriteLine("5: Find Number"); Console.WriteLine("6: Binary Search"); Console.WriteLine("7: Insertion Sort"); Console.WriteLine("8: Bubble Sort"); Console.WriteLine("9: Merge Sort"); Console.WriteLine("10: Vending Machine"); Console.WriteLine("11: Day of Week"); Console.WriteLine("12: Temperature Conversion"); Console.WriteLine("13: Monthly Payment"); Console.WriteLine("14: Square Root"); Console.WriteLine("15: To Binary"); Console.WriteLine("16: Binary Swap Nibbles"); int choice = 0; while (!(choice > 0 && choice < 17)) { try { Console.Write("Enter your choice: "); choice = Convert.ToInt32(Console.ReadLine()); } catch (FormatException) { //Console.WriteLine(Ex); } } switch (choice) { case 1: AnagramDetection anagramDetection = new AnagramDetection(); anagramDetection.anagram(); break; case 2: PrimeNumbers primeNumbers = new PrimeNumbers(); primeNumbers.prime(); break; case 3: PrimeAnagramPalindrome primeAnagramPalindrome = new PrimeAnagramPalindrome(); primeAnagramPalindrome.checkForPrimeAnagramPalindrome(); break; case 4: int[] integerArray = { 10, 8, 7, 4, 3, 5, 0, 1, 2, 6, 9 }; integerArray = Utility.BubbleSort(integerArray); Console.WriteLine("After Bubble Sort:"); for (int i = 0; i < integerArray.Length; i++) { Console.Write(integerArray[i] + " "); } Console.WriteLine(); int pos1 = Utility.BinarySearch(6, 0, 11, integerArray); if (pos1 == -1) { Console.WriteLine("Not Found!"); } else { Console.WriteLine("Found at location: " + pos1); } Console.WriteLine(); string[] stringArray = { "saad", "fahad", "saba", "zeeshan", "ashhar", "owais" }; stringArray = Utility.BubbleSort(stringArray); Console.WriteLine("After Bubble Sort:"); for (int i = 0; i < stringArray.Length; i++) { Console.Write(stringArray[i] + " "); } int pos2 = Utility.BinarySearch("saad", 0, 11, stringArray); Console.WriteLine(); if (pos2 == -1) { Console.Write("Not Found!"); } else { Console.Write("Found at location: " + pos2); } break; case 5: FindingNumber findingNumber = new FindingNumber(); findingNumber.Find(); break; case 6: BinarySearch search = new BinarySearch(); search.binarySearch(); break; case 7: InsertionSort insertionSort = new InsertionSort(); insertionSort.Sort(); break; case 8: BubbleSort bubbleSort = new BubbleSort(); bubbleSort.Sort(); break; case 9: MergeSort mergeSort = new MergeSort(); mergeSort.Sort(); break; case 10: VendingMachine vendingMachine = new VendingMachine(); vendingMachine.machine(); break; case 11: DayOfWeek dayOfWeek = new DayOfWeek(); dayOfWeek.getDay(); break; case 12: TemperatureConversion conversion = new TemperatureConversion(); conversion.temperatureConversion(); break; case 13: MonthlyPayment monthlyPayment = new MonthlyPayment(); monthlyPayment.payment(); break; case 14: SquareRoot root = new SquareRoot(); root.calculateSquareRoot(); break; case 15: ConvertToBinary convert = new ConvertToBinary(); convert.conversion(); break; case 16: BinarySwapNibbles binarySwapNibbles = new BinarySwapNibbles(); binarySwapNibbles.swapNibbles(); break; default: Console.WriteLine("Wrong Choice!"); break; } }
public static void Main(string[] args) { var items = new int[] { 3, 1, 6, 4, 5, 2 }; var insertionSort = new InsertionSort(); var count = insertionSort.Sort(items); Console.WriteLine(string.Join(",", items)); Console.WriteLine(count); //var bubbleSort = new BubbleSort(); //var count = bubbleSort.OptimizedSort(items); //Console.WriteLine(string.Join(",", items)); //Console.WriteLine(count); //var missing = new HashSet<int>(); //var store = new HashSet<int>(); //int count = 0; //int max = 0; //for (int i = 0; i < a.Length; i++) //{ // max = Math.Max(max, a[i]); // if(max == i + 1) // { // count++; // } //} //for (int i = 0; i < a.Length; i++) //{ // if (!store.Contains(i + 1) && i + 1 != a[i]) // missing.Add(i + 1); // if (i + 1 < a[i]) // store.Add(a[i]); // else // missing.Remove(a[i]); // if (missing.Count() == 0) // count++; //} //WorkPerform del1 = new WorkPerform(WorkPerform1); //WorkPerform del2 = new WorkPerform(WorkPerform2); //del1 += del2; //del1(5, WorkType.GoToMeeting); //Func<int, int, int> func = (x, y) => x * y; //Console.WriteLine(func(2, 3)); //string S = "Sun 10:00-20:00\nFri 05:00-10:00\nFri 16:30-23:50\nSat 10:00-24:00\nSun 01:00-04:00\nSat 02:00-06:00\nTue 03:30-18:15\nTue 19:00-20:00\nWed 04:25-15:14\nWed 15:14-22:40\nThu 00:00-23:59\nMon 05:00-13:00\nMon 15:00-21:00"; //int totalTime = 7 * 24 * 60; //List<string> schedules = S.Split('\n').ToList(); //Dictionary<string, Time> abc = new Dictionary<string, Time>(); //string[] days = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; //List<string> final = new List<string>(); //for (int i = 0; i < days.Count(); i++) //{ // var d = schedules.Where(x => x.Contains(days[i])).ToList(); // List<string> temp = new List<string>(); // for (int j = 0; j < d.Count(); j++) // { // temp.Add(d[j].Substring(4, 11)); // } // temp.Sort(); // final.AddRange(temp); //} //int maxMinutes = 0; //for (int i = 0; i < final.Count - 1; i++) //{ // int startTime; // int endTime; // int time; // if (i == final.Count - 1) // { // startTime = int.Parse(final[i].Substring(6, 2)) * 60 + int.Parse(final[i].Substring(9, 2)); // endTime = int.Parse(final[0].Substring(0, 2)) * 60 + int.Parse(final[0].Substring(3, 2)); // } // else // { // startTime = int.Parse(final[i].Substring(6, 2)) * 60 + int.Parse(final[i].Substring(9, 2)); // endTime = int.Parse(final[i + 1].Substring(0, 2)) * 60 + int.Parse(final[i + 1].Substring(3, 2)); // } // if(endTime < startTime) // { // time = (24 * 60) - startTime + endTime; // } // else // { // time = endTime - startTime; // } // if (maxMinutes < time) // { // maxMinutes = time; // } //} //return maxMinutes; // schedule = schedule //.OrderBy(d => DateTime.ParseExact(d, "dd'/'MM'/'yyyy", CultureInfo.InvariantCulture)) //.ToArray(); // var max_profit = 0; // var min = 200001; // for (var i = 0; i < A.Length; i++) // { // if (min > A[i]) // { // min = A[i]; // } // else // { // max_profit = Math.Max(max_profit, A[i] - min); // } // } // return max_profit; //return dp[A.length - 1]; //return count; //return numSlice; }