Пример #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;
            }
        }
Пример #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");
        }
Пример #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;
        }
Пример #4
0
 public HashtableDataItem(double value, int key, HashtableDataItem next)
 {
     this.value = value;
     this.key   = key;
     this.next  = next;
 }