Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.AbstractCollection; import java.util.Iterator; /** * Instances of this class are used to represent a multiset -- a searchable collection in which one can add

 import java.util.AbstractCollection; import java.util.Iterator; /** * Instances of this class are used to represent a multiset -- a searchable collection in which one can add multiple * copies of an element. * @param Element type for this collection */ @SuppressWarnings({"unused", "unchecked"}) public class ArrayMultiSet extends AbstractCollection { private E[] _store; private int _size; private long _modCount; private static final int DEFAULT_BACKING_STORE_LENGTH = 12; public ArrayMultiSet() { _store = (E[])new Object[DEFAULT_BACKING_STORE_LENGTH]; } /** * Create a new multiset instance. The multiset's backing store will need to be allocated with a length equal to the length of {@code initialArray}. * The multiset's elements should be aliases for the entries in {@code initialArray}. * Prerequisite: {@code initialArray} CANNOT be null. * * @param initialArray Array containing the initial elements for our ArrayMultiSet. */ public ArrayMultiSet(E[] initialArray) { } @Override public boolean isEmpty() { return _size == 0; } @Override public int size() { return _size; } /** * Returns a newly allocated array containing the elements in the Multiset. The returned array should have a length equal to the * current size of the ArrayMultiSet. * * @return Newly allocated array whose entries are aliases to the elements in the Multiset. */ @Override public E[] toArray() { } } 

Help me complete:

ArrayMultiSet constructor -- the constructor has a single parameter that is an array of generic type named initialArray. The constructor will allocate a new array with a length equal to the length of initialArray to be used by the backing store. You should then set the size of the multiset equal to the length of initialArray. Finally, assign the entries in the backing store to alias the entries in initialArray.

toArray() -- this method returns a newly allocated array containing the elements in the multiset. The array this method returns must only contain the elements in the multiset and not any nulls or other values that are stored in the backing store, but are not in the multiset.

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

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

Students also viewed these Databases questions

Question

What are negative messages? (Objective 1)

Answered: 1 week ago

Question

Ty e2y Evaluate the integral dy

Answered: 1 week ago