SortedArrayMultiSet

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 DocumentRight 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++)
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.

This note was uploaded on 04/13/2011 for the course ENGR 202 taught by Professor Yavuzyildirim during the Spring '11 term at Boğaziçi University.

Page1 / 6

SortedArrayMultiSet - package comp202; import...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online