public T getData(int index) {
   LLNode<T> node = head;
   if (index < 0) return null;
   for (int i = 0; i < index; i++) {
     node = node.getPointer();
   }
   return node.getData();
 }
 public String toString() {
   String line = "";
   LLNode<T> current = head;
   while (current != null) {
     line += current.getData().toString() + ",";
     current = current.getPointer();
   }
   return line;
 }
Exemple #3
0
  public String toString() {
    String response;
    response = new String("[");
    if (n == 0) return response;
    else {
      LLNode temp;
      temp = head;

      for (int i = 0; i < n; i++) {
        // System.out.print(temp.getData());
        // System.out.print(" ");
        if (i != n - 1) response += temp.getData() + ", ";
        else response += temp.getData();
        temp = temp.next;
      }
    }
    response += "]";
    return response;
  }
Exemple #4
0
  public void print() {
    if (n == 0) System.out.println("Empty List");
    else {
      LLNode temp;
      temp = head;

      for (int i = 0; i < n; i++) {
        System.out.print(temp.getData());
        System.out.print(" ");
        temp = temp.next;
      }
    }
    System.out.print("\n");
  }