Example #1
0
        public void Insert(GroceryRecord newRecord)
        {
            int key = newRecord.getgroceryId();
            int h   = hash(key);

            int location = h;

            for (int i = 1; i < m; i++)
            {
                if (array[location] == null || array[location].getgroceryId() == -1)
                {
                    array[location] = newRecord;
                    n++;
                    return;
                }

                if (array[location].getgroceryId() == key)
                {
                    throw new System.InvalidOperationException("Duplicate key");
                }

                location = (h + i) % m;
            }
            Console.WriteLine("table is full : item can't be inserted ");
        }