-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayingLinkedList.java
More file actions
51 lines (40 loc) · 1.08 KB
/
DisplayingLinkedList.java
File metadata and controls
51 lines (40 loc) · 1.08 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
class Node{
int val;
Node next;
Node(int val){
this.val=val;
}
}
public class DisplayingLinkedList {
public static void print(Node head){
Node temp=head;
while(temp!=null){
System.out.println(temp.val);
temp=temp.next;
}
}
public static void display(Node head){// >-print linked list in reverse order
if(head==null)
return;
display(head.next);
System.out.println(head.val+" ");
}
public static void main(String[] args) {
Node a=new Node(10);
Node b=new Node(20);
Node c=new Node(30);
Node d=new Node(40);
Node e=new Node(50);
Node f=new Node(60);
a.next=b;
b.next=c;
c.next=d;
d.next=e;
e.next=f;
display(a);
// for(int i=0;i<=6;i++){//instead of this use while loop and make the condition as
//while(temp!=null){}
// System.out.println(temp.val);
// temp=temp.next;
}
}