Exemplo n.º 1
0
        public void Delete(int key)
        {
            int hash = hashFunc(key);
            HashtableDataItem head = table[hash];
            HashtableDataItem prev = null;

            while (head != null)
            {
                if (head.getKey().Equals(key))
                {
                    break;
                }
                prev = head;
                head = head.next;
            }
            if (head == null)
            {
                throw new Exception("Exception: there is no such element in hashtable");
            }
            if (prev != null)
            {
                prev.next = head.next;
            }
            else
            {
                table[hash] = head.next;
            }
        }
Exemplo n.º 2
0
        public double Search(int key)
        {
            int hash = hashFunc(key);
            HashtableDataItem head = table[hash];

            while (head != null)
            {
                if (head.getKey().Equals(key))
                {
                    return(head.getValue());
                }
                head = head.next;
            }
            throw new Exception("Exception: there is no such element in hashtable");
        }
Exemplo n.º 3
0
        public void Insert(double value, int key)
        {
            int hash = hashFunc(key);
            HashtableDataItem head = table[hash];

            while (head != null)
            {
                if (head.getKey().Equals(key))
                {
                    head.setValue(value);
                    return;
                }
                head = head.next;
            }
            head = table[hash];
            HashtableDataItem newItem = new HashtableDataItem(value, key, head);

            table[hash] = newItem;
        }