public class NewVector { Node headNode = null; public void addElement(Object obj) { //Adds a new Object at the end of the list. if (headNode == null) { headNode = new Node(obj); } else { Node vectorNode; vectorNode = headNode; while(vectorNode.nextNode != null) { vectorNode = vectorNode.nextNode; } vectorNode.nextNode = new Node(obj); } } public void insertElementAt(Object obj, int index) { //Inserts a new Object at the position indicated by the index. Objects after that position //are moved up by one index position. index = 0; Node currentNode = headNode; for (int i=0; i <= size(); i++) { currentNode.obj = currentNode.nextNode.obj; index ++; } Node newNode = new Node(obj); newNode = headNode; while(!(newNode.obj == currentNode.obj || newNode == null)) { newNode.obj = newNode.nextNode.obj; if(newNode == null) { return; } Node vectorNode = new Node(obj); vectorNode.nextNode = newNode.nextNode; newNode.nextNode = vectorNode; } } public void setElementAt(Object obj, int index) { // Inserts a new Object at the position indicated by the index by overwriting any existing // Object at that position. } /* public Object elementAt(int index) { return obj; // Returns the Object located at the position indicated by the index. } */ public void remove(int index) { // Removes the Object located at the position indicated by the index. All Objects after that // position are moved down by one index position } public int size() { Node currentNode = headNode; int x= 200; int size=0; while (currentNode != null && size < x) { currentNode = currentNode.nextNode; size++; } return size; } public Object indexOf(Object obj) { // returns the index of the first occurrence of the Object obj. return obj; } public String toString() { String str = ""; Node currentNode; currentNode = headNode; if (headNode!=null) do { str += currentNode.obj + "\n"; currentNode = currentNode.nextNode; } while (currentNode!=null); return str; } }