Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Please. Also, the code should have two methods called removeRepetitions and printRange. Please post code with output and I will leave a thumbs up.

Java Please. Also, the code should have two methods called removeRepetitions and printRange. Please post code with output and I will leave a thumbs up.

image text in transcribedimage text in transcribed

Write a program that creates a linked list of integers, assigns integers to the linked list, prints a range of values in the list and eliminates duplicate numbers in the list. Your program must have two methods First method is called printRange which has two parameters, x and y. printRange should write out all integers in the list that are between the first occurrence of x (inclusive) and the first occurrence of y (but not including y). You may assume integers can be compared for equality using == Use the following header for the method: void printRange (int x, int y); . Use the following logic to develop printRange This makes the implementation easier. Print integers from x to y including x but not including y y If there isn't an entry with a value equal to x, then print nothing If there isn't an entry after x, that has a value equal to y, then print the integers from x (inclusive) to the end of the list Print the values on one line separated by space. Put an end of line after the values are ALL printed. Hint, your program will need to make multiple calls to printRange For this program, you are [hard coding] creating your data in the program, and not entering it from the console. In your program create a linked list with the following members: {1, 1, 2, 3, 3, 75, 4, 4, 8, 9). Review the sample output below. You MUST USE the values for x and y, shown (shown in bold) as parameters in multiple calls to printRange to test the logic of your program Below is a sample output. // Comments List [1,2,3,4,5,6,7] Il x = 2 y = 5 prints 234 // prints list including x but not y List[1,2,3,4,5,6,7] // x = 2 y = 78 prints 2 3 4 5 6 7 // prints list including x, no value sy so print to end List [1,2,3,4,5,6,7] // x = 2 y = 1 prints 234567 // prints list including x, no value Ey so print to end List[1,2,3,4,5,6,7] // x = 8 y = 5 1/ prints nothing The second method is called removeRepetitions. removeRepetitions steps through the linked list comparing numbers and when duplicate numbers are found, removes one of the duplicate numbers. Again, you may assume integers can be compared for equality using == Use the following header for the method removeRepetitions: void remove_repetitions() Here is a brief outline of an algorithm for removeRepetitions: variable p steps through the list for each number in the list, define a new variable q equal top While q is not the last number in the list If the next number has data equal to the data in p, remove the next number Otherwise move q to the next number

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 Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago