/**
*
* @author SeekerLinJunYu
*
* @param <E>
*/
public class LinkedListSet<E> implements Set<E> {
private LinkedListClass<E> linkedlist;
public LinkedListSet() {
linkedlist = new LinkedListClass<>();
}
@Override
public void add(E e) {
if (linkedlist.constains(e)) {
return;
}
else
linkedlist.add(0, e);
}
@Override
public boolean isEmpty() {
return linkedlist.isEmpty();
}
@Override
public int getSize() {
return linkedlist.getSize();
}
@Override
public boolean contains(E e) {
return linkedlist.constains(e);
}
@Override
public void remove(E e) {
linkedlist.removeElement(e);
}
}
BSTSet
/**
*
* @author Administrator
*
* @param <E>
*/
public class BSTSet<E extends Comparable<E>> implements Set<E> {
private BST<E> bst;
public BSTSet() {
bst = new BST<>();
}
@Override
public void add(E e) {
bst.add(e);
}
@Override
public boolean isEmpty() {
return bst.isEmpty();
}
@Override
public boolean contains(E e) {
return bst.contains(e);
}
@Override
public void remove(E e) {
bst.removeElement(e);
}
@Override
public int getSize() {
return bst.getSize();
}
}
网友评论