LAPTOP-8KA88UT5_20200907-陈浩

问题

判断当前容器中是否全部包含指定容器中的所有元素,若包含,返回true,否则,返回false

解决:

public boolean containsAll(Collection<?> c) {
        if (c instanceof Bag) {
            Bag other = (Bag) c;
            Object[] thisElemets = this.elements;
            Object[] otherElements = other.elements;
            
            for (int i = 0; i < other.counter; i++) {
                Object temp= otherElements[i];
                    if(!this.contains(temp)) {
                        return false;
                    }
                }   
            }
        return true;    
        }

吐槽