Java 具有线性探测和随机数的哈希表

Java 具有线性探测和随机数的哈希表,java,arrays,random,netbeans,hashtable,Java,Arrays,Random,Netbeans,Hashtable,嗨,我的任务是显示和计算将随机生成的键逐个插入初始空101 bucket哈希表所需的操作跟踪 我创建这个类是为了生成100个随机数,然后将它们插入哈希表类,但我不知道如何将它们插入哈希表,我是手动执行的。 如果你能给我一些建议,我将不胜感激 守则: import java.util.Random; public class RandomNumbers { static void main(String[] args) { throw new UnsupportedOperationEx

嗨,我的任务是显示和计算将随机生成的键逐个插入初始空101 bucket哈希表所需的操作跟踪

我创建这个类是为了生成100个随机数,然后将它们插入哈希表类,但我不知道如何将它们插入哈希表,我是手动执行的。
如果你能给我一些建议,我将不胜感激

守则:

import java.util.Random;

public class RandomNumbers {
static void main(String[] args) {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}




public RandomNumbers() {


    for (int i = 0; i < 100; i++) {
        System.out.println(getRandomNumberInRange(0, 15024267));
    }

}


public static int getRandomNumberInRange(int min, int max) {

    if (min >= max) {
        throw new IllegalArgumentException("max must be greater than min");
    }

    Random r = new Random();
    return r.nextInt((max - min) + 1) + min;
}

    String[] numbersPrinting;

}
import java.util.Random;
公共类随机数{
静态void main(字符串[]参数){
抛出新的UnsupportedOperationException(“尚未受支持”);//若要更改生成的方法体,请选择“工具”“模板”。
}
公众电话号码(){
对于(int i=0;i<100;i++){
System.out.println(getRandomNumberInRange(015024267));
}
}
公共静态int getRandomNumberInRange(int最小值,int最大值){
如果(最小值>=最大值){
抛出新的IllegalArgumentException(“最大值必须大于最小值”);
}
随机r=新随机();
返回r.nextInt((最大-最小)+1)+min;
}
字符串[]数字打印;
}
如你所见,我手动插入了随机数

哈希表代码:

import java.util.Arrays;

/**
 *
 *
 */
public class HashFunction {

String[] theArray;
int arraySize;
int itemsInArray = 0;
    int K = 0;

/**
 *
 */
public static void main(String[] args) {

    HashFunction theFunc = new HashFunction(101);


    String[] elementsToAdd2 = {"3638273","3483793","1362909","14908691","14624805","3959017","14208240","8911589","3701879", };


    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");

}
}
导入java.util.array;
/**
*
*
*/
公共类哈希函数{
字符串[]数组;
内部阵列化;
int itemsInArray=0;
int K=0;
/**
*
*/
公共静态void main(字符串[]args){
HashFunction theFunc=新的HashFunction(101);
字符串[]elementsToAdd2={“3638273”、“3483793”、“1362909”、“14908691”、“14624805”、“3959017”、“14208240”、“8911589”、“3701879”、};
函数hashFunction2(元素添加2,函数数组);
}
public void hashFunction2(字符串[]stringsforary,字符串[]数组){
对于(int n=0;n

我不知道如何将随机数类中的随机数插入到哈希表类中

我认为您应该做的是在
HashFunction
类的主函数中创建随机数:

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);

}
publicstaticvoidmain(字符串[]args){
HashFunction theFunc=新的HashFunction(101);
String[]elementsToAdd2=新字符串[101];

对于(int i=0;我感谢你这太棒了,你是对的,这就是方法。你知道如何计算操作的跟踪,我的意思是显示程序完成之前需要多少步骤。再次感谢你!!!!!