import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* Description:
*
* @author Glenn Lancaster
* @version 15 May 07
*/
public class MyVector
{
private Object[] arr;
private int sz;
public MyVector()
{
sz = 0;
arr = new Object[10];
}
private void ensure(int newSize)
{
if ( newSize <= sz ) {
return;
}
Object[] tmp = new Object[newSize];
for(int i = 0; i < sz; i++) {
tmp[i] = arr[i];
}
arr = tmp;
}
public void add(Object x)
{
// precondition: sz < capacity
if ( sz >= arr.length ) {
ensure( 2 * sz );
}
arr[sz] = x;
sz++;
}
public int size()
{
return sz;
}
// New methods 5/22/207
public void set(int index, Object elem)
{
if ( index < 0 || index >= sz ) {
throw new IndexOutOfBoundsException();
}
arr[index] = elem;
}
public Object get(int index)
{
if ( index < 0 || index >= sz ) {
throw new IndexOutOfBoundsException();
}
return arr[index];
}
public Iterator