From 66260b0a740562c1a8ae8a576f71a50def5f9ce1 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 10 Dec 2019 10:05:27 -0600 Subject: Finish lab????? --- csci1913/Java/project3/project3_strap012.java | 23 ++++++++++++++++------- csci1913/Java/project3/the.txt | 5 +++++ 2 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 csci1913/Java/project3/the.txt (limited to 'csci1913') diff --git a/csci1913/Java/project3/project3_strap012.java b/csci1913/Java/project3/project3_strap012.java index 966c4fb..4c1f0a6 100644 --- a/csci1913/Java/project3/project3_strap012.java +++ b/csci1913/Java/project3/project3_strap012.java @@ -41,7 +41,15 @@ class AnagramTree { goLeft = false; bottom = bottom.right; } else { - bottom.words = new WordNode(word, bottom.words); + WordNode badNode = bottom.words; + boolean wordExists = false; + while (badNode != null) { + if (badNode.word.equals(word)) + wordExists = true; + badNode = badNode.next; + } + if (!wordExists) + bottom.words = new WordNode(word, bottom.words); addWord = true; break; } @@ -59,16 +67,16 @@ class AnagramTree { } public void anagrams() { - System.out.println(findAnagrams(head.right)); //e should be lower than other words as it is e + findAnagrams(head.right); //e should be lower than other words as it is e } - private String findAnagrams(TreeNode subtree) { - StringBuilder builder = new StringBuilder(); + private void findAnagrams(TreeNode subtree) { try { if (subtree.words.next != null) { + System.out.println(); while (subtree.words != null) { - builder.append(subtree.words.word); - builder.append(" "); + System.out.print(subtree.words.word); + System.out.print(" "); subtree.words = subtree.words.next; } } @@ -79,7 +87,8 @@ class AnagramTree { } catch (NullPointerException ignore) { //Do nothing } - return builder.toString(); + + } private int compareSummaries(byte[] left, byte[] right) { diff --git a/csci1913/Java/project3/the.txt b/csci1913/Java/project3/the.txt new file mode 100644 index 0000000..6afe356 --- /dev/null +++ b/csci1913/Java/project3/the.txt @@ -0,0 +1,5 @@ +the the the the eht the the the +the +the het +hte +the \ No newline at end of file -- cgit v1.2.3