given:
class Widget {
Object value;
}
interface WidgetMap {
void put( Widget key, Widget value );
Widget get( Widget key );
}
… how would I go about implementing WidgetMap using only Widget objects or primitives?
Without the use of other classes (toolkits, collections, JDK classes ). Primitive arrays would be allowed, but it would be better to do without them.
This is a map implemented as a linked list of
WidgetMap. It doesn’t strike me as terribly efficient, or useful, but it should function. I assume you also want aremovefunction, but I’ll leave that as an exercise. This also assumes you appropriately override theWidget.equalsfunction, though it should be trivial to fix it not to have that requirement.Working example code.