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 ");
        }
Example #2
0
 public void Insert1(GroceryRecord newRecord)
 {
     if (n >= m / 2)
     {
         rehash(nextPrime(2 * m));
         Console.WriteLine("New List Size is : " + m);
     }
     Insert(newRecord);
 }
Example #3
0
        public GroceryRecord Delete(int key)
        {
            int h        = hash(key);
            int location = h;

            for (int i = 1; i < m; i++)
            {
                if (array[location] == null)
                {
                    return(null);
                }
                if (array[location].getgroceryId() == key)
                {
                    GroceryRecord temp = array[location];
                    array[location].setgroceryId(-1);
                    n--;
                    return(temp);
                }
                location = (h + i) % m;
            }
            return(null);
        }