-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoublyLL.java
More file actions
48 lines (46 loc) · 1.09 KB
/
DoublyLL.java
File metadata and controls
48 lines (46 loc) · 1.09 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
class dNode{
int val;
dNode next;
dNode prev;
dNode(int val){
this.val=val;
}
}
public class DoublyLL {
public static void print(dNode head){
dNode temp=head;
while(temp!=null){
System.out.println(temp.val+" ");
temp=temp.next;
}
System.out.println();
}
public static void printReverse(dNode tail){
dNode temp=tail;
while(temp!=null){
System.out.println(temp.val+" ");
temp=temp.prev;
}
System.out.println();
}
public static void display(dNode node){
dNode temp=node;
while(temp!=null && temp.prev!=null){
temp=temp.next;
}
print(temp);
}
public static void main(String[] args) {
dNode a=new dNode(10);
dNode b=new dNode(20);
dNode c=new dNode(30);
dNode d=new dNode(40);
a.next=b; b.prev=a;
b.next=c; c.prev=b;
c.next=d; d.prev=c;
print(a);
System.out.println(c.prev.val);
// printReverse(d);
display(b);
}
}