src/com/michaelho/RandomizedAlgorithms/RA3.java
// Method to remove a given key
Method to remove a given key
Method to remove a given key
public V remove(K key) {
            int bucketIndex = hash(key);
            HashNode<K, V> head = bucketArray.get(bucketIndex);
            HashNode<K, V> prev = null;
            while (head != null) {
                if (head.key.equals(key))
                    break;
                prev = head;
                head = head.next;
            }
            if (head == null)
                return null;
            size--;
            if (prev != null)
                prev.next = head.next;
            else
                bucketArray.set(bucketIndex, head.next);
            return head.value;
        }
public V remove ( K key ) { int bucketIndex = hash ( key ) ; HashNode < K , V > head = bucketArray . get ( bucketIndex ) ; HashNode < K , V > prev = null ; while ( head != null ) { if ( head . key . equals ( key ) ) break ; prev = head ; head = head . next ; } if ( head == null ) return null ; size -- ; if ( prev != null ) prev . next = head . next ; else bucketArray . set ( bucketIndex , head . next ) ; return head . value ; }
Method to remove a given key
Method to remove a given key
// Get head of chain // Search for key in its chain // If Key found // Else keep moving in chain // If key was not there // Reduce size // Remove key