This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int countEmpty() { | |
return countEmpty(this.overallRoot); | |
} | |
private int countEmpty(IntTreeNode overallRoot) { | |
if (overallRoot == null) { | |
return 1; | |
} else { | |
return countEmpty(overallRoot.left) + countEmpty(overallRoot.right); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int countLeftNodes() { | |
return countLeftNodes(this.overallRoot); | |
} | |
private int countLeftNodes(IntTreeNode overallRoot) { | |
if (overallRoot != null) { | |
if (overallRoot.left != null) { | |
return 1 + countLeftNodes(overallRoot.left) + countLeftNodes(overallRoot.right); | |
} else { | |
return countLeftNodes(overallRoot.right); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Assignment_Four { | |
public static double balance = 1500.00; | |
public static double largest = 0.0; | |
public static double smallest = 10000.00; // should this be changed to 1500? | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String repl(String str, int rep) { | |
String result = ""; | |
for (int i = rep; i > 0; i--) { | |
result += str; | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// returns whether given integer is a perfect number or not | |
public boolean perfectNumber(int number) { | |
int temp = 0; | |
for(int i= 1; i <= number/2; i++) { | |
if(number % i == 0) { | |
temp += i; | |
} | |
} | |
if(temp == number) { | |
return true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// returns whether or not a given int passed in is a palindrome | |
public boolean isPalindrome(Queue<Integer> q) { | |
Stack<Integer> s = new Stack<Integer>(); | |
boolean isPalindrome = true; | |
int qSize = q.size(); | |
for (int i = 0; i < qSize; i++) { | |
s.push(q.peek()); | |
q.add(q.remove()); | |
} | |
while (!s.isEmpty()) { |