-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathremove_particular_element_in_LL.java
59 lines (54 loc) · 1.59 KB
/
remove_particular_element_in_LL.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
57
58
59
package Linkedlist;
public class remove_particular_element_in_LL {
Node head;
static class Node {
int data;
Node next;
Node(int data)
{
this.data=data;
this.next=null;
}
}
public Node remove(Node head)
{
Node current=head;
while(current.next!=null){
if(head==null)
{
return null;
}
if(head.data==6)
{
head=head.next;
}
if(current.next.data==6)
{
current.next=current.next.next;
}
else {
current=current.next;
}
}
return head;
}
public void printlist(Node head)
{
Node current_node=head;
while(current_node!=null)
{
System.out.println(current_node.data);
current_node=current_node.next;
}
}
public static void main(String[] args) {
remove_particular_element_in_LL ll=new remove_particular_element_in_LL();
ll.head = new remove_particular_element_in_LL.Node(6);
ll.head.next = new remove_particular_element_in_LL.Node(6);
ll.head.next.next = new remove_particular_element_in_LL.Node(2);
ll.head.next.next.next = new remove_particular_element_in_LL.Node(3 );
ll.head.next.next.next.next = new remove_particular_element_in_LL.Node(6);
remove_particular_element_in_LL.Node t=ll.remove(ll.head);
ll.printlist(t);
}
}