sir how to insert as h[“Apple”] = 120
I am not understand
Insertion into hashtable using [] = operator
For operator overloading in hash maps [ ] , There can be two cases -:
- The key exist . So if the key exist , we return the original box - which has the value .
Suppose ,If the key value pair (Mango , 80) already exist in hash table. And if we do h[“Mango”] = 100 . So , h[“Mango”] returns the value by reference. - The key does not exist . So the key is created using insert function having key value as (key , garbage ) . Now that same key is searched in hash-map where it is created and the value is returned as reference . now this value is replaced by assignment = 120 .
The statement can be elaborated as -
h.operator - This returns the value of key apple by reference , and this is assigned as 120.
Hey Chandan, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.