Esempio n. 1
0
  /** A testing method */
  public static void main(String[] args) {

    MyLinkedList<Integer> aList = new MyLinkedList<Integer>();

    for (int i = 0; i < 10; i++) {
      aList.addNode(i);
    }

    Node<Integer> aNode = aList.head;
    while (aNode != null) {
      System.out.print(aNode.data + " ");
      aNode = aNode.next;
    }
    System.out.println();

    System.out.println("Contains 7 (true): " + aList.contains(7));
    System.out.println("Contains 13 (false): " + aList.contains(13));

    aList.removeLast();

    System.out.println("Contains 9 (false): " + aList.contains(9));

    Node<Integer> bNode = aList.head;
    while (bNode != null) {
      System.out.print(bNode.data + " ");
      bNode = bNode.next;
    }
    System.out.println();

    MyLinkedList<String> bList = new MyLinkedList<String>();
    for (int j = 0; j < 6; j++) {
      bList.addNode("string number " + j);
    }
    Node<String> cNode = bList.head;
    while (cNode != null) {
      System.out.println(cNode.data);
      cNode = cNode.next;
    }
  }