Exemplo n.º 1
0
 public T set(int index, T newValue) {
   if (index >= size || index < 0) {
     throw new IndexOutOfBoundsException();
   }
   LNode current = start;
   for (int i = 0; i < index; i++) {
     current = current.getNext();
   }
   T oldValue = current.getValue();
   current.setValue(newValue);
   return oldValue;
 }
Exemplo n.º 2
0
 public void set(int pos, T value) {
   int index = 0;
   LNode temp = start;
   if (size == 0) {
     throw new NoSuchElementException();
   }
   if (pos < 0 || pos >= getSize()) {
     throw new IndexOutOfBoundsException();
   }
   while (index != pos) {
     index++;
     temp = temp.getNext();
   }
   temp.setValue(value);
 }