sorting-visualization/SortingVisualization/Program.cs

97 lines
3.6 KiB
C#
Raw Normal View History

using SortingVisualization.Algorithms;
using System;
namespace SortingVisualization {
class Program {
static void Main(string[] args) {
SortingAlgorithm sort;
Console.WriteLine("Select an algorithm:\n\t1. Bubblesort\n\t2. Insertion Sort\n\t3. Selection Sort\n\t4. Quicksort\n\t5. Radixsort\n\t6. Shell Sort\n\t7. Mergesort\n\t8. Heapsort\n\t9. Cocktailshakersort\n\t10. Gravitysort");
string input;
int SetSize = 20;
int selection;
do { input = Console.ReadLine(); }
while (!int.TryParse(input, out selection));
switch (selection) {
case 1:
sort = new Bubblesort();
break;
case 2:
sort = new Insertionsort();
break;
case 3:
sort = new Selectionsort();
break;
case 4:
sort = new Quicksort();
break;
case 5:
sort = new Radixsort();
break;
case 7:
sort = new Mergesort();
break;
case 9:
sort = new Cocktailshakersort();
break;
case 10:
sort = new Gravitysort();
break;
default:
Console.WriteLine("Not Implemented or invalid selection!");
return;
}
Console.WriteLine("Select the set Size:");
do {
input = Console.ReadLine();
} while (!int.TryParse(input, out SetSize));
Console.WriteLine("Select a set:\n\t1. Random\n\t2. Ordered\n\t3. Reversed\n\t4. Single Error");
do { input = Console.ReadLine(); }
while (!int.TryParse(input, out selection));
SetType type;
switch (selection) {
case 1:
type = SetType.Random;
break;
case 2:
type = SetType.Ordererd;
break;
case 3:
type = SetType.Reversed;
break;
case 4:
type = SetType.SingleError;
break;
default:
Console.WriteLine("Not Implemented or invalid selection!");
return;
}
DataSet set;
if (type == SetType.Random || type == SetType.SingleError) {
Console.WriteLine("Do you want to enter a seed? (y/n)");
ConsoleKeyInfo key;
do {
int seed;
key = Console.ReadKey(true);
if (key.Key == ConsoleKey.Y) {
Console.WriteLine("Enter a seed: ");
do {
input = Console.ReadLine();
} while (!int.TryParse(input, out seed));
set = new DataSet(SetSize, type, seed);
break;
}
if (key.Key == ConsoleKey.N) {
Console.WriteLine("Generating with random seed...");
set = new DataSet(SetSize, type);
break;
}
} while (true);
} else {
set = new DataSet(SetSize, type);
}
sort.Sort(ref set);
}
}
}