-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestGeneric.java
More file actions
61 lines (50 loc) · 2.4 KB
/
TestGeneric.java
File metadata and controls
61 lines (50 loc) · 2.4 KB
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
58
59
60
61
public class TestGeneric {
public static void main(String[] args) {
// We create a DoublyLinkedList for Integer and one for String
DoublyLinkedList<Integer> integerList = new DoublyLinkedList<Integer>();
DoublyLinkedList<String> stringList = new DoublyLinkedList<String>();
// We add Integers
integerList.add(34);
integerList.add(67);
System.out.println("Integer Linked List:");
System.out.println(" ----- " + integerList);
stringList.add("abc");
stringList.add("test");
System.out.println("String Linked List:");
System.out.println(" ----- " + stringList);
// We test opposite adding
integerList.addOppositeSide(33);
System.out.println("33 is appended at the end:");
System.out.println(" ----- " + integerList);
stringList.addOppositeSide("33");
System.out.println("\"33\" is appended at the end:");
System.out.println(" ----- " + stringList);
// We test searchAndRemove
integerList.searchAndRemove(33);
System.out.println("33 removed:");
System.out.println(" ----- " + integerList);
stringList.searchAndRemove("hello");
System.out.println("hello (that is not in the list) removed:");
System.out.println(" ----- " + stringList);
// We test the search
System.out.println("We search for 34 (int)");
System.out.println(" ----- " + integerList.search(34));
System.out.println("We search for \"abc\"");
System.out.println(" ----- " + stringList.search("abc"));
System.out.println("We search for \"isItHere\"");
System.out.println(" ----- " + stringList.search("isItHere?"));
// We test the remove
integerList.removeAt(1);
System.out.println("We remove the second element (integerList):");
System.out.println(" ----- " + integerList);
stringList.removeAt(stringList.getSize() - 2);
System.out.println("We remove the second to last element (stringList):");
System.out.println(" ----- " + stringList);
// We test getFirst.
// We do not need to cast anymore
String elem1 = stringList.getFirst();
System.out.println("First element in stringList ---> " + elem1);
Integer elem2 = integerList.getFirst();
System.out.println("First element in integerList ---> " + elem2);
}
}