SortedArraySet - /*THIS CODE IS MY OWN WORK. I DID NOT...

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

View Full Document Right Arrow Icon
/*THIS CODE IS MY OWN WORK. I DID NOT CONSULT TO ANY PROGRAM WRITTEN BY OTHER STUDENTS. I READ AND FOLLOWED THE GUIDELINE GIVEN IN THE PROGRAMMING ASSIGNMENT. NAME: ERCAN YILMAZ */ package comp202; import java.util.ArrayList; import java.util.Comparator; import java.util.NoSuchElementException; public class SortedArraySet<AnyType> implements Set<AnyType> { private AnyType [ ] items ; private int theSize ; private Comparator<? super AnyType> cmp ; public SortedArraySet() { theSize = 0; items= (AnyType [])new Comparable [5]; cmp=null; } public SortedArraySet( Comparator<? super AnyType> c) { theSize = 0; items= (AnyType [])new Comparable [5]; cmp = c; } public boolean isEmpty() { return getSize()== 0; } public int getSize() { return theSize; } public boolean add ( AnyType x ) { if(contains(x)) return false; if( items.length == getSize() ) { doubleArray(); } int counter= theSize-1; items[theSize++]= x; while( { AnyType temp= items[counter]; items[counter]= x; items[counter+1]= temp;
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
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 301 taught by Professor Raultekin during the Spring '10 term at Boğaziçi University.

Page1 / 4

SortedArraySet - /*THIS CODE IS MY OWN WORK. I DID NOT...

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

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