static void Main(string[] args) { HashTable hashTable = new HashTable(); hashTable.Insert("qwer1", "barbaz1"); hashTable.Insert("qwer12", "barbaz12"); hashTable.Insert("qwer123", "barbaz123"); hashTable.Insert("qwer1234", "barbaz1234"); hashTable.Insert("qwer12345", "barbaz12345"); hashTable.Insert("qwer123456", "barbaz123456"); Console.WriteLine($"Key: qwer1; Value: {hashTable.Search("qwer1")}"); Console.WriteLine($"Key: qwer12; Value: {hashTable.Search("qwer12")}"); Console.WriteLine($"Key: qwer123; Value: {hashTable.Search("qwer123")}"); Console.WriteLine($"Key: qwer1234; Value: {hashTable.Search("qwer1234")}"); Console.WriteLine($"Key: qwer12345; Value: {hashTable.Search("qwer12345")}"); Console.WriteLine($"Key: qwer123456; Value: {hashTable.Search("qwer123456")}"); hashTable.Delete("qwer12"); hashTable.Delete("qwer1234"); hashTable.Delete("qwer123456"); Console.WriteLine($"Key: qwer1; Value: {hashTable.Search("qwer1")}"); Console.WriteLine($"Key: qwer12; Value: {hashTable.Search("qwer12")}"); Console.WriteLine($"Key: qwer123; Value: {hashTable.Search("qwer123")}"); Console.WriteLine($"Key: qwer1234; Value: {hashTable.Search("qwer1234")}"); Console.WriteLine($"Key: qwer12345; Value: {hashTable.Search("qwer12345")}"); Console.WriteLine($"Key: qwer123456; Value: {hashTable.Search("qwer123456")}"); Console.ReadKey(); }
static void Main(string[] args) { // Создаем новую хеш таблицу. var hashTable = new HashTable(); // Добавляем данные в хеш таблицу в виде пар Ключ-Значение. hashTable.Insert("Little Prince", "I never wished you any sort of harm; but you wanted me to tame you..."); hashTable.Insert("Fox", "And now here is my secret, a very simple secret: It is only with the heart that one can see rightly; what is essential is invisible to the eye."); hashTable.Insert("Rose", "Well, I must endure the presence of two or three caterpillars if I wish to become acquainted with the butterflies."); hashTable.Insert("King", "He did not know how the world is simplified for kings. To them, all men are subjects."); // Выводим хранимые значения на экран. ShowHashTable(hashTable, "Created hashtable."); Console.ReadLine(); // Удаляем элемент из хеш таблицы по ключу // и выводим измененную таблицу на экран. hashTable.Delete("King"); ShowHashTable(hashTable, "Delete item from hashtable."); Console.ReadLine(); // Получаем хранимое значение из таблицы по ключу. Console.WriteLine("Little Prince say:"); var text = hashTable.Search("Little Prince"); Console.WriteLine(text); Console.ReadLine(); }
static void Main(string[] args) { int size = 252; HashTable <int, int> hashTable = new HashTable <int, int>(size); hashTable.Add(1, 1); hashTable.Add(1, 2); hashTable.Add(3, 5); hashTable.Add(4, 3); hashTable.Add(5, 4); hashTable.Add(8, 6); hashTable.Add(13, 7); hashTable.Show(); Console.WriteLine(hashTable.Delete(13)); hashTable.Show(); Console.WriteLine(hashTable.GetValue(8)); Console.ReadKey(); }
public static void Main() { HashTable <int, string> testTable = new HashTable <int, string>(); testTable.Add(1, "test"); string test = testTable.GetValue(1); Console.WriteLine(test); testTable.Delete(1); Console.WriteLine(testTable.GetValue(1)); }
static void Main(string[] args) { var table = new HashTable <int>(7); table.Add(4); Console.WriteLine(table); table.Add(11); table.Add(1); table.Add(47298); table.Add(56298); Console.WriteLine(table); table.Delete(11); Console.WriteLine(table); }
public void DeleteElementsAndCheckTheirExistenceShallReturnFalseTrueFalse() { table.AddElement("111"); table.AddElement("222"); table.Delete("111"); Assert.IsFalse(table.Check("111")); Assert.IsTrue(table.Check("222")); table.Delete("222"); Assert.IsFalse(table.Check("222")); }
static void Main(string[] args) { var hashTable = new HashTable <string>(); hashTable.Insert("1", "asfdgfghdfgsfwfwfwfwef"); hashTable.Insert("2", "cvcvbcbcbcbcbcbcbcbcvb"); hashTable.Insert("3", "lklklklklklklklklklklk"); hashTable.ShowHashTable(hashTable, "Хен-таблица"); Console.WriteLine(); hashTable.Delete("2"); hashTable.ShowHashTable(hashTable, "Хен-таблица"); Console.WriteLine(); Console.WriteLine("Поиск:"); var text = hashTable.Search("3"); Console.WriteLine(text); }
private static void EventLoop(HashTable table) { Menu(); int choice = 1; while (choice != 0) { WriteLine(); WriteLine("Enter your choice: "); string input = ReadLine(); while (!int.TryParse(input, out choice)) { WriteLine("It`s not a number, try again: "); input = ReadLine(); } switch (choice) { case 1: { WriteLine("Write the string: "); string str = ReadLine(); table.AddElement(str); break; } case 2: { WriteLine("Write the string: "); string str = ReadLine(); if (table.Check(str)) { WriteLine("There`s such string in the hash table"); } else { WriteLine("There`s no such string in the hash table"); } break; } case 3: { WriteLine("Write the string: "); string str = ReadLine(); while (!table.Check(str)) { WriteLine("There`s no such string in hash table, try again: "); str = ReadLine(); } table.Delete(str); break; } case 0: { break; } default: { WriteLine("Wrong number, try again: "); break; } } } }
/// <summary> /// Make actions requested by user /// </summary> /// <param name="table">Used table</param> private static void EventLoop(HashTable table) { Menu2(); int choice = 1; while (choice != 0) { WriteLine(); Write("Enter your choice: "); string input = ReadLine(); while (!int.TryParse(input, out choice)) { WriteLine("It`s not a number, try again: "); input = ReadLine(); } switch (choice) { case 1: { Write("Write the string: "); string str = ReadLine(); try { table.AddElement(str); } catch (FormatException e) { WriteLine(e.Message); } break; } case 2: { Write("Write the string: "); string str = ReadLine(); bool presence = false; try { presence = table.Check(str); } catch (FormatException e) { WriteLine(e.Message); } if (presence) { WriteLine("There`s such string in the hash table"); } else { WriteLine("There`s no such string in the hash table"); } break; } case 3: { Write("Write the string: "); string str = ReadLine(); bool presence = false; try { presence = table.Check(str); } catch (FormatException e) { WriteLine(e.Message); } if (presence) { table.Delete(str); } break; } case 0: { break; } default: { Write("Wrong number, try again: "); break; } } } }