Skip to content

Instantly share code, notes, and snippets.

View micylt's full-sized avatar

Dylan Yelton micylt

  • Western Washington University
  • Seattle
View GitHub Profile
@micylt
micylt / countEmpty.java
Last active August 24, 2017 22:24
Counts the number of empty branches within an int tree
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);
}
@micylt
micylt / return-left-children-tree.java
Last active August 24, 2017 22:24
returns the number of left children in the tree. A left child is a node that appears as the root of the left-hand subtree of another node. An empty tree has 0 left nodes. For example, the following tree has four left children (the nodes storing the values 5, 1, 4, and 7):
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);
@micylt
micylt / assign4
Last active August 29, 2015 14:21
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?
public static String repl(String str, int rep) {
String result = "";
for (int i = rep; i > 0; i--) {
result += str;
}
return result;
}
// 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;
@micylt
micylt / isPalindrome
Last active August 29, 2015 14:20
isPalindrome
// 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()) {