-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParth.java
More file actions
61 lines (61 loc) · 1.2 KB
/
Parth.java
File metadata and controls
61 lines (61 loc) · 1.2 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
import java.util.*;
class Node6
{
int val;
Node6 prev,next;
Node6(int d)
{
val=d;
}
}
public class Parth
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
String inp[]=in.nextLine().trim().split(" ");
int t=in.nextInt();
Node6 head=null,tail=null;
for(String s:inp)
{
if(s.equals("head")||s.equals(""))
continue;
Node6 n=new Node6(Integer.parseInt(s));
if(head==null)
head=tail=n;
else{
tail.next=n;
n.prev=tail;
tail=n;
}
}
Node6 curr=head;
while(curr!=null)
{
if(curr.val==t)
{
if(curr.prev!=null)
curr.prev.next=curr.next;
else
head=curr.next;
if(curr.next!=null)
curr.next.prev=curr.prev;
}
curr=curr.next;
}
if(head==null)
System.out.println("head->(empty list)");
else{
System.out.print("head-> ");
Node6 p=head;
while(p!=null)
{
System.out.print(p.val);
if(p.next!=null)
System.out.print(" -> ");
p=p.next;
}
System.out.println();
}
}
}