package com.cl.set;
public class LinkedListSet<E> implements Set<E> {
private LinkedList<E> list;
public LinkedListSet() {
list = new LinkedList<>();
}
//O(n)
@Override
public void add(E e) {
if(!list.contains(e))
list.addFirst(e);
}
//O(n)
@Override
public void remove(E e) {
list.removeElement(e);
}
//O(n)
@Override
public boolean contains(E e) {
return list.contains(e);
}
@Override
public int getSise() {
return list.getSize();
}
@Override
public boolean isEmpty() {
return list.isEmpty();
}
}
其中LinkedList是自己实现的单链表,参考:https://mp.csdn.net/postedit/88812059