package wordlist;
import java.util.Iterator;

abstract public class WordArray implements Iterable<String> {
	
	protected String[] words;
	protected int numWords;
	
	public WordArray() {
		words = new String[8];
		numWords = 0;
	}
	
	protected boolean isFull() {
		return numWords == words.length;
	}
	
	protected void resize() {
                // Implement array resizing here
	}
	
	public boolean isSorted() {
   		// Implement a method that returns true iff the list is
		// sorted here
	}
	
	abstract public void add(String s); 

	public boolean contains(String s) {
		// Throw an exception if the array is not sorted.
		// Then do binary search.
	}

	@Override
	public Iterator<String> iterator() {
		return new Iter();
	}

	private class Iter implements Iterator<String> {
		private int i;
		
		public Iter() {
			i = 0;
		}

		@Override
		public boolean hasNext() {
			return i < numWords;
		}

		@Override
		public String next() {
			return words[i++];
		}

		@Override
		public void remove() {
			throw new UnsupportedOperationException();
		}
		
	}
}
