-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractciell1.java
More file actions
41 lines (39 loc) · 893 Bytes
/
practciell1.java
File metadata and controls
41 lines (39 loc) · 893 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
class Node{
int val;
Node next;
Node(int val){
this.val=val;
}
}
public class practciell1 {
static void display(Node head){
Node temp=head;
while (temp!=null) {
System.out.println(temp.val);
temp=temp.next;
}
}
static Node LeftMiddle(Node head){
Node fast=head;
Node slow=head;
while(fast.next.next!=null && fast.next!=null){
fast=fast.next.next;
slow=slow.next;
}
return slow;
}
public static void main(String[] args) {
Node a=new Node(60);
Node b=new Node(70);
Node c=new Node(80);
Node d=new Node(90);
Node e=new Node(100);
Node f= new Node(110);
a.next=b;
b.next=c;
c.next=d;
d.next=e;
e.next=f;
display(LeftMiddle(a));
}
}