示例#1
0
 public void Initialize()
 {
     HashFunctionString hashFunctionString = new HashFunctionString();
     hashTableString = new HashTable<string>(hashFunctionString);
     OtherHashFunctionInt hashFunctionInt = new OtherHashFunctionInt();
     hashTableInt = new HashTable<int>(hashFunctionInt);
 }
示例#2
0
        static void Main(string[] args)
        {
            HashTable hash = new HashTable(17, 3);

            hash.put("first message");
            hash.put("я сделал это!");
            hash.put("думал, что очень сложно");
            hash.put("надеюсь, правильно");
            for (int i = 0; i < hash.capacity; i++)
            {
                if (hash.check[i])
                {
                    Console.Write("Под индексом " + i + " строка: " + hash.arr[i]);
                    Console.WriteLine();
                }
            }

            Console.WriteLine();
            Console.ReadLine();
        }
示例#3
0
 static void Main(string[] args)
 {
     HashTable<string> table = new HashTable<string>();
     table.InsertHashTable("Strochka");
     if (table.ExistHashElement("Strochka"))
     {
         Console.WriteLine("True");
     }
     else
     {
         Console.WriteLine("False");
     }
     table.RemoveHashElement("Strochka");
     if (table.ExistHashElement("Strochka"))
     {
         Console.WriteLine("True");
     }
     else
     {
         Console.WriteLine("False");
     }
 }
示例#4
0
        static void Main(string[] args)
        {
            DataItem dataItem;
            int      key;
            int      size;
            int      n;
            int      keysPerCell = 10;

            Console.WriteLine("Enter size of hash table:");
            size = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter initial number of items:");
            n = int.Parse(Console.ReadLine());

            HashTable theTable = new HashTable(size);

            Hashtable hashtable = new Hashtable(size);

            hashtable.Add("awe", theTable);
            hashtable.Add(1, "aweawr");

            foreach (var item in hashtable.Values)
            {
                Console.WriteLine(item);
            }

            for (int i = 0; i < n; i++)
            {
                key = Math.Abs(new Random().Next() * 2 * size);

                dataItem = new DataItem(key);
                theTable.Insert(dataItem);
            }

            while (true)
            {
                Console.WriteLine("Enter first letter of ");
                Console.WriteLine("show, insert, delete, or find: ");

                char choice = char.Parse(Console.ReadLine());

                switch (choice)
                {
                case 's':
                    theTable.DisplayTable();
                    break;

                case 'i':
                    Console.WriteLine("Enter key value to insert: ");
                    key      = int.Parse(Console.ReadLine());
                    dataItem = new DataItem(key);
                    theTable.Insert(dataItem);
                    break;

                case 'd':
                    Console.WriteLine("Enter key value to delete: ");
                    key = int.Parse(Console.ReadLine());
                    theTable.Delete(key);
                    break;

                case 'f':
                    Console.WriteLine("Enter key value to find: ");
                    key      = int.Parse(Console.ReadLine());
                    dataItem = theTable.Find(key);

                    if (dataItem != null)
                    {
                        Console.WriteLine("Found: " + key);
                    }
                    else
                    {
                        Console.WriteLine("Could not find: " + key);
                    }
                    break;

                default:
                    break;
                }
            }
        }