{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

SortedArrayMultiSet - package comp202 import...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
package comp202; p import java.util.Comparator ; import java.util.NoSuchElementException ; i public class SortedArrayMultiSet<AnyType> implements Set<AnyType> { public SortedArrayMultiSet ( ) { { cmp = null; items = (AnyType[]) new Object[5]; theSize = 0; } public SortedArrayMultiSet ( Comparator<? super AnyType> c ) { this.cmp = c; items = (AnyType[]) new Object[5]; theSize = 0; } public boolean isEmpty( ) { boolean flag = false; b if (theSize == 0){ i flag = true; f } return flag; } public int getSize( ) { return theSize; } public int add( AnyType x ) { if (!this.isEmpty()) { if( theSize + 1 == items.length ) { doubleArray( ); } AnyType[] temp = (AnyType [])new Object[ items.length]; int id = 0; i for (int i = 0; i < items.length; i++) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
if(items[i] != null ){ if ((compare(items[i], x) == 0) || (compare(items[i], x) < 0)) { temp[i] = items[i]; id = i; } } } if(id == 0){ temp[0] = x; t for(int j = id+1; j < temp.length-1; j++) { temp[j] = items[j-1]; } }else{ temp[id+1] = x; t for(int j = id+2; j < temp.length; j++) { temp[j] = items[j-1]; } } for(int k = 0; k < temp.length; k++) { items[k] = temp[k]; } theSize++; t } else { items[0] = x; theSize++; } return multiplicity(x); } public boolean remove( AnyType x ) { boolean flag = false; b for (int i = 0; i < items.length; i++)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}