package set; // int형 집합 클래스 만들기 public class IntSet { private int max; // 집합의 최대 기수 private int num; // 집합의 요소 개수 private int[] set; // 집합 본체 // 생성자 public IntSet(int capacity) { max = 0; max = capacity; try { set = new int[max]; // 집합 배열 생성 } catch(OutOfMemoryError e) { // 배열의 생성 실패 max = 0; } } // 집합의 최대 개수 public int capacity() { return max; } // 집합의 요소 개수 public int size() { return num; } // 집합에서 n을 검색합니다(index 반환) public int indexOf(int n) { for(int i=0; i= max || contains(n) == true) return false; // 가득 찼거나 이미 n이 존재 else { set[num++] = n; // 가장 마지막 자리에 추가 return true; } } // 집합에서 n을 삭제 public boolean remove(int n) { int idx; // n이 저장된 요소의 인덱스 if(num <= 0 || (idx = indexOf(n)) == -1) return false; // 비어 있거나 이미 n이 존재 else { set[idx] = set[--num]; // 마지막 요소를 삭제한 곳으로 옮긴다 return true; } } // 집합 s에 복사 public void copyTo(IntSet s) { int n = (s.max < num) ? s.max : num; // 복사할 요소 개수 for(int i=0; i