forked from joharbatta/DataStructure-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveDuplicatell.java
More file actions
72 lines (72 loc) · 1017 Bytes
/
Copy pathremoveDuplicatell.java
File metadata and controls
72 lines (72 loc) · 1017 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.util.*;
public class removeDuplicatell
{
static class Node
{
int data;
Node next;
Node(int data)
{
this.data=data;
next=null;
}
}
Node head;
void insert(int data)
{
Node temp=new Node(data);
if(head==null)
{
head=temp;
return;
}
Node cur=head;
while(cur.next!=null)
{
cur=cur.next;
}
cur.next=temp;
}
void remove()
{
Node cur=head;
while(cur!=null)
{
Node temp=cur;
while(temp.next!=null)
{
if(cur.data==temp.next.data)
{
temp.next=temp.next.next;
}
else
{
temp=temp.next;
}
}
cur=cur.next;
}
}
void print()
{
Node cur=head;
while(cur!=null)
{
System.out.print(cur.data+" ");
cur=cur.next;
}
}
public static void main(String args[])
{
removeDuplicatell d=new removeDuplicatell();
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size");
int size=sc.nextInt();
for(int i=0;i<size;i++)
{
d.insert(sc.nextInt());
}
d.remove();
d.print();
}
}