Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 1.08 KB

quiz-answers.md

File metadata and controls

43 lines (32 loc) · 1.08 KB

CSE 143

Quiz Answers

Week 2

  1. boolean zen is a word used to describe if code using booleans is written in the most concise way possible. If something evaluates to a boolean value you should return that value instead of using an if/else structure to determine whether to return true or false.

  2. No, a boolean zen version is shown below.

    return width > 0 && width < 100 && height > 0 && height < 100;
  3. No, a boolean zen version is shown below.

    return list.isEmpty();
  4. One possible answer is shown below.

    public boolean equals(Stack<Integers1Stack<Integer>s2) {
    	Stack<Integertemp = new Stack<Integer>();
    	boolean isEqual = true;
    
    	while (isEqual && !s1.isEmpty() && !s2.isEmpty()) {
    		int element1 = s1.pop();
    		int element2 = s2.pop();
    		isEqual = isEqual && element1 == element2;
    		temp.push(element1);
    		temp.push(element2);
    	}
    
    	isEqual = isEqual && s1.isEmpty() && s2.isEmpty();
    
    	while (!temp.isEmpty()) {
    		s2.push(temp.pop());
    		s1.push(temp.pop());
    	}
    
    	return isEqual;
    }