This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I am working with building Hash Tables, with Linear Probing and I have three class files.
The first is a driver file that calls the super class HashTable.
It generates random values to fit the size of the hash table indicated in the driver file
Here is the code snippet from the driver file:
It first creates a new object called HTable which is the super class in my other class files...
and then generate random values denoted by n of how many items to insert.
It calls my "insert" method in my subclass for Linear Probing...
My problem is, in my subclass for LPTable...
I need to generate the array of values of the number of items to insert, but when I create the data array, it is only inserting one value...
I believe it is my placement of the creation of the data array in my subclass...
Here is my subclass and what I have...
I need to generate the complete data array of all the values so that I can perform the hash table functions, but I also want to print out the data array to test to see they are all there...
Here is my SuperClass code snippet:
Here is my subclass code:
When I run my program right now, it only inserts one value...i need to insert all random values in ONE call, and then I want to print the result to see that it performed the operation correcltly.
Any help would be appreciated..I think it my placement of the declarations of the array and the call to insert but I'm not sure.
*confused* But LPT is a local variable in the driver--how does a subclass have access to it?
That aside--I don't see how to help; unless your loop isn't executing as many times as you think it is, or the key you're adding is always the same, from the code given, there's no reason it would be only "inserting once". So there's some other logical error not contained in the code provided. Since we can't run it, there's nothing we can do except guess.
Joined: May 31, 2010
Here are the files, I tried to attach them but it wouldn't let me attach in .java or .txt format...
A warning that it prints the entire hash for every single insert would have been in order :( Not cool.
Now: what makes you think there's only a single insert happening, which the deluge of S.o.p's gives lie to? And what is the point of the following method, apparently used to determine if something is found in the hash table?Will this ever indicate that a key is found?
- Pick spaces, or tabs, but not both.
- Remove code that isn't used.
- Remove code that *is* used, but is superfluous.
- Remove excess blank lines.
- Remove comments that do not add to understanding.
- Start with much, much smaller values until you actually know it works, otherwise debug runs take too long.
- Why does the subclass have its own probe count? But return the superclass's prob count?
- Why does LPT re-implement h() with the same implementation?
- What's the difference between LPT's arraySize and HTable's size?
- Why does LPT.insert2() create a new array list? Named hash? Of the same size as the item you're inserting?
- Why does the program attempt to write to ofile even if there's an exception?
- Why is the average/etc. shown for every findrun rather than at the end of all of them?
(Also, Java conventions state that classes should begin with a capital letter, and non-final variables begin with lower-case letters. Following the conventions makes your code easier to read for other Java programmers :)
LPTable seems to be a mish-mash of nonsensical code; what specifically are you trying to do? You might want to consider starting over, taking care to keep only the code you actually need and know to work correctly.