Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Collection Programming Write a program that takes as a parameter a Set of Integers. From that Set the method should remove the smallest integer in

Collection Programming

Write a program that takes as a parameter a Set of Integers. From that Set the method should remove the smallest integer in the set and return that integer. Example: A Set called s contains the following values: s = {3, 4, 5, 8, 9, 12, 14, 13 , 1, 2, 0, 20}. After calling z = removeMin(s) the returned set should contain the following values: s = {3, 4, 5, 8, 9, 12, 14, 13 , 1, 2, 20}. And the value 0(zero) should be returned and put into z. Note: as the set may be a hashSet, you cannot assume that the first element is the smallest.

Main program:

Set x1 = new HashSet<>();

x1.add(3);

x1.add(4);

x1.add(5);

x1.add(8);

x1.add(9);

x1.add(12);

x1.add(14);

x1.add(13);

x1.add(1);

x1.add(2);

x1.add(0);

x1.add(20); System.out.println("Before : " +x1);

int ans = removeMin(x1);

System.out.println("Removed : " ans);

System.out.println("After : " +x1);

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

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

What do you think Katsoudas means by the phrase one size fits one?

Answered: 1 week ago