template void Map2: :remove (K& key, K& keyFromMap, V& valueFromMap) MapPairReco
ID: 3701497 • Letter: T
Question
template void Map2: :remove (K& key, K& keyFromMap, V& valueFromMap) MapPairRecord x; Integer bucket Compare: :hashCode (key) % hashTableBounds::arraysize; while (!KCompare: :areEqual (key, map[bucket].front ().keyItem)) ( // The item you are looking for is in the current bucket // so do not increment bucket bucket++i I/ eliminate this line // what you want to do is to dequeue off of the front of the bucket // and then enqueue that item onto the back of the bucket so that // while loop conditional will test the next item in the bucket map[bucket].dequeue (x); keyFromMap.transferFrom(x. keyItem)i valueFromMap.transferFrom(x.valueItem)i mapSize--i // removeExplanation / Answer
here is your modified code : --------->>>>>>>>>
template<class K,class V,class KCompare>
void Map2<K,v,KCompare>::remove(K& key,k& keyFromMap,V& valueFromMap){
MapPairRecord x;
Integer bucket = KCompare::hashCode(key) % hashTableBounds::arraySize;
while(!KCompare::areEqual(key,map[bucket].front().keyItem)){
MapPairRecord temp = map[bucket].front();
map[bucket].dequeue(temp);
map[bucket].enqueue(temp);
}
map[bucket].dequeue(x);
keyFromMap.tranferFrom(x.keyItem);
valueFromMap.transferFrom(x.valueItem);
mapSize--;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.