-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLL.java
More file actions
84 lines (83 loc) · 2.05 KB
/
LL.java
File metadata and controls
84 lines (83 loc) · 2.05 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
73
74
75
76
77
78
79
80
81
82
83
84
import java.util.*;
public class LL {
// class Node{
// String data;
// Node next;
//
// Node(String data){
// this.data = data;
// this.next = null;
// size++;
// }
// }
// private int size;
// LL(){
// this.size = 0;
// }
// Node head = null;
// public void addFirst(String data){
// Node nn = new Node(data);
// if(head == null){
// head = nn;
// return;
// }
// nn.next = head;
// head = nn;
// }
// public void addLast(String data){
// Node nn = new Node(data);
// if(head == null){
// head = nn;
// return;
// }
// Node temp = head;
// while (temp.next != null){
// temp = temp.next;
// }
// temp.next = nn;
// }
// public void deleteFirst(){
// if(head == null) {
// System.out.println("The list is empty");
// return;
// }
// size--;
// head = head.next;
//
// }
// public void deleteLast(){
// Node curr = head;
// Node prev = null;
// if(head == null){
// System.out.println("list is empty");
// return;
// }
// while(curr.next!=null){
// prev = curr;
// curr = curr.next;
// }
// prev.next = null;
// size--;
// }
// public void printList(){
// Node temp = head;
// while(temp!= null){
// System.out.print(temp.data + "->");
// temp = temp.next;
// }
// System.out.println("NULL");
// }
public static void main(String[] args) {
LinkedList<String> list = new LinkedList<String>();
list.addFirst("a");
list.addFirst("is");
list.addFirst("This");
list.addLast("list");
System.out.println(list);
System.out.println(list.size());
for(int i = 0;i<list.size();i++){
System.out.print(list.get(i)+"-> ");
}
System.out.println("NULL");
}
}