public static void Main(string[] args) { var hashTable = new HashTable<int,string>(); hashTable.Add(1, "Test") .Add(2, "Test 2") .Add(3, "Test 3") .Add(0, "Test 4") .Add(16, "Test 5") .Add(19, "Test 37") .Add(19, "Test 200") .Remove(3); for (int i = 20; i < 50; i++) { hashTable.Add(i, "String " + i); } Console.WriteLine(string.Join(" ", hashTable.Keys)); Console.WriteLine(hashTable[2]); foreach (var pair in hashTable) { Console.WriteLine(pair); } }
static public void Main() { IHash hash; HashTable.HashTable hashTable; Console.WriteLine("Type:\n -0 to use first function,\n -1 to use second function."); ushort command = Convert.ToUInt16(Console.ReadLine()); while (command > 1) { Console.WriteLine("Wrong input! Try again."); command = Convert.ToUInt16(Console.ReadLine()); } if (command == 1) { hash = new Hash2(); } else { hash = new Hash1(); } hashTable = new HashTable.HashTable(hash); hashTable.Add(1); for (int i = 0; i < 1000; ++i) { hashTable.Add(51 * i); } Console.WriteLine(hashTable.Search(33)); Console.WriteLine(hashTable.Search(102)); hashTable.DeleteElement(51); hashTable.DeleteElement(0); Console.WriteLine(hashTable.Search(0)); // hash.Print(); }
static void Main() { var test = new HashTable<int, string>(); test.Add(1, "a"); test.Add(2, "b"); test.Add(1, "c"); test.Add(2, "d"); }
public void AddAndSearch_2() { hashTable = new HashTable.HashTable(new Hash1()); hashTable.Add(1); hashTable.Add(2); Assert.AreEqual(true, hashTable.Search(1)); Assert.AreEqual(true, hashTable.Search(2)); Assert.AreEqual(false, hashTable.Search(3)); }
static void Main() { HashFunction1 ooo = new HashFunction1(); HashTable myTable = new HashTable(2, ooo); myTable.Add("ololo"); myTable.Add("olololo"); myTable.PrintTable(); Console.Read(); }
public static void Main() { HashTable hash = new HashTable(); hash.Add(1); for (int i = 0; i < 1000; ++i) { hash.Add(51 * i); } Console.WriteLine(hash.Search(33)); Console.WriteLine(hash.Search(102)); hash.DeleteElement(51); hash.DeleteElement(0); Console.WriteLine(hash.Search(0)); hash.Print(); }
static void Main(string[] args) { HashTable<string, int> people = new HashTable<string, int>(); people.Add("gosho", 14); people.Add("tosho", 15); people.Add("pesho", 16); people.Add("ivan", 20); people.Add("stoqn", 40); Console.WriteLine("Count {0}", people.Count); Console.WriteLine("Gosho is {0} years old.", people["gosho"]); people.Remove("gosho"); Console.WriteLine("Count {0}", people.Count); Console.WriteLine(people.Contain("gosho")); }
public void Get_Missing() { HashTable<string, int> table = new HashTable<string, int>(); table.Add("100", 100); int value = table["missing"]; }
public void Add_Unique_Adds() { HashTable<string, int> table = new HashTable<string, int>(); List<int> added = new List<int>(); for (int i = 0; i < 100; i++) { Assert.AreEqual(i, table.Count, "The count was incorrect"); int value = _rng.Next(); string key = value.ToString(); // this ensure we should never throw on Add while (table.ContainsKey(key)) { value = _rng.Next(); key = value.ToString(); } table.Add(key, value); added.Add(value); } // now make sure all the keys and values are there foreach (int value in added) { Assert.IsTrue(table.ContainsKey(value.ToString()), "ContainsKey returned false?"); Assert.IsTrue(table.ContainsValue(value), "ContainsValue returned false?"); int found = table[value.ToString()]; Assert.AreEqual(value, found, "The indexed value was incorrect"); } }
public void Get_Succeeds() { HashTable<string, int> table = new HashTable<string, int>(); table.Add("100", 100); int value = table["100"]; Assert.AreEqual(100, value, "The returned value was incorrect"); for (int i = 0; i < 100; i++) { table.Add(i.ToString(), i); value = table["100"]; Assert.AreEqual(100, value, "The returned value was incorrect"); } }
public void Remove_Missing() { HashTable<string, int> table = new HashTable<string, int>(); table.Add("100", 100); Assert.IsFalse(table.Remove("missing"), "Remove on an empty collection should return false"); }
static void Main() { string stringText = Console.ReadLine(); var symbolsColection = new HashTable<char, int>(); for (int i = 0; i < stringText.Length; i++) { char symbol = stringText[i]; if (!symbolsColection.ContainsKey(symbol)) { symbolsColection.Add(symbol, 1); } else { symbolsColection[symbol]++; } } var sortedSymbolsColection = symbolsColection.OrderBy(s => s.Key); foreach (var symbol in sortedSymbolsColection) { Console.WriteLine("{0}: {1} time/s", symbol.Key, symbol.Value); } }
public void DeleteElement_2() { hashTable = new HashTable.HashTable(new Hash2()); hashTable.DeleteElement(1); hashTable.Add(1); hashTable.DeleteElement(1); Assert.AreEqual(false, hashTable.Search(1)); }
public void TryGet_Succeeds() { HashTable<string, int> table = new HashTable<string, int>(); table.Add("100", 100); int value; Assert.IsTrue(table.TryGetValue("100", out value)); Assert.AreEqual(100, value, "The returned value was incorrect"); for (int i = 0; i < 100; i++) { table.Add(i.ToString(), i); Assert.IsTrue(table.TryGetValue("100", out value)); Assert.AreEqual(100, value, "The returned value was incorrect"); } }
public void TestAddMethodShouldReplaceValues() { var hashTable = new HashTable<int, int>(); hashTable.Add(1, 2); hashTable[2] = 3; Assert.AreEqual(2, hashTable.Count); hashTable.Add(1, 3); Assert.AreEqual(2, hashTable.Count); Assert.AreEqual(3, hashTable[1]); hashTable.Add(1, 4); Assert.AreEqual(2, hashTable.Count); Assert.AreEqual(4, hashTable[1]); }
public void TryGet_Missing() { HashTable<string, int> table = new HashTable<string, int>(); table.Add("100", 100); int value; Assert.IsFalse(table.TryGetValue("missing", out value)); }
public void TestAddMethod() { var hashTable = new HashTable<int, int>(); hashTable.Add(1, 2); hashTable[2] = 3; Assert.AreEqual(2, hashTable.Count); }
public void TestGetValueMethodShouldThrowException() { var hashTable = new HashTable<int, int>(); hashTable.Add(1, 2); hashTable[2] = 3; hashTable.GetValue(3); }
public static void Main() { var HashTable = new HashTable<int, string> { { 3, "ar" } }; HashTable[2] = "asd"; string indexCheck = HashTable[2]; Console.WriteLine("toString:"); Console.WriteLine(HashTable); Console.WriteLine("indexer:"); Console.WriteLine(HashTable[2]); Console.WriteLine(indexCheck); Console.WriteLine("keys:"); var keysChecker = HashTable.Keys; foreach (int key in keysChecker) { Console.WriteLine(key); } Console.WriteLine("count:"); Console.WriteLine(HashTable.Count); Console.WriteLine("remove:"); HashTable.Remove(4); Console.WriteLine(HashTable[2]); HashTable.Remove(2); Console.WriteLine(HashTable[2]); Console.WriteLine("count:"); Console.WriteLine(HashTable.Count); string res; bool findChecker = HashTable.Find(3, out res); Console.WriteLine("Find value by key 3:"); Console.WriteLine(res); Console.WriteLine(findChecker); Console.WriteLine(HashTable); Console.WriteLine("clear"); HashTable.Clear(); Console.WriteLine(HashTable); Console.WriteLine("----"); Console.WriteLine("resize"); for (int i = 0; i < 100; i++) { HashTable.Add(i, i.ToString()); } Console.WriteLine(HashTable); }
public void TestRemoveMethod() { var hashTable = new HashTable<int, int>(); hashTable.Add(1, 2); hashTable[2] = 3; Assert.IsTrue(hashTable.Remove(2)); Assert.IsFalse(hashTable.Remove(-1)); }
public void AddToHashTableMustWork() { var hashTable = new HashTable<string, int>(); var key = "testkey"; var testValue = 100; hashTable.Add(key, testValue); Assert.AreEqual(hashTable[key], testValue); }
internal static void Main() { HashTable<int, int> hashTable = new HashTable<int, int>(); hashTable.Add(1234, 100); // в слот 179 hashTable.Add(1774, 120); // в слот 86 hashTable.Add(86, 180); // в слот 86 -> колизия Console.WriteLine("Отпечатва данните на елемента с ключ 86: {0}", hashTable.Find(86)); Console.WriteLine("Отпечатва данните на елемента с ключ 1234: {0}", hashTable.Find(1234)); Console.WriteLine("Отпечатва данните на елемента с ключ 1774: {0}", hashTable.Find(1774)); try { Console.WriteLine("Отпечатва данните на елемента с ключ 1773: {0}", hashTable.Find(1773)); } catch (InvalidOperationException ioe) { Console.WriteLine(ioe.Message); } }
public void RemoveFromHashTableMustWork() { var hashTable = new HashTable<string, int>(); var key = "testkey"; var testValue = 100; hashTable.Add(key, testValue); hashTable.Remove(key); Assert.AreEqual(hashTable.Count, 0); }
public void HashTableCountWorksCorectWithAddOfElements() { var hashTable = new HashTable<int, string>(); var expectedCount = 50; for (int i = 0; i < expectedCount; i++) { hashTable.Add(i * 2, "Test text " + i); } Assert.AreEqual(expectedCount, hashTable.Count); }
public static void Main() { // Create HashTable and add few elements. var hashtableTest = new HashTable<int, string>(); hashtableTest.Add(1, "One"); hashtableTest.Add(11, "Eleven"); hashtableTest.Add(2, "Two"); hashtableTest.Add(3, "Three"); Console.WriteLine("---------- Test Find(1) ----------"); Console.WriteLine(hashtableTest.Find(1)); Console.WriteLine("\n---------- Test Remove(1) ----------"); hashtableTest.Remove(1); Console.WriteLine("\n---------- Test Count() ----------"); Console.WriteLine(hashtableTest.Count()); Console.WriteLine("\n---------- Test get all Keys() and print ----------"); var listOfKeys = hashtableTest.Keys(); foreach (var item in listOfKeys) { Console.WriteLine(item); } Console.WriteLine("\n---------- Test foreach ----------"); foreach (var item in hashtableTest) { Console.WriteLine(item); } // If index is empty this will throw new NullReferenceException. Console.WriteLine("\n---------- Test this[0] ----------"); Console.WriteLine(hashtableTest[2]); Console.WriteLine("\n---------- Test Clear() and print count ----------"); hashtableTest.Clear(); Console.WriteLine(hashtableTest.Count()); }
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); } }
public void Add_Duplicate_Throws() { HashTable<string, int> table = new HashTable<string, int>(); List<int> added = new List<int>(); for (int i = 0; i < 100; i++) { Assert.AreEqual(i, table.Count, "The count was incorrect"); int value = _rng.Next(); string key = value.ToString(); // this ensure we should never throw on Add while (table.ContainsKey(key)) { value = _rng.Next(); key = value.ToString(); } table.Add(key, value); added.Add(value); } // now make sure each attempt to re-add throws foreach (int value in added) { try { table.Add(value.ToString(), value); Assert.Fail("The Add operation should have thrown with the duplicate key"); } catch (ArgumentException) { // correct! } } }
public void TestGetValueMethod() { var hashTable = new HashTable<int, int>(); hashTable.Add(1, 2); hashTable[2] = 3; Assert.AreEqual(2, hashTable.Count); Assert.AreEqual(2, hashTable[1]); Assert.AreEqual(2, hashTable.GetValue(1)); Assert.AreEqual(3, hashTable[2]); Assert.AreEqual(3, hashTable.GetValue(2)); }
public void Remove_Found() { HashTable<string, int> table = new HashTable<string, int>(); for (int i = 0; i < 100; i++) { table.Add(i.ToString(), i); } for (int i = 0; i < 100; i++) { Assert.IsTrue(table.ContainsKey(i.ToString()), "The key was not found in the collection"); Assert.IsTrue(table.Remove(i.ToString()), "The value was not removed (or remove returned false)"); Assert.IsFalse(table.ContainsKey(i.ToString()), "The key should not have been found in the collection"); } }
static void Main() { HashTable<string, int> testTable = new HashTable<string, int>(); testTable.Add("stoicho", 14); testTable.Add("peicho", 6); testTable.Add("koicho", 4); testTable.Add("koicho", 114); testTable.Add("koicho", 41); testTable.Add("nacho", 4111); testTable.Add("bochko", 341); testTable.Add("zuza", 341); testTable.Add("ko", 341); foreach (var key in testTable.Keys()) { Console.WriteLine(key); } var third = testTable[2]; Console.WriteLine("===================="); foreach (var pair in third) { Console.WriteLine(pair.Key + " " + pair.Value); } Console.WriteLine("===================="); // Console.WriteLine(testTable.Keys()[3]); //Console.WriteLine("Capacity " + testTable.Capacity + " Count " + testTable.Count); //testTable.Remove("koicho"); //Console.WriteLine(testTable.Find("koicho")); //testTable.Clear(); // Console.WriteLine(testTable.Find("peicho")); }
static void RunHashTable() { HashTable<string, int> hash = new HashTable<string, int>(); hash.Add("0", 0); hash.Add("1", 1); hash.Add("2", 2); hash.Add("3", 3); hash.Add("3", 3); hash.Add("4", 4); hash.Add("5", 5); hash.Add("5", 5, (s, s1) => s == s1); foreach (KeyValue<string, int> keyValue in hash) Console.WriteLine(keyValue.Key + " -> " + keyValue.Value); Console.WriteLine(hash["1"]); }
static void Main(string[] args) { var superHashTable = new SuperHashTable <Person>(100); var person = new Person() { Name = "Andriy", Age = 20, Gender = 0 }; superHashTable.Add(new Person() { Name = "Yaroslav", Age = 20, Gender = 0 }); superHashTable.Add(new Person() { Name = "Kate", Age = 17, Gender = 1 }); superHashTable.Add(new Person() { Name = "Vasya", Age = 25, Gender = 0 }); superHashTable.Add(new Person() { Name = "Yuriy", Age = 28, Gender = 0 }); superHashTable.Add(person); Console.WriteLine(superHashTable.Search(new Person() { Name = "Andriy", Age = 20, Gender = 0 })); Console.WriteLine(superHashTable.Search(person)); Console.WriteLine(); var person1 = new Person() { Name = "Andriy", Age = 20, Gender = 0, Id = 1 }; var person2 = new Person() { Name = "Kate", Age = 17, Gender = 1, Id = 2 }; var person3 = new Person() { Name = "Vasya", Age = 25, Gender = 0, Id = 3 }; var hashTable = new HashTable <int, Person>(10); hashTable.Add(person1.Id, person); hashTable.Add(person2.Id, person); hashTable.Add(person3.Id, person); Console.WriteLine(hashTable.Search(person1.Id, person1)); Console.WriteLine(hashTable.Search(person2.Id, person3)); //var hashTable = new HashTable<int, string>(100); //hashTable.Add(5, "Hello"); //hashTable.Add(18, "World"); //hashTable.Add(777, "Hey"); //hashTable.Add(7, "Developer"); //Console.WriteLine(hashTable.Search(6, "Andriy")); //Console.WriteLine(hashTable.Search(18, "World")); Console.WriteLine(); var badHashTable = new BadHashTable <int>(100); badHashTable.Add(5); badHashTable.Add(18); badHashTable.Add(777); badHashTable.Add(7); Console.WriteLine(badHashTable.Search(6)); Console.WriteLine(badHashTable.Search(18)); Console.ReadLine(); }
private static void BenchmarkTest() { var limit = int.MaxValue / 10752; var hs = new HashTable <string, int>(); var addHs = new Stopwatch(); addHs.Start(); for (int i = 0; i < limit; i++) { hs.Add(i.ToString(), i); } addHs.Stop(); var readHs = new Stopwatch(); readHs.Start(); foreach (var item in hs) { Console.WriteLine("{0} - {1}", item.Key, item.Value); } readHs.Stop(); var delHs = new Stopwatch(); delHs.Start(); hs.Clear(); delHs.Stop(); hs = null; var dic = new Dictionary <string, int>(); var addDic = new Stopwatch(); addDic.Start(); for (int i = 0; i < limit; i++) { dic.Add(i.ToString(), i); } addDic.Stop(); var readDic = new Stopwatch(); readDic.Start(); foreach (var item in dic) { Console.WriteLine("{0} - {1}", item.Key, item.Value); } readDic.Stop(); var delDic = new Stopwatch(); delDic.Start(); dic.Clear(); delDic.Stop(); dic = null; var csHs = new System.Collections.Hashtable(); var addCsHs = new Stopwatch(); addCsHs.Start(); for (int i = 0; i < limit; i++) { csHs.Add(i, i); } addCsHs.Stop(); var readCsHs = new Stopwatch(); readCsHs.Start(); foreach (System.Collections.DictionaryEntry item in csHs) { Console.WriteLine("{0} - {1}", item.Key, item.Value); } readCsHs.Stop(); var delCsHs = new Stopwatch(); delCsHs.Start(); csHs.Clear(); delCsHs.Stop(); csHs = null; Console.WriteLine("HashTable vs. Dictionary vs C# HashTable"); Console.WriteLine("Add - {0} - {1} - {2}", addHs.Elapsed.TotalSeconds, addDic.Elapsed.TotalSeconds, addCsHs.Elapsed.TotalSeconds); Console.WriteLine("Read - {0} - {1} - {2}", readHs.Elapsed.TotalSeconds, readDic.Elapsed.TotalSeconds, readCsHs.Elapsed.TotalSeconds); Console.WriteLine("Delete - {0} - {1} - {2}", delHs.Elapsed.TotalSeconds, delDic.Elapsed.TotalSeconds, delCsHs.Elapsed.TotalSeconds); }
static void Main(string[] args) { HashTable <string, string> mht = new HashTable <string, string>(3); mht.Add("bi25ll", "bob"); mht.Add("bi3tlly", "b0ob"); mht.Add("jonwees", "bob"); mht.Add("bitll", "bob"); mht.Add("bi36weelly", "b0ob"); mht.Add("jo23nes", "bob"); mht.Add("b2363ill", "bob"); mht.Add("bi235lly", "b0ob"); mht.Add("j3365ones", "bob"); mht.Add("bi23435ll", "bob"); mht.Add("bi23635lly", "b0ob"); mht.Add("josdgnes", "bob"); Console.WriteLine(mht["bitll"]); mht["bitll"] = "billy bob"; Console.WriteLine(mht["bitll"]); mht.Remove("bitll"); mht.Remove("bi36weelly"); mht.Remove("billy"); mht.Remove("billy"); mht.Remove("billy"); }
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(); }
private static void Main() { BadHashTable <int> badHashTable = new BadHashTable <int>(10); badHashTable.Add(5); badHashTable.Add(18); badHashTable.Add(777); Console.WriteLine(badHashTable.Search(6)); Console.WriteLine(badHashTable.Search(18)); Console.ReadLine(); Console.Clear(); HashTable <int, string> hashTable = new HashTable <int, string>(10); hashTable.Add(5, "Hello"); hashTable.Add(18, "World"); hashTable.Add(777, "!"); Console.WriteLine(hashTable.Search(6, "Lol")); Console.WriteLine(hashTable.Search(18, "World")); Console.ReadLine(); Console.Clear(); SuperHashTable <Person> superHashTable = new SuperHashTable <Person>(10); Person person = new Person() { Name = "A", Age = 25, Gender = 0 }; superHashTable.Add(new Person() { Name = "A", Age = 25, Gender = 0 }); superHashTable.Add(person); superHashTable.Add(new Person() { Name = "C", Age = 21, Gender = 1 }); Console.WriteLine(superHashTable.Search(new Person() { Name = "A", Age = 25, Gender = 0 })); Console.WriteLine(superHashTable.Search(person)); Console.ReadLine(); Console.Clear(); OpenHashingHashTable <string, string> openHashingHashTable = new OpenHashingHashTable <string, string>(); openHashingHashTable.Insert("Little Prince", "I never wished you any sort of harm; but you wanted me to tame you..."); openHashingHashTable.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."); openHashingHashTable.Insert("Rose", "Well, I must endure the presence of two or three caterpillars if I wish to become acquainted with the butterflies."); openHashingHashTable.Insert("King", "He did not know how the world is simplified for kings. To them, all men are subjects."); ShowHashTable(openHashingHashTable, "Created hashtable."); openHashingHashTable.Delete("King"); ShowHashTable(openHashingHashTable, "Delete item from hashtable."); Console.WriteLine($"Little Prince say: {openHashingHashTable.Search("Little Prince")}"); }
static void Main(string[] args) { HashTable <dynamic, dynamic> ht = new HashTable <dynamic, dynamic>(); var options = "Please Select the options bewlow\n" + "1 to insert\n" + "2 to delete\n" + "3 to contain\n" + "4 get value by key\n" + "5 to get Size\n" + "6 to iterator\n" + "7 to print\n" + "Any other Key to exit"; int user_input; bool flag = true; bool res; dynamic get_value; dynamic get_key; while (flag) { Console.WriteLine(options); res = int.TryParse(Console.ReadLine(), out user_input); if (!res) { Console.WriteLine("please select Integer"); continue; } switch (user_input) { case 1: Console.WriteLine("Please Select Value to key "); get_key = Console.ReadLine(); Console.WriteLine("Please Select Value to value "); get_value = Console.ReadLine(); ht.Add(get_key, get_value); break; case 2: Console.WriteLine("Delete"); Console.WriteLine("Please Select Value to key which you want to delete"); get_key = Console.ReadLine(); ht.remove(get_key); break; case 3: Console.WriteLine("Contain"); Console.WriteLine("Please Select Value to key to check if its present or not"); get_key = Console.ReadLine(); ht.contain(get_key); Console.WriteLine("Delete At Position"); break; case 4: Console.WriteLine("Contain"); Console.WriteLine("Please Select Value to key to check the value"); get_key = Console.ReadLine(); ht.get_value_by_id(get_key); break; case 5: Console.WriteLine("get size"); ht.size(); break; case 6: Console.WriteLine("Iterator"); break; case 7: Console.WriteLine("Printing "); ht.print(); break; default: Console.WriteLine("Exit"); flag = false; break; } } /*ht.Add(2, "B"); * ht.Add(3, "C"); * ht.Add("aaa", "yo"); * ht.Add("sb", "lol"); * ht.Add(4, "D"); * ht.Add("a", "A"); * ht.Add("b", "AFF"); * ht.Add(5, "E"); * * //ht.print(); * //ht.size(); * //ht.remove("aaa"); * ht.print(); * //ht.size(); * * * * //Console.WriteLine(ht.get_value_by_id("a")); * * * //Console.WriteLine(ht.contain(1)); * * Node<dynamic,dynamic> tempNode = ht.get_main_Node(); * iterator<dynamic, dynamic> i = new iterator<dynamic, dynamic>(tempNode); * tempNode = i.next(tempNode); * tempNode = i.next(tempNode); * tempNode = i.next(tempNode);*/ Console.ReadKey(); }
static void Main(string[] args) { // начальные данные для теста string beginText = "Осенью имя рэпера часто упоминалось в отечественных СМИ СМИ"; string[] beginArrayWords = beginText.Split(' '); //создание и заполнение хэш-таблицы HashTable <string> testHashTable = new HashTable <string>(beginArrayWords.Length); foreach (string word in beginArrayWords) { testHashTable.Add(word); } Console.WriteLine(testHashTable); Console.WriteLine(); // тестируем количество элементов Console.Write("Количество элементов: "); Console.WriteLine(testHashTable.Count); Console.WriteLine(); //тестируем удаление элемента Console.WriteLine("удалим \"в\""); testHashTable.Remove("в"); Console.WriteLine(testHashTable); Console.WriteLine(); Console.WriteLine("удалим отсутствующий элемент \"о\""); testHashTable.Remove("о"); Console.WriteLine(testHashTable); Console.WriteLine(); //тестируем итератор Console.WriteLine("-=тестируем итератор=-"); try { foreach (string element in testHashTable) { Console.WriteLine(element); } } catch (InvalidOperationException e) { Console.WriteLine(e.Message); } Console.WriteLine("-=тестируем исключение из итератора=-"); try { foreach (string element in testHashTable) { Console.WriteLine(element); testHashTable.Remove(element); } } catch (InvalidOperationException e) { Console.WriteLine(e.Message); } Console.WriteLine(); //тестируем копирование в массив Console.WriteLine("-=тестируем копирование в массив=-"); string[] testArray = new string[testHashTable.Count]; testHashTable.CopyTo(testArray, 0); foreach (string element in testArray) { Console.WriteLine(element); } Console.WriteLine(); // тестируем исключения копирования в массив Console.WriteLine("-=тестируем исключения при копировании в массив=-"); try { testHashTable.CopyTo(testArray, -1); } catch (ArgumentNullException e1) { Console.WriteLine(e1.Message); } catch (ArgumentOutOfRangeException e2) { Console.WriteLine(e2.Message); } catch (ArgumentException e3) { Console.WriteLine(e3.Message); } Console.WriteLine(); string[] testArray1 = new string[testHashTable.Count - 1]; try { testHashTable.CopyTo(testArray1, 0); } catch (ArgumentNullException e1) { Console.WriteLine(e1.Message); } catch (ArgumentOutOfRangeException e2) { Console.WriteLine(e2.Message); } catch (ArgumentException e3) { Console.WriteLine(e3.Message); } Console.WriteLine(); string[] testArray2 = null; try { testHashTable.CopyTo(testArray2, 0); } catch (ArgumentNullException e1) { Console.WriteLine(e1.Message); } catch (ArgumentOutOfRangeException e2) { Console.WriteLine(e2.Message); } catch (ArgumentException e3) { Console.WriteLine(e3.Message); } Console.WriteLine(); //тестируем очистку Console.WriteLine("очистка"); testHashTable.Clear(); Console.WriteLine(testHashTable); Console.WriteLine(); //тестируем на работы с null Console.WriteLine("-=тестируем на работы с null=-"); Console.WriteLine(); testHashTable.Add(null); testHashTable.Add(null); testHashTable.Add(null); Console.WriteLine(testHashTable); Console.WriteLine(); testHashTable.Remove(null); Console.WriteLine(testHashTable); Console.WriteLine(); }
static void Main(string[] args) { HashTable h1 = new HashTable(); h1.Add(23); h1.Add(57); h1.Add(88); h1.Add(78); h1.Add(63); h1.Add(3); h1.Add(92); h1.Add(52); h1.Add(30); h1.Add(112); h1.Add(142); //Silmeden önce h1.ShowData(); WriteLine(); h1.Remove(78); h1.Remove(23); h1.Remove(63); h1.Remove(30); h1.Remove(52); h1.Remove(32); //Sildikten Sonra h1.ShowData(); }