Please help me , just explain the codes, what is happening at A B C like that. T
ID: 3839117 • Letter: P
Question
Please help me , just explain the codes, what is happening at A B C like that.
Thanks in advance.
LAB ASSIGNMENT
Complete Table Below:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
A
B
C
D
E
F
G
H
I
J
K
L
M
N
class LinkedHashEntry private int key: int value Linked HashEntry next: public Linked HashEntry (int key int value n this key key this value value this next int getKey return key: int getValue return value: void setValue int value this value value LinkedHashEntry getNext return next void setNext (LinkedHashEntry next) this next const int TABLE SIZE 128 class HashMap private Linked HashEntry table public HashMap table new LinkedHashEntr tTABLE-SIZEl: for int i 0: i TABLE SI2E: it table Di NULL: int get (int key) int hash key t TABLE SIZE if (table hash NULL) return -1 else LinkedHashEn entry tab while entry NULL & 6 entry->getKey entry entry->getNext if (entry NULL) return -1; else return entry->getValueExplanation / Answer
A : we declare Private instance variables as key , value and Next reference of type LinkedHasEntry
B : Parameterized Constructors that Initialises key , value and reference is NULL
C: these are accessor and mutator methods that does set and get operations also called getters and setters.
D : our Table SIZE is fixed constant of 128.
E: Default Constructor that Initialises Array to SIZE 128 and marks all those enteries as NULL
F :It comes in get metod, We do a modulo operation using 128 as our table size so that larger number also falls
within 0 to 127 to get the hash value.
G : During a get operation if we find key entry as NULL we return -1 saying key is not there else we try to find the entry
H :Its a PUT method, Where we add key and value by calculating HASH
I: if TABLE[hash] is NULL means none of the entries were der for that hash, so create a new LinkedHash with the key and value.
J : Otherwise some key has the same hash so we need to go till the end of the Linked hash and add the entry there if key is already there just update the value else create a new key value pair for same hash code
K :Removes method that removes the key
L :If the hash code matched i.e there is some entry with the SAME Hash Key , TRY TO SEarch the key and keep searching until we get the key or List is not NULL
M :if key is found and prev is NULL means its the first entry so delete it
otherwise link the prev entry to foundkey next entry and then delete the found entry.
N : this function helps us free the memory , Its a destructor that will check the allocated space. If the space is allocated free up the mempry and move to next and then free all the links . Then we delete the table as well which was allocated dynamically ..
Thanks, please rate and provide feedback.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.