-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListDemo.java
More file actions
55 lines (46 loc) · 1.04 KB
/
LinkedListDemo.java
File metadata and controls
55 lines (46 loc) · 1.04 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
import java.util.*;
public class LinkedListDemo {
public static void main(String[] args)
{
LinkedList l1=new LinkedList();
l1.add(100);
l1.add(20);
l1.add(30);
l1.add(40);
l1.add(50);
System.out.println("Initial LinkedList: ");
for(Object e:l1)
{
System.out.println(e);
}
l1.addFirst(5);
System.out.println("After using AddFirst : ");
for(Object e:l1)
{
System.out.println(e);
}
l1.addLast(70);
System.out.println("After using AddLast : ");
for(Object e:l1)
{
System.out.println(e);
}
Object e1=l1.getFirst();
System.out.println("First Element: "+e1);
Object e2=l1.getLast();
System.out.println("Last Element: "+e2);
System.out.println(l1.peek());
System.out.println(l1.poll());
System.out.println("After using Poll : ");
for(Object e:l1)
{
System.out.println(e);
}
l1.sort(Comparator.naturalOrder());
System.out.println("After using sort : ");
for(Object e:l1)
{
System.out.println(e);
}
}
}