Algorithmen & Datenstrukturen mit Java: Ein sehr einfacher erster Test |
1package tests.persistent.list;
2
3import ds.interfaces.List;
4import ds.util.E;
5
6import static ds.persistent.list.LinkedList.empty;
7import static ds.persistent.list.LinkedList.stats;
8import static ds.util.E.mkE;
9
10import static java.lang.System.out;
11
12public class LinkedList1 {
13 public static void main(String [] argv) {
14 List l = empty();
15
16 l = l.cons(mkE(4)).cons(mkE(3)).cons(mkE(2)).cons(mkE(1));
17 l = l.concat(l); // requires persistent concatenation !!!
18
19 out.println("");
20 out.println("l : " + l);
21 out.println("l.isEmpty() : " + l.isEmpty());
22 out.println("l.length() : " + l.length());
23 out.println("l.head() : " + l.head());
24 out.println("l.last() : " + l.last());
25 out.println("l.at(3) : " + l.at(3));
26 out.println("l.member(3) : " + l.member(mkE(3)));
27 out.println("l.member(9) : " + l.member(mkE(9)));
28
29 List l2 = l.tail();
30 out.println("l2 = l.tail() : " + l2);
31 out.println("l2.length() : " + l2.length());
32 out.println("l2.reverse() : " + l2.reverse());
33 out.println("l2 : " + l2);
34 out.println("l : " + l);
35 out.println("l.length() : " + l.length());
36
37 out.println("\n" + stats());
38 }
39}
1package tests.destructive.list;
2
3import ds.interfaces.List;
4import ds.util.E;
5
6import static ds.destructive.list.LinkedList.empty;
7import static ds.destructive.list.LinkedList.stats;
8import static ds.util.E.mkE;
9
10import static java.lang.System.out;
11
12public class LinkedList1 {
13 public static void main(String [] argv) {
14 List l = empty();
15
16 l = l.cons(mkE(4)).cons(mkE(3)).cons(mkE(2)).cons(mkE(1));
17 l = l.concat(l.copy()); // requires cloning before concat
18
19 out.println("l : " + l);
20 out.println("l.isEmpty() : " + l.isEmpty());
21 out.println("l.length() : " + l.length());
22 out.println("l.head() : " + l.head());
23 out.println("l.at(3) : " + l.at(3));
24 out.println("l.member(3) : " + l.member(mkE(3)));
25 out.println("l.member(9) : " + l.member(mkE(9)));
26
27 List l2;
28 out.println("l2 = l.tail() : " + (l2 = l.tail()));
29 out.println("l2 = l2.reverse() : " + (l2 = l2.reverse()));
30 out.println("l2.length() : " + l2.length());
31 out.println("l : " + l);
32
33 out.println("\n" + stats());
34 }
35}
|
Letzte Änderung: 22.10.2015 | © Prof. Dr. Uwe Schmidt |