Began implementation of TestInterpolationSearch#runIntSearch
This commit is contained in:
parent
d31dbbb4d8
commit
b97fb17561
@ -6,12 +6,13 @@ public class TestInterpolationSearch {
|
||||
|
||||
/** Holds the list of 1024 unique values used to search through */
|
||||
public int[] values;
|
||||
|
||||
/** Holds the size of the table to generate */
|
||||
public int tableSize;
|
||||
|
||||
/**
|
||||
* Generates a list of 1024 random, non-repeating, integers and assigns them to the values field.
|
||||
*/
|
||||
public void RandomDistinct() {
|
||||
public void randomDistinct() {
|
||||
/* Used to track what ints have been used */
|
||||
HashSet<Integer> isUsed = new HashSet<>();
|
||||
int[] newList = new int[1024];
|
||||
@ -34,4 +35,17 @@ public class TestInterpolationSearch {
|
||||
Arrays.sort(newList);
|
||||
this.values = newList;
|
||||
}
|
||||
|
||||
public void runIntSearch() {
|
||||
int totalDivisions;
|
||||
Random rand = new Random();
|
||||
|
||||
System.out.println(" Key\t\tFound\t\tIndex\t\tDivisions");
|
||||
System.out.println("----------------------------------------------");
|
||||
for (int i = 0; i < this.tableSize; i++) {
|
||||
int key = rand.nextInt(9999) + 1;
|
||||
InterpolationSearch results = new InterpolationSearch(this.values, key);
|
||||
System.out.println(" " + key + "\t\t" + results.isFound() + "\t\t" + results.getIndex() + "\t\t" + results.getDivisions());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user