-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathLinkedListSet.java
46 lines (37 loc) · 1.03 KB
/
LinkedListSet.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
/***********************************************************
* @Description : 基于链表的集合
* @author : 梁山广(Laing Shan Guang)
* @date : 2018/5/17 00:30
* @email : [email protected]
***********************************************************/
package Chapter07SetAndMap.Section2LinkedListSet;
import Chapter04LinkedList.Section5Delete.LinkedList;
import Chapter07SetAndMap.Section1SetBasicAndBSTSet.Set;
public class LinkedListSet<E> implements Set<E> {
private LinkedList<E> list;
public LinkedListSet() {
list = new LinkedList<>();
}
@Override
public void add(E e) {
if (!list.contain(e)) {
list.addFirst(e);
}
}
@Override
public void delete(E e) {
list.deleteElement(e);
}
@Override
public boolean contain(E e) {
return list.contain(e);
}
@Override
public int getSize() {
return list.getSize();
}
@Override
public boolean isEmpty() {
return list.isEmpty();
}
}