Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions