Question: Define an ADT for a bag (see Section 2.1 ) and create an array-based implementation for bags. Be sure that your bag ADT does not
Define an ADT for a bag (see Section 2.1 ) and create an array-based implementation for bags. Be sure that your bag ADT does not rely in any way on knowing or controlling the position of an element. Then, implement the dictionary ADT of Figure 4.27 using your bag implementation.

/** The Dictionary abstract class. */ public interface Dictionary { }; /** Reinitialize dictionary */ public void clear(); /** Insert a record @param k The key for the record being inserted. @param e The record being inserted. */ public void insert (K k, E e); /** Remove and return a record. @param k The key of the record to be removed. @return A maching record. If multiple records match "k", remove an arbitrary one. Return null if no record with key "k" exists. */ public E remove (K k); /** Remove and return an arbitrary record from dictionary. @return the record removed, or null if none exists. */ public E removeAny (); /** @return A record matching "k" (null if none exists). If multiple records match, return an arbitrary one. */ public E find (K k); /** @return the number of records in the dictionary. */ public int size (); Figure 4.27 The abstract class definition for a simple dictionary.
Step by Step Solution
3.37 Rating (153 Votes )
There are 3 Steps involved in it
Heres an abstract data type ADT definition for a bag along with an arraybased implementation in Java ... View full answer
Get step-by-step solutions from verified subject matter experts
