Using System Using Systemcollectionsgeneric Using Systemdiagnostics Namespace Simplesort C Q43862441
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace SimpleSort
{
class Sort
{
static voidMain(string[] args)
{
Console.Write(” How manyrandom numbers to you want to sort = “);
string UserInput = Console.ReadLine();
int size = Convert.ToInt32(UserInput);
Random rand = new Random();
int[] arr = new int[size];
Console.WriteLine(“nn Unsorted————“);
//Generate an unsorted array
for (int i = 0; i < size; i++)
{
arr[i] = rand.Next(0, 100);
Console.WriteLine(” ” + arr[i]);
}
Console.WriteLine(“nn Built-InSort————“);
//The built-in “arr.Sort” sorts “in-place”,
//i.e. it destroys the original unsorted arr.
//We need to make a temporary copy of the original.
int[] temp = new int[size];
Array.Copy(arr, temp, size);
Stopwatch s = new Stopwatch(); // start the stopwatch
s.Start();
Array.Sort(temp);
s.Stop(); //stop the Stopwatch and print the elapsedtime
Console.WriteLine(” It took {0} to sort {1}numbersnn”, s.Elapsed, size);
for (int i = 0; i < size; i++) {Console.WriteLine(” ” + temp[i]); }
Console.WriteLine(“nn SelectionSort————“);
SelectSort(arr);
for (int i = 0; i < size; i++) {Console.WriteLine(” ” + arr[i]); }
Console.ReadKey();
}
static voidSelectSort(int[] arr)
{
int min;
int min_index;
int temp;
int size = arr.Length;
Stopwatch s = new Stopwatch(); // start the stopwatch
s.Start();
for (int i = 0; i < size; i++)
{
min = arr[i];
min_index = i;
for (int j = i + 1; j < size; j++)
{
if (arr[j] < min) { min = arr[j]; min_index = j; }
}
// the smallest element smaller than the current head of the list(if there is one)
// is swapped with the current head of list.
if (min_index != i)
{
temp = arr[i];
arr[i] = arr[min_index];
arr[min_index] = temp;
}
}
s.Stop(); //stop the Stopwatch and print the elapsedtime
Console.WriteLine(” It took {0} to sort {1}numbersnn”, s.Elapsed, size);
}
}
}
1. Assignment 1 (50 Points) Use the selection sort program discussed in class (attached) and run it with inputs of length, 25, 50, 75, 100, 150, 200, 250, 300, 350, 400. Record the execution times for our selection sort and the built-in sort. Enter the recorded execution times into Excel and graph. On the same graph also graph n^2, and n*log(n) (using the same values for n (25, 50, 75, 100, 150, 200, 250, 300, 350, 400). 2. Problem 1 (50 points): Ask the user to enter a string (e.g. “Welcome to Saint Martin’s U!”). Your program should count and display the total number of vowels (A, E, I, 0, U) – count both uppercase and lowercase vowels – in that given input. In the example above, the output should 9. [Hint: Convert the string to all upper (or all lower) case to safe having to check ‘A’ or ‘a’ for each vowel respectively.] 3. Problem 2 (50 points): Ask the user to enter a positive integer b. Validate the input (to make sure it is positive). Then output whether or not the number b is divisible by 3. (Hint: Modulus operator] Show transcribed image text 1. Assignment 1 (50 Points) Use the selection sort program discussed in class (attached) and run it with inputs of length, 25, 50, 75, 100, 150, 200, 250, 300, 350, 400. Record the execution times for our selection sort and the built-in sort. Enter the recorded execution times into Excel and graph. On the same graph also graph n^2, and n*log(n) (using the same values for n (25, 50, 75, 100, 150, 200, 250, 300, 350, 400). 2. Problem 1 (50 points): Ask the user to enter a string (e.g. “Welcome to Saint Martin’s U!”). Your program should count and display the total number of vowels (A, E, I, 0, U) – count both uppercase and lowercase vowels – in that given input. In the example above, the output should 9. [Hint: Convert the string to all upper (or all lower) case to safe having to check ‘A’ or ‘a’ for each vowel respectively.] 3. Problem 2 (50 points): Ask the user to enter a positive integer b. Validate the input (to make sure it is positive). Then output whether or not the number b is divisible by 3. (Hint: Modulus operator]
Expert Answer
Answer to using System; using System.Collections.Generic; using System.Diagnostics; namespace SimpleSort { class Sort { static voi…
OR