public static void main(String[] args) {
    System.out.println("ListTest Compiled and running");

    List A = new List();
    List B = new List();

    for (int i = 1; i <= 20; i++) {
      A.append(i);
      B.prepend(i);
    }
    System.out.println(A);
    System.out.println(B);

    for (A.moveTo(0); A.getIndex() >= 0; A.moveNext()) {
      System.out.print(A.getElement() + " ");
    }
    System.out.println();
    for (B.moveTo(B.length() - 1); B.getIndex() >= 0; B.movePrev()) {
      System.out.print(B.getElement() + " ");
    }
    System.out.println();

    /*List C = A.copy();
    System.out.println(A.equals(B));
    System.out.println(B.equals(C));
    System.out.println(C.equals(A));*/

    A.moveTo(5);
    A.insertBefore(-1);
    A.moveTo(15);
    A.insertAfter(-2);
    A.moveTo(10);
    A.delete();
    System.out.println(A);
    A.clear();
    System.out.println(A.length());

    /*
    	List A = new List();
        List B = new List();
        List D = new List();

    	System.out.println(A.equals(D));
    	A.moveTo(5);
        System.out.println(D.equals(A));


        for(int i=1; i<=20; i++){
             A.append(i);
             B.prepend(i);
             D.append(i);
          }

          System.out.println(A);
          System.out.println(B);

    */

  }
Exemple #2
1
 public List concat(List L) {
   List lstOld = this.copy();
   for (int i = 0; i < L.length(); i++) {
     L.moveTo(i);
     lstOld.append(L.getElement());
   }
   return lstOld;
 }
  public static void main(String args[]) {
    List A = new List();
    for (int i = 1; i < 16; i++) {
      A.append(i);
    }
    System.out.println(A.toString());
    System.out.println(A.length());
    List B = new List();
    for (A.moveTo(0); A.getIndex() > -1; A.moveNext()) {
      B.prepend(A.getElement());
    }
    System.out.println(B.toString());
    System.out.println(B.length());
    System.out.println((int) A.front() + (int) B.front());
    System.out.println(A.back() == B.back());
    System.out.println(A.equals(B));
    System.out.println(A.equals(A));
    A.clear();
    System.out.println(A.length());
    A.append(3);
    A.prepend(1);
    A.prepend(1);
    A.append(7);
    A.moveTo(3);
    A.insertAfter(8);
    A.insertBefore(5);
    A.moveNext();
    A.insertAfter(13);
    A.movePrev();
    A.delete();
    System.out.println(A.toString());
    A.deleteFront();
    A.deleteBack();
    System.out.println(A.toString());

    // Should output:
    // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    // 15
    // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
    // 15
    // 16
    // false
    // false
    // true
    // 0
    // 1 1 3 5 8 13
    // 1 3 5 8
  }
Exemple #4
0
 public boolean equals(List L) {
   if (intLength == L.length()) {
     for (int i = 0; i < intLength; i++) {
       this.moveTo(i);
       L.moveTo(i);
       if (this.getElement() != L.getElement()) return false;
     }
     return true;
   } else return false;
 }