Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int HashInsert(int key, HashSlot hashTable[])
- {
- int index, prevIndex = -1, counter = 0;
- index = hash(key);
- if (hashTable[index].indicator == EMPTY) {
- hashTable[index].key = key;
- hashTable[index].indicator = USED;
- hashTable[index].next = -1;
- return index;
- } else if (hashTable[index].indicator == USED) {
- if (HashFind(key,hashTable) != -1) return -1;
- while (counter < TABLESIZE) {
- counter++;
- if (hashTable[index].next == -1) {
- if (prevIndex == -1) prevIndex = index;
- index = hash(index+1);
- }
- if (hashTable[index].next != -1) {
- index = hashTable[index].next;
- }
- if (hashTable[index].indicator == EMPTY) {
- hashTable[prevIndex].next = index;
- hashTable[index].key = key;
- hashTable[index].indicator = USED;
- hashTable[index].next = -1;
- return index;
- }
- }
- }
- return counter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement