/* * MyList.java * * Created on November 25, 2004, 5:13 PM */ /** * * @author levenick */ import java.util.*; /** * An implementation of a variable sized list of ints. * * It uses an array and a variable, last, that holds the index of the * last entry in the array (all the entries are kept at the beginning of * the array. */ public class MyIntVectorList { Vector list; /** Creates a new instance of List */ public MyIntVectorList() { list = new Vector(); } /** * see return * @return returns the element at the passed index * @param i is the index */ public int elementAt(int i) { return ((Integer) list.elementAt(i)).intValue(); } /** * Replaces the element at the index with the passed value */ public void replaceElementAt(int nuValue, int i) { list.setElementAt(new Integer(nuValue), i); } /** * Removes the element at the passed index. */ public void removeElementAt(int removalIndex) { list.removeElementAt(removalIndex); } /** * Adds an element at a particular index. * * Values from there down are first shifted down one. * * Last is incremented (since there is one more thing in the list). * @param insertMe the new int value to be inserted * @param putHereIndex where to put the value */ public void addElementAt(int insertMe, int putHereIndex) { list.insertElementAt(new Integer(insertMe), putHereIndex); } public void addElement(int nu) { list.addElement(new Integer(nu)); } /** * * @return */ public int length() { return list.size(); } public void makeEmpty() { list.removeAllElements(); } public String toString() { String returnMe="MyIntVectorList: {"; for (Iterator it=list.iterator(); it.hasNext();) returnMe += "," + it.next().toString(); return returnMe + "}"; } }