Skip to content
Snippets Groups Projects
Commit 82474d84 authored by Tobias Eisenberger's avatar Tobias Eisenberger
Browse files

Bedienprogramm

parent 7606cd0d
No related branches found
No related tags found
No related merge requests found
......@@ -5,3 +5,4 @@
/.vs/Dictionaries
/Dictionaries/bin/Debug/netcoreapp3.1
/Dictionaries/obj
/.vs
using Dictionaries.Test.src.Core;
using System;
using Dictionaries.src.Array;
using Dictionaries.src.LinkedList;
using Dictionaries.src.BinaryTree;
using Dictionaries.src.HashTable;
using Dictionaries.src.Factory;
using Dictionaries.Test.src.Core;
using ArrayTestCase = Dictionaries.Test.src.Array.TestCase;
namespace Dictionaries.src
{
enum DictionaryType
{
Array,
LinkedList,
BinaryTree,
HashTable
}
enum DictionaryAction
{
insert,
search,
delete,
print
}
class Program
{
static DictionaryType[] typeList = (DictionaryType[])Enum.GetValues(typeof(DictionaryType));
const int SHUT_DOWN = 4;
static void Main(string[] args)
{
int type;
IDictionary dictionary;
do
{
Console.Clear();
printDictionaryTypeMenu();
type = requestTypeSelection();
if (type != SHUT_DOWN)
{
string dictionarySelection = requestDictionarySelection((DictionaryType)type);
if (dictionarySelection != "")
{
dictionary = createDictionary(dictionarySelection, (DictionaryType)type);
run(dictionary);
}
}
} while (type != SHUT_DOWN);
Tester tester = new Tester();
tester.run(new ArrayTestCase.MultiSetUnsorted());
tester.run(new ArrayTestCase.SetUnsorted());
......@@ -32,5 +79,140 @@ namespace Dictionaries.src
bt.delete(69);
}
private static void printDictionaryTypeMenu()
{
Console.WriteLine("Dictionary wählen:");
foreach (int i in typeList)
{
Console.WriteLine($"{i} - {(DictionaryType)i}");
}
Console.WriteLine($"{SHUT_DOWN} - Beenden");
}
private static int requestTypeSelection()
{
int type;
do
{
Console.Write("Auswahl: ");
type = int.Parse(Console.ReadLine());
} while (!Enum.IsDefined(typeof(DictionaryType), type) && type != SHUT_DOWN);
return type;
}
private static string requestDictionarySelection(DictionaryType type)
{
Console.WriteLine($"{Environment.NewLine}Konkrete Implementierung von {type} wählen:");
string[] dictionaries = null;
switch (type)
{
case DictionaryType.Array:
dictionaries = new string[] {
typeof(MultiSetSortedArray).AssemblyQualifiedName,
typeof(MultiSetUnsortedArray).AssemblyQualifiedName,
typeof(SetSortedArray).AssemblyQualifiedName,
typeof(SetUnsortedArray).AssemblyQualifiedName };
break;
case DictionaryType.LinkedList:
dictionaries = new string[] {
typeof(MultiSetSortedLinkedList).AssemblyQualifiedName,
typeof(MultiSetUnsortedLinkedList).AssemblyQualifiedName,
typeof(SetSortedLinkedList).AssemblyQualifiedName,
typeof(SetUnsortedLinkedList).AssemblyQualifiedName };
break;
case DictionaryType.BinaryTree:
dictionaries = new string[] {
typeof(BinSearchTree).AssemblyQualifiedName,
typeof(AVLTree).AssemblyQualifiedName,
typeof(Treap).AssemblyQualifiedName };
break;
case DictionaryType.HashTable:
dictionaries = new string[] {
typeof(HashTabSepChain).AssemblyQualifiedName,
typeof(HashTabQuadProb).AssemblyQualifiedName };
break;
}
for (int i = 0; i < dictionaries.Length; i++)
{
string dictionaryFQN = dictionaries[i].Split(',')[0];
string[] dictionaryName = dictionaryFQN.Split('.');
Console.WriteLine($"{i} - {dictionaryName[dictionaryName.Length-1]}");
}
Console.WriteLine($"{dictionaries.Length} - Zurück");
int dictionarySelection;
do
{
Console.Write("Auswahl: ");
dictionarySelection = int.Parse(Console.ReadLine());
} while (dictionarySelection < 0 || dictionarySelection > dictionaries.Length);
return dictionarySelection == dictionaries.Length ? "" : dictionaries[dictionarySelection];
}
private static IDictionary createDictionary(string className, DictionaryType type)
{
DictionaryFactory factory;
if (type == DictionaryType.Array)
{
factory = new ArrayFactory(className);
}
else
{
factory = new DictionaryFactory(className);
}
return factory.createObject();
}
private static void run(IDictionary dictionary)
{
int action;
do
{
Console.Write(Environment.NewLine);
foreach (int i in Enum.GetValues(typeof(DictionaryAction)))
{
Console.WriteLine($"{i} - {(DictionaryAction)i}");
}
Console.WriteLine("4 - Zurück");
Console.Write("Auswahl: ");
action = int.Parse(Console.ReadLine());
bool wasSuccessful = false;
switch (action)
{
case (int)DictionaryAction.insert:
wasSuccessful = dictionary.insert(requestElement());
break;
case (int)DictionaryAction.search:
wasSuccessful = dictionary.search(requestElement());
break;
case (int)DictionaryAction.delete:
wasSuccessful = dictionary.delete(requestElement());
break;
case (int)DictionaryAction.print:
Console.Write("Ausgabe: ");
dictionary.print();
break;
}
if ((DictionaryAction)action != DictionaryAction.print)
{
Console.WriteLine("Ergebnis: {0}", wasSuccessful ? "Erfolgreich" : "Fehlgeschlagen");
}
} while (action != 4);
}
private static int requestElement()
{
Console.Write("Eingabe: ");
int element = int.Parse(Console.ReadLine());
return element;
}
}
}
using System;
namespace Dictionaries.src.Factory
{
class ArrayFactory : DictionaryFactory
{
public ArrayFactory(string className) : base(className) { }
public override IDictionary createObject()
{
buildDependencies();
return base.createObject();
}
private void buildDependencies()
{
int size;
do
{
Console.Write($"Größe angeben: ");
size = int.Parse(Console.ReadLine());
} while (size < 1);
constructorParams = new object[] { size };
}
}
}
using System;
namespace Dictionaries.src.Factory
{
class DictionaryFactory
{
protected string className;
protected object[] constructorParams;
public DictionaryFactory (string className)
{
this.className = className;
}
public virtual IDictionary createObject()
{
return (IDictionary)Activator.CreateInstance(Type.GetType(className), constructorParams);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment