public void quadraticHashInsert(int key) { //quadratic probing method if (!checkOpenSpace())//if no open spaces available { Console.WriteLine("table is at full capacity!"); return; } if (Search(key)) { Console.WriteLine("Key already exists!"); return; } int j = 0; int hash = HashTabQuadProb.hash(key); while (table[hash] != null) { j++; hash = mod((HashTabQuadProb.hash(key) + (j * j)), maxSize); if (table[hash] != null) { hash = mod((HashTabQuadProb.hash(key) + ((j * j) * -1)), maxSize); } } if (table[hash] == null) { table[hash] = new HashProbe(key, key); return; } }
public bool Search(int key) { int j = 0; int hash = HashTabQuadProb.hash(key); while (table[hash] != null && table[hash].getkey() != key) { j++; hash = mod((HashTabQuadProb.hash(key) + (j * j)), maxSize); if (table[hash] != null) { hash = mod((HashTabQuadProb.hash(key) + ((j * j) * -1)), maxSize); } } if (table[hash] == null) { return(false); } else { Console.WriteLine("Der Schlüssel " + key + " ist im folgenden hash gespeichert: " + hash); return(true); } }
public bool Delete(int key) { int j = 0; int hash = HashTabQuadProb.hash(key); while (table[hash] != null && table[hash].getkey() != key) { j++; hash = mod((HashTabQuadProb.hash(key) + (j * j)), maxSize); if (table[hash] != null) { hash = mod((HashTabQuadProb.hash(key) + ((j * j) * -1)), maxSize); } } if (table[hash] == null) { return(false); } else { table[hash] = null; return(true); } }