Set

作者: SeekerLinJunYu | 来源:发表于2019-03-13 00:28 被阅读0次
    /**
     * 
     * @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();
        }
    
    }
    

    相关文章

      网友评论

          本文标题:Set

          本文链接:https://www.haomeiwen.com/subject/ifdapqtx.html