Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

mplement the squeeze() method in the provided ArraySqueeze class so that it performs as indicated in the comment. The main() method in this class runs

mplement the squeeze() method in the provided ArraySqueeze class so that it performs as indicated in the comment. The main() method in this class runs some test cases on squeeze(). You should also add a few nontrivial and interesting test cases of your own at the end of main().

PLEASE TRY TO KEEP IT LESS THAN 10 LINES O(n)

public class ArraySqueeze { /** * squeeze() takes an array of ints. On completion the array contains the * same numbers, but wherever the array had two or more consecutive * duplicate numbers, they are replaced by one copy of the number. Hence, * after squeeze() is done, no two consecutive numbers in the array are the * same. * * Any unused elements at the end of the array are set to -1. * * For example, if the input array is [ 4 , 1 , 1 , 3 , 3 , 3 , 1 , 1 ], it * reads [ 4 , 1 , 3 , 1 , -1 , -1 , -1 , -1 ] after squeeze() completes. * * @param ints * the input array. */ public static void squeeze(int[] ints) { // TODO: Fill in your solution here. Ours takes linear time and is less than 10 lines long, // not counting blank/comment lines or lines already present in this file. } /** * main() runs test cases on your squeeze() method. Prints summary * information on basic operations and halts with an error (and a stack * trace) if any of the tests fail. */ public static void main(String[] args) { String result; System.out.println("Let's squeeze arrays! "); int[] test1 = {3, 7, 7, 7, 4, 5, 5, 2, 0, 8, 8, 8, 8, 5}; System.out.println("squeezing " + TestHelper.stringInts(test1) + ":"); squeeze(test1); result = TestHelper.stringInts(test1); System.out.println(result + " "); TestHelper.verify(result.equals( "[ 3 , 7 , 4 , 5 , 2 , 0 , 8 , 5 , -1 , -1 , -1 , -1 , -1 , -1 ]"), "BAD SQEEZE!!! No cookie."); int[] test2 = {6, 6, 6, 6, 6, 3, 6, 3, 6, 3, 3, 3, 3, 3, 3}; System.out.println("squeezing " + TestHelper.stringInts(test2) + ":"); squeeze(test2); result = TestHelper.stringInts(test2); System.out.println(result + " "); TestHelper.verify(result.equals( "[ 6 , 3 , 6 , 3 , 6 , 3 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ]"), "BAD SQEEZE!!! No cookie."); int[] test3 = {4, 4, 4, 4, 4}; System.out.println("squeezing " + TestHelper.stringInts(test3) + ":"); squeeze(test3); result = TestHelper.stringInts(test3); System.out.println(result + " "); TestHelper.verify(result.equals("[ 4 , -1 , -1 , -1 , -1 ]"), "BAD SQEEZE!!! No cookie."); int[] test4 = {0, 1, 2, 3, 4, 5, 6}; System.out.println("squeezing " + TestHelper.stringInts(test4) + ":"); squeeze(test4); result = TestHelper.stringInts(test4); System.out.println(result + " "); TestHelper.verify(result.equals("[ 0 , 1 , 2 , 3 , 4 , 5 , 6 ]"), "BAD SQEEZE!!! No cookie."); System.out.println(" Additional tests done by the student or TA: "); // Insert your additional test cases here. } }

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 3 Lnai 6323

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

3642159389, 978-3642159381

More Books

Students also viewed these Databases questions

Question

What are some examples where recurrent neural networks can be used?

Answered: 1 week ago

Question

Assess three steps in the selection process.

Answered: 1 week ago

Question

Identify the steps in job analysis.

Answered: 1 week ago