static void Main(string[] args) { Console.WriteLine("Hello World!"); var test = new HashTable <int>(); Console.WriteLine(test.Add(2555, 123)); Console.WriteLine(test.Contains(0)); Console.WriteLine(test.Contains(0)); Console.WriteLine(test.Add(1, 123)); Console.WriteLine(test.Add(0, 12344)); Console.WriteLine(test.Remove(0)); Console.WriteLine(test.Remove(0)); Console.WriteLine(test.Add(1, 12344)); Console.WriteLine(test.Add(2, 12344)); Console.WriteLine(test.Add(2, 12344)); Console.WriteLine(test.Add(3, 12344)); Console.WriteLine(test.Add(4, 12344)); Console.WriteLine(test.Add(5, 12344)); Console.WriteLine(test.Add(6, 12344)); Console.WriteLine(test.Add(7, 12344)); Console.WriteLine(test.Add(8, 12344)); Console.WriteLine(test.Add(9, 12344)); Console.ReadLine(); }
static void Main(string[] args) { try { HashTable <string> wood = new HashTable <string>(); wood.Add("береза"); wood.Add("осина"); wood.Add("сосна"); wood.Add("ель"); wood.Add("рябина"); wood.Add("ольха"); wood.Add("дуб"); wood.Add("бук"); wood.Add("липа"); wood.Add("акация"); Console.WriteLine(wood); Console.WriteLine("количество элементов =" + wood.Count); Console.WriteLine("Проверим на наличие элемента акация: " + wood.Contains("акация")); Console.WriteLine("Проверим на наличие элемента пихта: " + wood.Contains("пихта")); string[] arrayWood = new string[10]; wood.CopyTo(arrayWood, 0); Console.WriteLine("Скопируем таблицу в массив получим: "); foreach (string e in arrayWood) { Console.WriteLine(e); } wood.Remove("липа"); Console.WriteLine("Удалим элемент липа получим: " + Environment.NewLine + wood); wood.Clear(); Console.WriteLine("Очистим таблицу получим: " + wood); } catch (ArgumentNullException e) { Console.WriteLine(e.ToString()); } catch (ArgumentOutOfRangeException e) { Console.WriteLine(e.ToString()); } catch (ArgumentException e) { Console.WriteLine(e.ToString()); } finally { Console.ReadKey(); } }
private static void Main(string[] args) { var integerTable = new HashTable <int>(); for (var i = 1; i <= 100; ++i) { if (i % 2 == 1) { integerTable.Add(i); } } for (var i = 1; i <= 100; ++i) { if (i % 4 == 0 && integerTable.Contains(i)) { integerTable.Erase(i); } } var stringTable = new HashTable <string>(); for (var i = 1; i <= 100; ++i) { stringTable.Add("word" + i.ToString()); } }
static void Main(string[] args) { var integers = new HashTable <int>(55); integers.Add(0); integers.Add(30); integers.Add(55); integers.Add(78); integers.Add(99); Console.WriteLine("integers: " + string.Join(", ", integers)); Console.WriteLine("integers.Contains(78) = " + integers.Contains(78)); Console.WriteLine("removing '55'"); integers.Remove(55); Console.WriteLine("integers: " + string.Join(", ", integers)); Console.WriteLine("copying integers to array and shifting elements 1 position right"); var array = new int[integers.Count + 1]; integers.CopyTo(array, 1); Console.WriteLine("array: " + string.Join(", ", array)); Console.WriteLine("clearing integers"); integers.Clear(); Console.WriteLine("integers: " + string.Join(", ", integers)); }
static void Main(string[] args) { var plz = new HashTable <int, string>(); plz.Add(24943, "Flensburg"); plz.Add(25355, "Barmstedt"); plz.Add(25746, "Heide"); Console.WriteLine(plz.Contains(25355)); plz.Remove(25355); Console.WriteLine(plz.Contains(25355)); foreach (var item in plz) { Console.WriteLine(item); } Console.ReadLine(); // Einwohner[Schleswig-Holstein] = 2838000; // Implementierung --> Probleme: // 1. Speicherverwaltung // 2. vom Indexer String zum Indexer Zahl // Abbilden nicht-numerischer Werte // Abbilden einer großen Wertmenge durch sog. Hashfunktion // Für Hashfunktionen --> "modulo" ! // Problem der Kollision // Hashtabelle --> List // oder auch Lineares Sondieren (Achtung: sehr leichte Klumpenbildung!) // oder sogar Quadratische Sondierung // 2 Funktionen (Schrittweite-Berechnung) // 1. Berechnen Array-Index // 2. Schrittweite beim Einfügen/Suchen // hashSteps = Konstante - (Hashkey mod Konstante) // Wichtig Länge entsprechend setzen, damit nicht zu viele Kollisionen zustande kommen Console.WriteLine("Weiter mit ENTER . . ."); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Создаём таблицу."); HashTable <string> hashTable = new HashTable <string> { "A", "B", "C" }; Console.WriteLine("Исходная таблица: " + hashTable); Console.WriteLine("Размер = {0}", hashTable.Count); Console.WriteLine(); Console.WriteLine("Добавляем дубликат."); hashTable.Add("C"); Console.WriteLine("Исходная таблица: " + hashTable); Console.WriteLine("Размер = {0}", hashTable.Count); Console.WriteLine(); Console.WriteLine("Добавляем оригинальное значение."); hashTable.Add("D"); Console.WriteLine("Исходная таблица: " + hashTable); Console.WriteLine("Размер = {0}", hashTable.Count); Console.WriteLine(); Console.WriteLine("Удаляем D."); hashTable.Remove("D"); Console.WriteLine("Исходная таблица: " + hashTable); Console.WriteLine("Размер = {0}", hashTable.Count); Console.WriteLine(); Console.WriteLine("Таблица содержит D?"); Console.WriteLine(hashTable.Contains("D") ? "Да" : "Нет"); Console.WriteLine(); Console.WriteLine("Очищаем таблицу."); hashTable.Clear(); Console.WriteLine("Исходная таблица: " + hashTable); Console.WriteLine("Размер = {0}", hashTable.Count); Console.WriteLine(); HashTable <int> hashTable1 = new HashTable <int> { 1, 2, 3, 2 }; HashTable <int> hashTable2 = new HashTable <int> { 1, 2, 3, 2 }; Console.WriteLine(hashTable1.Equals(hashTable2)); Console.ReadKey(); }
static void Main(string[] args) { // The code provided will print ‘Hello World’ to the console. // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app. HashTable _table = new HashTable(); _table.Add("sveta", 5); _table.Add("super", 1); var result = _table.Contains("sveta"); Console.WriteLine("Hello World!"); Console.ReadKey(); // Go to http://aka.ms/dotnet-get-started-console to continue learning how to build a console app! }
private static void Main() { HashTable <int> hashTable = new HashTable <int>(); int[] array = new int[10]; hashTable.Add(5); hashTable.Add(2); hashTable.Add(13); hashTable.Add(522); hashTable.Add(125); hashTable.Add(9); hashTable.Add(55); foreach (int value in hashTable) { Console.WriteLine(value); } Console.WriteLine(); Console.WriteLine(hashTable.Contains(9)); Console.WriteLine(hashTable.Remove(13)); Console.WriteLine(); foreach (int value in hashTable) { Console.WriteLine(value); } Console.WriteLine(); foreach (int value in hashTable) { Console.WriteLine(value); } Console.WriteLine(); hashTable.CopyTo(array, 1); foreach (int value in array) { Console.WriteLine(value); } Console.ReadLine(); }
static void Main(string[] args) { HashTable <int> hashTable = new HashTable <int>(); hashTable.Add(31); hashTable.Add(72); hashTable.Add(17); hashTable.Add(3); hashTable.Add(8); hashTable.Add(14); Console.Write("HashTable before changes={ "); foreach (int element in hashTable) { Console.Write(element + " "); } Console.Write(" }"); Console.WriteLine(); HashTable <string> hashTable1 = new HashTable <string>(); hashTable1.Add("s"); hashTable1.Add("b"); hashTable1.Add("c"); hashTable1.Add("de"); hashTable1.Add("e"); Console.WriteLine(hashTable1.Contains(null)); Console.WriteLine(hashTable1.Remove(null)); hashTable1.Clear(); Hashtable qwe = new Hashtable(); qwe.Add(0, "A"); qwe.Add(1, "B"); qwe.Add(2, null); Console.WriteLine(qwe.Contains(2)); qwe.Remove(2); }
/// <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()); }
static void Main(string[] args) { try { HashTable<string, int> hashTable = new HashTable<string, int>(); hashTable.Add("pesho", 1); hashTable.Add("gosho", 5); hashTable.Add("misho", 2); hashTable.Add("sasho", 3); Console.WriteLine("Count is : {0}", hashTable.Count); hashTable.Remove("sasho"); Console.WriteLine("Count is : {0}", hashTable.Count); Console.WriteLine(hashTable.Find("gosho")); Console.WriteLine(hashTable.Contains("gosho")); Console.WriteLine(hashTable["gosho"]); foreach (var item in hashTable) { Console.WriteLine(item.Key + " -> " + item.Value); } for (int i = 0; i < 30; i++) { hashTable.Add(i * 131 + "", i + 100); } Console.WriteLine("Count is : {0}", hashTable.Count); hashTable.Clear(); Console.WriteLine("Count is : {0}", hashTable.Count); Console.WriteLine(hashTable.Find("gosho")); } catch (ArgumentException aex) { Console.WriteLine(aex.Message); } }
/// <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()); }