-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADT.java
40 lines (32 loc) · 938 Bytes
/
ADT.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
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.TreeSet;
public class ADT {
public static void main(String[] args) {
LinkedList<Integer> ll = new LinkedList<Integer>();
ll.push(4);
ll.push(3);
ll.push(7);
ll.push(3);
ll.push(6);
ll.push(6);
ll.push(1);
TreeSet<Integer> tsll = duplicateFree(ll);
Iterator<Integer> tsllit = tsll.iterator();
while(tsllit.hasNext()){
System.out.println(tsllit.next());
}
}
public static <T> TreeSet<T> duplicateFree (Collection<T> c){
TreeSet<T> ts = new TreeSet<T>();
Iterator<T> it = c.iterator();
while(it.hasNext()){
T temp = it.next();
if(!ts.add(temp)){
System.out.println("duplicate detected");
}
}
return ts;
}
}