Hi i have this program and i want to count and print the total steps that needed to complete the program when i'm running it 10 times. (count the total console lines)
Any advice is appreciated
The code of the Hash Table:
public class HashFunction {
String[] theArray;
int arraySize;
int itemsInArray = 0;
int K = 0;
/**
*
* @param args
*/
public static void main(String[] args) {
HashFunction theFunc = new HashFunction(101);
String[] elementsToAdd2 = new String[101];
for (int i = 0; i <= 100; i++) {
elementsToAdd2[i] = Integer.toString(RandomNumbers.getRandomNumberInRange(0, 15024267));
}
theFunc.hashFunction2(elementsToAdd2, theFunc.theArray);
}
public void hashFunction2(String[] stringsForArray, String[] theArray) {
for (int n = 0; n < stringsForArray.length; n++) {
String newElementVal = stringsForArray[n];
// Create an index to store the value in by taking
// the modulus
int arrayIndex = Integer.parseInt(newElementVal) % 101;
System.out.println("P" + arrayIndex + " " + "I" + newElementVal + "@" + arrayIndex );
// Cycle through the array until we find an empty space
while (theArray[arrayIndex] != "-1") {
++arrayIndex;
System.out.println( "P" + arrayIndex);
// If we get to the end of the bucket go back to index 0
arrayIndex %= arraySize;
}
theArray[arrayIndex] = newElementVal;
}
}
HashFunction(int size) {
arraySize = size;
theArray = new String[size];
Arrays.fill(theArray, "-1");
}
}
Program to run the class 10 times:
public class RunTenTimes
{
public static void main(String[] args)
{
for(int i=1; i<=10; i++)
HashFunction.main(args);
}
}
Should i add the code in the main class or in the RunTenTimes Class?
Aucun commentaire:
Enregistrer un commentaire