17.Java基于二分搜索树实现Set

package com.cl.set;

public class BSTSet<E extends Comparable<E>> implements Set<E> {

    private BST<E> bst;

    public BSTSet() {
        bst=new BST<>();
    }

    //O(h)
    @Override
    public void add(E e) {
        bst.add(e);
    }

    //O(h)
    @Override
    public void remove(E e) {
        bst.removeByPredicessor(e);
    }
    //O(h)
    @Override
    public boolean contains(E e) {
        return bst.contains(e);
    }

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

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

其中BST请参考:https://mp.csdn.net/postedit/88812048

猜你喜欢

转载自blog.csdn.net/cl723401/article/details/88812089