Exemplo n.º 1
1
  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);

    */

  }
  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
  }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
1
 void add(List other) {
   for (int i = 0; i < other.length(); i++) {
     _add(other.item(i));
   }
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
public static String toString(List L) {
  // Save the current position of the list
  int oldPos = L.currPos();
  StringBuffer out = new StringBuffer((L.length() + 1) * 4);

  L.moveToStart();
  out.append("< ");
  for (int i = 0; i < oldPos; i++) {
    out.append(L.getValue());
    out.append(" ");
    L.next();
  }
  out.append("| ");
  for (int i = oldPos; i < L.length(); i++) {
    out.append(L.getValue());
    out.append(" ");
    L.next();
  }
  out.append(">");
  L.moveToPos(oldPos); // Reset the fence to its original position
  return out.toString();
}
Exemplo n.º 7
0
 @Test
 public void NumberOfFiles() {
   assertEquals(files.length(), 2);
 }
Exemplo n.º 8
0
 /**
  * The length of this list.
  *
  * @return The length of this list.
  */
 public int length() {
   return 1 + tail.length();
 }