-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoubleLinkedList.java
56 lines (44 loc) · 1.21 KB
/
DoubleLinkedList.java
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
package JAVA;
public class DoubleLinkedList{
Node_ head = null;
public static void main(String[] args) {
DoubleLinkedList ll = new DoubleLinkedList();
ll.add(1);
ll.add(2);
ll.add(3);
ll.add(4);
ll.add(5);
ll.print_();
}
void add(int data){
if(head == null){
Node_ newNode = new Node_(null,data,null);
head = newNode;
return;
}
Node_ currentNode = head;
while(currentNode.next != null){
currentNode = currentNode.next;
}
Node_ newNode = new Node_(currentNode,data,null);
currentNode.next = newNode;
return;
}
void print_(){
while (head != null){
System.out.println("----------------------------------------------------------");
System.out.println(head.previous+"--"+head.data+"--"+head.next);
head = head.next;
}
}
}
class Node_{
Node_ previous;
int data;
Node_ next;
Node_(Node_ previous, int data, Node_ next){
this.previous = previous;
this.data = data;
this.next = next;
}
}