static void Main(string[] args) { int[] collection = Console.ReadLine().Split().Select(int.Parse).ToArray(); MergeSort <int> .Sort(collection); StringBuilder sb = new StringBuilder(); foreach (var i in collection) { sb.Append(i + " "); } Console.WriteLine(sb); }
static void Main(string[] args) { int[] arr = new int[] { 5, 1, 7, 0, 49, 3, 6, 2, 20, 4 }; //BubbleSort.Sort(arr); //InsertionSort.Sort(arr); //SelectionSort.Sort(arr); //QuickSort.Sort(arr); MergeSort.Sort(arr); Console.WriteLine(String.Join(" ", arr)); Console.ReadLine(); }
public static void Test(int length, int minimumVal, int maximumVal) { MergeSort mSort = new MergeSort(); int[] array = Utilities.GenerateRandomizedArray(length, minimumVal, maximumVal); Stopwatch watch = new Stopwatch(); watch.Start(); int[] sortedArray = mSort.Sort(array); watch.Stop(); TimeSpan mergeSortTime = watch.Elapsed; List<int> comparisonList = array.ToList(); watch.Restart(); comparisonList.Sort(); watch.Stop(); TimeSpan dotNETTime = watch.Elapsed; Console.WriteLine(string.Format("Unsorted: {0}{1}Sorted: {2}{1}Elapsed Time: {3}{1}Compare To: {4}{1}", Utilities.FormatPrintArray(array), Environment.NewLine, Utilities.FormatPrintArray(sortedArray), mergeSortTime.ToString(), dotNETTime.ToString())); }
static void Main(string[] args) { // bubble sort var array = new int[] { 1, 4, 3, 7, 44, 34, 6, 11, 36, 43 }; var sorted = BubbleSort.Sort(array); foreach (int item in sorted) { Console.Write(item.ToString()); } // binary search var myArray = new int[] { 1, 2, 4, 6, 10, 14, 15, 19, 20, 34, 36, 38, 40, 42 }; var value = BinarySearch.BSearch(10, myArray); // merge sort int[] mergeSorted = MergeSort.Sort(array); Console.ReadKey(); }
private static void DoMergeSort() { int[] array = new int[] { 5, 3, 8, 9, 1, 7, 0, 2, 6, 4 }; MergeSort mSort = new MergeSort(); mSort.Sort(array); }
static void Main(string[] args) { Console.WriteLine("Warmup"); var stopwatch = Stopwatch.StartNew(); long seed = Environment.TickCount; // Prevents the JIT Compiler // from optimizing Fkt calls away long result = 0; int count = 100000000; while (stopwatch.ElapsedMilliseconds < 1200) // A Warmup of 1000-1500 mS // stabilizes the CPU cache and pipeline. { result = TestFunction(seed, count); // Warmup } stopwatch.Stop(); int arraySize = 1000000; var runCount = 2; stopwatch.Reset(); stopwatch.Start(); var stringArray = GetStringArray(arraySize); stopwatch.Stop(); Console.WriteLine($"Initializing a {arraySize} elements string array: {stopwatch.ElapsedMilliseconds} ms"); stopwatch.Reset(); stopwatch.Start(); var intArray = GetIntArray(arraySize); stopwatch.Stop(); Console.WriteLine($"Initializing a {arraySize} elements Integer array: {stopwatch.ElapsedMilliseconds} ms"); stopwatch.Reset(); stopwatch.Start(); var stringList = GetStringArrayList(arraySize); stopwatch.Stop(); Console.WriteLine($"Initializing a {arraySize} elements string List: {stopwatch.ElapsedMilliseconds} ms"); var currentCount = 0; Console.WriteLine("-------------------------------------------------------------"); Console.WriteLine("-------------- Integer Bubble Sort ---------------------"); Console.WriteLine("-------------------------------------------------------------"); while (currentCount < runCount) { stopwatch.Reset(); stopwatch.Start(); BubbleSort.Sort(intArray = GetIntArray(arraySize)); stopwatch.Stop(); Console.WriteLine($"Bubble Sorting an Integer array of {arraySize} elements {stopwatch.ElapsedMilliseconds} ms"); //PrintTop10(intArray); currentCount++; } currentCount = 0; Console.WriteLine("-------------------------------------------------------------"); Console.WriteLine("------------ Integer Bubble Sort (Parallel) ----------------"); Console.WriteLine("-------------------------------------------------------------"); while (currentCount < runCount) { stopwatch.Reset(); stopwatch.Start(); BubbleSort.sortParallel(GetIntArray(arraySize)); stopwatch.Stop(); Console.WriteLine($"Bubble Sorting an Integer array of {arraySize} elements {stopwatch.ElapsedMilliseconds} ms"); //PrintTop10(intArray); currentCount++; } currentCount = 0; Console.WriteLine("-------------------------------------------------------------"); Console.WriteLine("-------------- Integer Merge Sort ---------------------"); Console.WriteLine("-------------------------------------------------------------"); while (currentCount < runCount) { stopwatch.Reset(); stopwatch.Start(); MergeSort.Sort(GetIntArray(arraySize)); stopwatch.Stop(); Console.WriteLine($"Merge Sorting an Integer array of {arraySize} elements {stopwatch.ElapsedMilliseconds} ms"); //PrintTop10(intArray); currentCount++; } //currentCount = 0; //Console.WriteLine("-------------------------------------------------------------"); //Console.WriteLine("-------------- String Bubble Sort ---------------------"); //Console.WriteLine("-------------------------------------------------------------"); //while (currentCount < runCount) //{ // stopwatch.Reset(); // stopwatch.Start(); // BubbleSort.Sort(GetStringArray(arraySize)); // stopwatch.Stop(); // Console.WriteLine($"Bubble Sorting a string array of {arraySize} elements {stopwatch.ElapsedMilliseconds} ms"); // //PrintTop10(stringArray); // currentCount++; //} currentCount = 0; Console.WriteLine("-------------------------------------------------------------"); Console.WriteLine("-------------- String Merge Sort ---------------------"); Console.WriteLine("-------------------------------------------------------------"); while (currentCount < runCount) { stopwatch.Reset(); stopwatch.Start(); MergeSort.Sort(GetStringArray(arraySize)); stopwatch.Stop(); Console.WriteLine($"Bubble Sorting a string array of {arraySize} elements {stopwatch.ElapsedMilliseconds} ms"); //PrintTop10(stringArray); currentCount++; } currentCount = 0; Console.WriteLine("-------------------------------------------------------------"); Console.WriteLine("-------------- String List Merge Sort ---------------------"); Console.WriteLine("-------------------------------------------------------------"); while (currentCount < runCount) { stopwatch.Reset(); stopwatch.Start(); MergeSort.Sort(GetStringArrayList(arraySize)); stopwatch.Stop(); Console.WriteLine($"Bubble Sorting a string array of {arraySize} elements {stopwatch.ElapsedMilliseconds} ms"); //PrintTop10(stringArray); currentCount++; } Console.Read(); }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> public static void Main(string[] args) { try { string condition = "null"; ////this loop is used for running the code countineously util the condition is false do { Console.WriteLine("enter 1 for anagram"); Console.WriteLine("enter 2 for primenumbers"); Console.WriteLine("enter 3 for day Of Week"); Console.WriteLine("enter 4 for temperature conversion"); Console.WriteLine("enter 5 for anagram and palindrome of prime numbers"); Console.WriteLine("enter 6 for Vending Machine"); Console.WriteLine("enter 7 for monthly payments"); Console.WriteLine("enter 8 for converting decimal to binary"); Console.WriteLine("enter 9 for Swap nibbles and find the new number"); Console.WriteLine("enter 10 for Search And Sort"); Console.WriteLine("enter 11 for the square root of a nonnegative number"); Console.WriteLine("enter 12 for searching the string in a file"); Console.WriteLine("enter 13 for insertion sort through file"); Console.WriteLine("enter 14 for bubble sort of integers through file"); Console.WriteLine("enter 15 for find your number"); Console.WriteLine("enter 16 for mergesort"); int i = Convert.ToInt32(Console.ReadLine()); switch (i) { case 1: Anagram anagram = new Anagram(); anagram.ToFindAnagram(); break; case 2: PrimeNumbers primeNumbers = new PrimeNumbers(); primeNumbers.FindPrimeNumbers(); break; case 3: WeekOfADay weekOfADay = new WeekOfADay(); weekOfADay.FindingWeekOfADay(); break; case 4: ConversionOfTemperature conversionOfTemperature = new ConversionOfTemperature(); conversionOfTemperature.ConvertingTemperatures(); break; case 5: PalindromeAndAnagramOfPrimeNumbers palindromeAndAnagramOfPrime = new PalindromeAndAnagramOfPrimeNumbers(); palindromeAndAnagramOfPrime.PalindromeOfPrimeNumbers(); palindromeAndAnagramOfPrime.AnagramOfPrimeNumbers(); break; case 6: VendingMachine vendingMachine = new VendingMachine(); vendingMachine.CountingChange(); break; case 7: MonthlyPayments monthlyPayments = new MonthlyPayments(); monthlyPayments.CalculationOfMonthlyPayments(); break; case 8: DecimalToBinary decimalToBinary = new DecimalToBinary(); decimalToBinary.Conversion(); break; case 9: Binary binary = new Binary(); binary.NewNumber(); break; case 10: SearchAndSort searchAndSort = new SearchAndSort(); searchAndSort.SearchAndSortedList(); break; case 11: SqrtOfNonNegativeNumber sqrtOfNonNegative = new SqrtOfNonNegativeNumber(); sqrtOfNonNegative.Sqrt(); break; case 12: BinarySearchThroughFile searchThroughFile = new BinarySearchThroughFile(); searchThroughFile.BinarySearchOfAStringInFile(); break; case 13: InsertionSortThroughFile insertionSortThroughFile = new InsertionSortThroughFile(); insertionSortThroughFile.SortingStringsInFile(); break; case 14: BubbleSortThroughFile bubbleSortThroughFile = new BubbleSortThroughFile(); bubbleSortThroughFile.SortingIntigersInFile(); break; case 15: FindYourNumber findYourNumber = new FindYourNumber(); findYourNumber.GuessNumber(); break; case 16: MergeSort mergeSort = new MergeSort(); Console.WriteLine("enter size of array"); int size = Convert.ToInt32(Console.ReadLine()); string[] words = new string[size]; Console.WriteLine("enter strings in to array"); for (int k = 0; k < size; k++) { words[k] = Console.ReadLine(); } mergeSort.Sort(words); Console.WriteLine("sorted array"); foreach (string sortedArray in words) { Console.WriteLine(sortedArray); } break; } Console.WriteLine("enter yes to execute remaining programs or enter no to stop execution"); condition = Console.ReadLine(); }while (condition == "yes"); } catch (Exception e) { Console.WriteLine(e.Message); } }