-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListClient.java
58 lines (51 loc) · 1.71 KB
/
ListClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//-----------------------------------------------------------------------------
// ListClient.java
// A test client for the List ADT. Use this to test your list module. The
// correct output is given below.
//-----------------------------------------------------------------------------
public class ListClient{
public static void main(String[] args){
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.moveFront(); A.index()>=0; A.moveNext()){
System.out.print(A.get()+" ");
}
System.out.println();
for(B.moveBack(); B.index()>=0; B.movePrev()){
System.out.print(B.get()+" ");
}
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.moveFront();
for(int i=0; i<5; i++) A.moveNext(); // at index 5
A.insertBefore(-1); // at index 6
for(int i=0; i<9; i++) A.moveNext(); // at index 15
A.insertAfter(-2);
for(int i=0; i<5; i++) A.movePrev(); // at index 10
A.delete();
System.out.println(A);
System.out.println(A.length());
A.clear();
System.out.println(A.length());
}
}
// Output of this program:
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// false
// false
// true
// 1 2 3 4 5 -1 6 7 8 9 11 12 13 14 15 -2 16 17 18 19 20
// 21
// 0