JAVA数据结构之BST实现Set集合

Set 接口

public interface Set<E>{
    void add(E e);
    void remove(E e);
    boolean contains(E e);
    int getSize();
    boolean isEmpty();
}

//需要之前的BST类

BSTSet

public class BSTSet<E> implements Set<E>{
    private BST<E> bst;
    //构造函数
    public BSTSet(){
        bst = new BST<>();
    }
     @Override
    public void add(E e) {
       bst.add(e)
    }

    @Override
    public void remove(E e) {
        bst.remove(e);
    }

    @Override
    public boolean contains(E e) {
        return bst.contain(e);
    }

    @Override
    public int getSize() {
        return bst.size();
    }

    @Override
    public boolean isEmpty() {
        return bst.isEmpty();
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_41263632/article/details/81915032