Question: Write in Java please!! Implement your own data structure in the new class DataStructure . DataStructure implements DataStructureADT and does not have any public or

Write in Java please!!

Implement your own data structure in the new class DataStructure . DataStructure implements DataStructureADT and does not have any public or package level fields, methods, or inner classes. Define an inner class for storing key and value as a pair. The inner class and its members should be private as well.

DataStructureADT:

/** * A data structure that can store at least 500 key,value pairs. * May not use any of Java's built-in Java collection types: such as: List, ArrayList, LinkedList, etc... But could use arrays. * May not add any public members (fields, methods, inner classes) * @param The key must not be null and must be Comparable. * @param The data value associated with a given key. */ public interface DataStructureADT, V> {

// Add the key,value pair to the data structure and increases size. // If key is null, throws IllegalArgumentException("null key"); // If key is already in data structure, throws RuntimeException("duplicate key"); // can accept and insert null values void insert(K key, V value);

// If key is found, Removes the key from the data structure and decreases size // If key is null, throws IllegalArgumentException("null key") without decreasing size // If key is not found, returns false. boolean remove(K key);

// Returns the value associated with the specified key // get - does not remove key or decrease size // If key is null, throws IllegalArgumentException("null key") V get(K key);

// Returns true if the key is in the data structure // Returns false if key is null or not present boolean contains(K key);

// Returns the number of elements in the data structure int size();

}

The new class DataStructure implements DataStructureADT and has all the same methods as in DataStructureADT but by overriding (same method header, different content).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!