Esempio n. 1
0
  public ReturnObject remove(int index) {
    ErrorMessage em = this.testBounds(index);
    if (em.toString() != "NO_ERROR") return new ReturnObjectImpl(em);

    if (index == 0) {
      ReturnObject result = this.object;
      if (this.next == null) {
        this.object = null;
      } else {
        this.object = this.next.getObject();
        this.next = this.next.getNext();
      }
      return result;
    }

    LinkedList current = this;
    LinkedList last = current;
    for (int i = 0; i < index; i++) {
      last = current;
      current = current.next;
    }

    last.next = current.next;

    return current.object;
  }
Esempio n. 2
0
  public ReturnObject get(int index) {
    ErrorMessage em = this.testBounds(index);
    if (em.toString() != "NO_ERROR") return new ReturnObjectImpl(em);

    LinkedList current = this;
    for (int i = 0; i < index; i++) {
      current = current.next;
    }

    return current.object;
  }