-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathLinkedListClient.java
74 lines (55 loc) Β· 1.4 KB
/
LinkedListClient.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package Lecture18;
public class LinkedListClient {
public static void main(String[] args) throws Exception {
LinkedList list = new LinkedList();
System.out.println("list is empty: " + list.isEmpty());
System.out.println("size of list: " + list.size());
list.addFirst(10);
list.addFirst(5);
list.display();
list.addLast(50);
list.addLast(60);
list.display();
System.out.println("size of list: " + list.size());
list.addNodeAt(2, 30);
list.display();
System.out.println(list.getAt(3));
list.addNodeAt(3, 40);
list.display();
System.out.println(list.getFirst());
System.out.println(list.getLast());
System.out.println("list is empty: " + list.isEmpty());
System.out.println("size of list: " + list.size());
list.display();
System.out.println("removed first node data: " + list.removeFirst());
list.display();
list.removeLast();
list.display();
list.addNodeAt(1, 20);
list.addNodeAt(2, 25);
list.display();
System.out.println("removing at 2nd index: " + list.removeAt(2));
list.display();
}
}
/* output:
list is empty: true
size of list: 0
5=>10=>END
5=>10=>50=>60=>END
size of list: 4
5=>10=>30=>50=>60=>END
50
5=>10=>30=>40=>50=>60=>END
5
60
list is empty: false
size of list: 6
5=>10=>30=>40=>50=>60=>END
removed first node data: 5
10=>30=>40=>50=>60=>END
10=>30=>40=>50=>END
10=>20=>25=>30=>40=>50=>END
removing at 2nd index: 25
10=>20=>30=>40=>50=>END
*/