Last active
October 11, 2018 00:15
-
-
Save maurobaraldi/b1182d5e60a18ac80bc2b1216aa5cf6e to your computer and use it in GitHub Desktop.
Hashing Function Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hashtable; | |
public class HashTable { | |
public static int hashFunction(int value) { | |
return value % 10; | |
} | |
public static boolean hashInsert(int hashTable[], int value) { | |
int pos = hashFunction(value); | |
if (hashTable[pos] == 0) { | |
hashTable[pos] = value; | |
} else { | |
while(hashTable[pos]!=0){ | |
pos++; | |
} | |
hashTable[pos] = value; | |
} | |
return true; | |
} | |
public static void main(String[] args) { | |
int hashTable[] = new int[20]; | |
hashInsert(hashTable,222); | |
hashInsert(hashTable,322); | |
hashInsert(hashTable,719); | |
for(int i=0;i<10;i++){ | |
System.out.println(hashTable[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment