static void Main(string[] args) { Person wesley = new Person() { FirstName = "Wesley", LastName = "van Schaijk", Age = 21 }; Person jimmy = new Person() { FirstName = "Jimmy", LastName = "Kijas", Age = 18 }; HashTable <string, Person> students = new HashTable <string, Person>(2); students.Insert("0925379", wesley); students.Insert("0940590", jimmy); Console.WriteLine(students.Get("0925379")); students.print(); students.Remove("0925379"); students.print(); }
/// <summary> /// Default constructor run the actual test. /// </summary> public ExerciseB() { var dictionary = new HashTable <string, string>(); // Print PrintOptions(); while (true) { string input = Console.ReadLine().Replace(".", ""); switch (input) { case "1": // Change/Put new translation in the HashTable. Console.Write("\tEnter the word: "); string key = Console.ReadLine().Trim(); Console.Write("\tEnter the translation: "); string value = Console.ReadLine().Trim(); dictionary.Put(key, value); break; case "2": // Translate word by word Console.WriteLine("\tPlease enter a sentence you want to translate:"); string[] toTranslate = Console.ReadLine().Trim().Split(' ', '.', '!', '?'); Console.Write("\t=> "); foreach (string word in toTranslate) { string translation = dictionary.Get(word); Console.Write((translation == default(string) ? word : translation) + " "); } Console.WriteLine(); break; case "3": return; default: continue; } Console.WriteLine("Press enter to continue."); Console.ReadLine(); Console.Clear(); PrintOptions(); } }
static void Main(string[] args) { HashTable ht = new HashTable(); ht.Put(1, "a"); ht.Put(2, "b"); ht.Put(4, "c"); ht.Put(5, "d"); ht.Put(6, "e"); ht.Put(7, "f"); Console.WriteLine(ht.Get(4)); ht.Remove(5); ht.Remove(10); }
/// <summary> /// Default constructor run the actual test. /// </summary> public ExerciseB() { var dictionary = new HashTable<string, string>(); // Print PrintOptions(); while (true) { string input = Console.ReadLine().Replace(".", ""); switch (input) { case "1": // Change/Put new translation in the HashTable. Console.Write("\tEnter the word: "); string key = Console.ReadLine().Trim(); Console.Write("\tEnter the translation: "); string value = Console.ReadLine().Trim(); dictionary.Put(key, value); break; case "2": // Translate word by word Console.WriteLine("\tPlease enter a sentence you want to translate:"); string[] toTranslate = Console.ReadLine().Trim().Split(' ', '.', '!', '?'); Console.Write("\t=> "); foreach (string word in toTranslate) { string translation = dictionary.Get(word); Console.Write((translation == default(string) ? word : translation) + " "); } Console.WriteLine(); break; case "3": return; default: continue; } Console.WriteLine("Press enter to continue."); Console.ReadLine(); Console.Clear(); PrintOptions(); } }
static void Main(string[] args) { HashTable <int, int> hashTable = new HashTable <int, int>(24); for (int i = 0; i < 5000000; i++) { hashTable.Set(i, i + 1); } Console.WriteLine(hashTable.Get(235)); //Dictionary<int, int> dictionary = new Dictionary<int, int>(24); //for (int i = 0; i < 25000000; i++) //{ // dictionary.Add(i, i + 1); //} //Console.WriteLine(dictionary[235]); }
/// <summary> /// Default constructor run the actual test. /// </summary> public ExerciseA() { var table = new HashTable<string, int>(15); table.Put("Simon", 19); table.Put("Emma", 18); table.Put("Tim", 21); table.Put("Putin", 13); table.Put("Obama", 25); int putinsAge = table.Get("Putin"); Console.WriteLine("Putin's age is: " + putinsAge); table.Remove("Tim"); if (!table.Contains("Tim")) { Console.WriteLine("Tim's age is removed!"); } Console.WriteLine("Max list size in the HashTable (should be low!): " + table.GetMaxCurrentPositionCollisions()); }
/// <summary> /// Default constructor run the actual test. /// </summary> public ExerciseA() { var table = new HashTable <string, int>(15); table.Put("Simon", 19); table.Put("Emma", 18); table.Put("Tim", 21); table.Put("Putin", 13); table.Put("Obama", 25); int putinsAge = table.Get("Putin"); Console.WriteLine("Putin's age is: " + putinsAge); table.Remove("Tim"); if (!table.Contains("Tim")) { Console.WriteLine("Tim's age is removed!"); } Console.WriteLine("Max list size in the HashTable (should be low!): " + table.GetMaxCurrentPositionCollisions()); }