diff options
author | RossTheRoss <msattr@gmail.com> | 2019-12-10 10:22:33 -0600 |
---|---|---|
committer | RossTheRoss <msattr@gmail.com> | 2019-12-10 10:22:33 -0600 |
commit | 838e682943fb52c5582a1a7a8ef2c986cdbac059 (patch) | |
tree | 0e49495f8c83f81ba259b49562efe834c08a588f /csci1913/Java/project3/project3_strap012.java | |
parent | Fix dumb mistake (diff) | |
download | homework-838e682943fb52c5582a1a7a8ef2c986cdbac059.tar homework-838e682943fb52c5582a1a7a8ef2c986cdbac059.tar.gz homework-838e682943fb52c5582a1a7a8ef2c986cdbac059.tar.bz2 homework-838e682943fb52c5582a1a7a8ef2c986cdbac059.tar.lz homework-838e682943fb52c5582a1a7a8ef2c986cdbac059.tar.xz homework-838e682943fb52c5582a1a7a8ef2c986cdbac059.tar.zst homework-838e682943fb52c5582a1a7a8ef2c986cdbac059.zip |
Minor fixes
Diffstat (limited to 'csci1913/Java/project3/project3_strap012.java')
-rw-r--r-- | csci1913/Java/project3/project3_strap012.java | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/csci1913/Java/project3/project3_strap012.java b/csci1913/Java/project3/project3_strap012.java index 48c57ae..019bce7 100644 --- a/csci1913/Java/project3/project3_strap012.java +++ b/csci1913/Java/project3/project3_strap012.java @@ -1,3 +1,4 @@ +//package used to bundle with Words class package project3; class AnagramTree { private TreeNode head; @@ -30,7 +31,7 @@ class AnagramTree { newSumm = stringToSummary(word); TreeNode top = head, bottom = top.right; boolean goLeft = false, addWord = false; - try { while (bottom != null) { + while (bottom != null) { int comp = compareSummaries(bottom.summary, newSumm); if (comp > 0) { // left is less than right, go left top = bottom; @@ -53,17 +54,13 @@ class AnagramTree { addWord = true; break; } - } - if (addWord) {} // Do nothing - else { - if (goLeft) - top.left = new TreeNode(word, newSumm); - else - top.right = new TreeNode(word, newSumm); + } + if (!addWord) { //Word was not added, keep going + if (goLeft) + top.left = new TreeNode(word, newSumm); + else + top.right = new TreeNode(word, newSumm); } - } catch (NullPointerException ignore) { - System.out.println("A"); - } } public void anagrams() { @@ -85,7 +82,11 @@ class AnagramTree { findAnagrams(subtree.left); } } catch (NullPointerException ignore) { - //Do nothing + /* + This exception exists as a kludge for any time + subtree is null. The program does bad things (crash) + if this is not present. + */ } @@ -117,6 +118,7 @@ class Anagrammer { anagrams.add(words.next()); } anagrams.anagrams(); + //Print extra line for neatness System.out.println(); } }
\ No newline at end of file |