-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestProg.java
More file actions
59 lines (52 loc) · 979 Bytes
/
testProg.java
File metadata and controls
59 lines (52 loc) · 979 Bytes
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
import java.util.*;
import static java.lang.System.out;
class Node<T extends Number> {
Node next;
T data;
Node(T data) {
this.data = data;
next = null;
}
}
class LinkedList<T extends Number> {
private static Node head;
private static Node tail;
public static void main(String[] args) {
}
public void addAtHead(T data) {
if(head == null) {
head = new Node(data);
head.next = null;
tail.next = null;
tail = head;
} else {
Node curr = new Node(data);
curr.next = head;
head = curr;
}
}
public void addAtTail(T data) {
if(head == null) {
head = new Node(data);
head.next = null;
tail.next = null;
tail = head;
} else {
Node curr = new Node(data);
tail.next = curr;
tail = curr;
}
}
public void display() {
if(head == null) {
out.println("List is empty!");
} else {
Node tmp = head;
while(tmp != null) {
out.print(tmp.data+"->");
tmp = tmp.next;
}
out.print("NULL");
}
}
}