Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A Simple Set Data Structure To build a Set from scratch, first we must create the universe. Luckily, we can build it in Java, which

A Simple Set Data Structure

image text in transcribed

To build a Set from scratch, first we must create the universe. Luckily, we can build it in Java, which saves a lot of time. For this part, we will build a Simpleset class that implements the basic operations necessary for a functioning data structure. To keep things simple, we're only going to build sets that hold ints. To this end you need to create a class called SimpleSet with the following: A private array of ints called data that will hold the actual numbers. It will also need the following methods: A no-parameter constructor that initialises the array, and any other variables you might have. Amethod called add that takes a single int parameter, and puts it in data if it's not there, but does nothing if it's already there. A method called remove that takes a single int parameter that removes that value if it's in data, but does nothing if it's not there. Amethod call contains that takes a single int and returns true if that element is in the set, and false otherwise. A method called size that returns the number of elements in the set. A method called isEmpty that returns true if there are no elements in the set, and false otherwise A method called to Array that returns an array containing exactly the elements of the set. A toString method that returns a String representation of the SimpleSet in the format' {x, y, z, ...}" where x, y, z, ... are replaced with the actual elements of the set. When implementing these, you may want to think about the following questions: How big should data be? What happens when data is full and we add a new element? What happens to the elements stored in data when we remove one? Is the size of the set the same as the length of data ? You have seen answers to these questions throughout the workshops and lectures, so think about where we might have done similar things before. Note that there is more than one right answer, the point here is for you to think about what you're trying to do, and pick a consistent approach. Note that there is a main method provided in the Runner class, but this does not form part of the tests, it's just there so you can run your code and test it manually. Finally, but not least, as the point here is for you to implement your own data structure an learn about how these things actually work

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

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

Differentiate the function. r(z) = 2-8 - 21/2 r'(z) =

Answered: 1 week ago

Question

=+Understand the fi eld of comparative IHRM.

Answered: 1 week ago

Question

=+j Understand different types of regions in the world.

Answered: 1 week ago