-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListDemo.java
More file actions
72 lines (54 loc) · 1.62 KB
/
LinkedListDemo.java
File metadata and controls
72 lines (54 loc) · 1.62 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
62
63
64
65
66
67
68
69
70
71
72
package datastructure.linkedlist;
public class LinkedListDemo {
public static void main(String[] args) {
LinkedList<String> list = new LinkedList<String>();
list.addFirst("gan");
list.addFirst("ann");
list.addLast("bob");
list.printContent();
/*
* try { list.removeLast(); } catch(NoSuchElementException e) {
* System.out.println(e.toString());
*
* }
*
*
* list.printContent();
*/
LinkedList<String> reverse = list.reverseList();
reverse.printContent();
try {
reverse.removeLast();
} catch (NoSuchElementException e) {
System.out.println(e.toString());
}
reverse.printContent();
LinkedList<Integer> linkedList = new LinkedList<Integer>();
linkedList.addInPlace(1);
linkedList.addInPlace(3);
linkedList.addInPlace(2);
linkedList.addInPlace(5);
linkedList.addInPlace(4);
/*
* LinkedList<String> linkedList = new LinkedList<String>();
*
* linkedList.addInPlace("cindy"); linkedList.addInPlace("emy");
* linkedList.addInPlace("bobby"); linkedList.addInPlace("dany");
* linkedList.addInPlace("andy");
*/
// print content of the list
linkedList.printContent();
LinkedList<Double> listOne = new LinkedList<Double>();
LinkedList<Double> listTwo = new LinkedList<Double>();
LinkedList<Double> mergedList = new LinkedList<Double>();
listOne.addInPlace(3.0);
listOne.addInPlace(2.0);
listOne.addInPlace(1.0);
listOne.addInPlace(4.0);
listTwo.addInPlace(5.0);
listTwo.addInPlace(7.0);
listTwo.addInPlace(6.0);
mergedList.mergedLinkedLists(listOne, listTwo, mergedList);
mergedList.printContent();
} // end of main()
} // LinkedListDemo