-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoublelyLL.java
More file actions
70 lines (55 loc) · 1.42 KB
/
DoublelyLL.java
File metadata and controls
70 lines (55 loc) · 1.42 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
package Collection;
public class DoublelyLL extends Node{
Node head =null;
public Node createNode(String data){
Node obj = new Node();
obj.prev = null;
obj.data = data;
obj.next = null;
return obj;
}
public void add(String name) {
Node newNode = createNode(name);
if (head == null) {
head = newNode;
} else {
Node temp = head;
while (temp.next != null) {
temp = temp.next;
}
temp.next = newNode;
newNode.prev = temp;
}
}
public void addAt(int index, String data){
}
public void remove(int index) {
if (index < 0) {
throw new IndexOutOfBoundsException("Invalid Index: " + index);
}
if (index == 0) {
head = head.next;
return;
}
for (int i = 0; i < index - 1; i++) {
head = head.next;
}
Node temp = head.next;
head.next = temp.next;
}
public void printMyLList() {
Node temp = head;
while (temp != null) {
System.out.println(temp.data);
temp = temp.next;
}
}
public static void main(String[] args) {
DoublelyLL list = new DoublelyLL();
list.add("20");
list.add("30");
list.add("50");
list.add("60");
list.printMyLList();
}
}