From e2cd5cce0a41191420a3f1897e51a8ed672baf5a Mon Sep 17 00:00:00 2001 From: Isaac Abell Date: Mon, 18 Sep 2023 19:43:38 -0400 Subject: [PATCH 01/10] stuff --- src/Tree.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Tree.java b/src/Tree.java index 458a7c7..bbf7a57 100644 --- a/src/Tree.java +++ b/src/Tree.java @@ -1,2 +1,7 @@ public class Tree { + + private class Node{ + + } } + From f906c7327d2a0e4d901bf3f30b3ecfab24955689 Mon Sep 17 00:00:00 2001 From: art33zy <47585282+art33zy@users.noreply.github.com> Date: Mon, 18 Sep 2023 19:59:58 -0400 Subject: [PATCH 02/10] added count method --- src/Tree.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Tree.java b/src/Tree.java index bbf7a57..8bd08b7 100644 --- a/src/Tree.java +++ b/src/Tree.java @@ -3,5 +3,8 @@ public class Tree { private class Node{ } + private int Count(int item){ + return 0; + } } From 8c5a6df0619c2d170795b55110149c5c92163b3c Mon Sep 17 00:00:00 2001 From: art33zy <47585282+art33zy@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:02:25 -0400 Subject: [PATCH 03/10] tet --- src/Tree.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Tree.java b/src/Tree.java index 8bd08b7..c5bdfb9 100644 --- a/src/Tree.java +++ b/src/Tree.java @@ -4,6 +4,9 @@ private class Node{ } private int Count(int item){ + if(Tree.isEmpty()){ + return 0; + } return 0; } } From bbb42e13c37b5ca7457bf47a3fd60de3ced703f9 Mon Sep 17 00:00:00 2001 From: art33zy <47585282+art33zy@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:07:43 -0400 Subject: [PATCH 04/10] added count method --- out/production/multiset-adt/Tree.class | Bin 0 -> 314 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 out/production/multiset-adt/Tree.class diff --git a/out/production/multiset-adt/Tree.class b/out/production/multiset-adt/Tree.class new file mode 100644 index 0000000000000000000000000000000000000000..de853c3d5d17a75c2a76f934d13ec03e98c60d9c GIT binary patch literal 314 zcmXX>%SyyR5UfciJ8m|*5A_2C59+~ufFiqB9J9&?4J21zP@il>NEsz9 gr4z<%h!f^RRxyqkBTO-4)|{K;n4@%v3{DXJ15E=tBLDyZ literal 0 HcmV?d00001 From 22e6fe0d70631cd10ee5425a389a396daa4140b4 Mon Sep 17 00:00:00 2001 From: art33zy <47585282+art33zy@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:15:51 -0400 Subject: [PATCH 05/10] updated count method to work --- src/Tree.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Tree.java b/src/Tree.java index c5bdfb9..c744dfa 100644 --- a/src/Tree.java +++ b/src/Tree.java @@ -3,11 +3,19 @@ public class Tree { private class Node{ } - private int Count(int item){ - if(Tree.isEmpty()){ + private int count(int item) { + if (Tree.isEmpty()) { return 0; + } else { + int num = 0; + if(this.root == item){ + num += 1; + } + for(subtree x : this.getSubtrees()){ + num += x.count(item); + } + return num; } - return 0; } } From 342e46d5371cf6c08a2a687cb8385eee063c5232 Mon Sep 17 00:00:00 2001 From: art33zy <47585282+art33zy@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:17:36 -0400 Subject: [PATCH 06/10] updated count method to work --- src/Tree.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Tree.java b/src/Tree.java index c744dfa..813f4f2 100644 --- a/src/Tree.java +++ b/src/Tree.java @@ -15,6 +15,7 @@ private int count(int item) { num += x.count(item); } return num; + } } } From da7b9d6cff283c287d22e0f0e991e650a22bbd8a Mon Sep 17 00:00:00 2001 From: Isaac-A-UofT <144389688+Isaac-A-UofT@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:22:40 -0400 Subject: [PATCH 07/10] stuff (#2) --- src/Tree.java | 52 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/Tree.java b/src/Tree.java index 813f4f2..695b75e 100644 --- a/src/Tree.java +++ b/src/Tree.java @@ -1,7 +1,31 @@ -public class Tree { +import java.util.ArrayList; +import java.util.List; - private class Node{ +public class Tree { + // Private Attributes + // The item stored at this tree's root, or null if the tree is empty. + private T root; + // The list of all subtrees of this tree. + private List> subtrees; + + public Tree(T root) { + this.root = root; + this.subtrees = new ArrayList<>(); + } + + public Tree(T root, List> subtrees) { + this.root = root; + this.subtrees = new ArrayList<>(subtrees); + } + + public T getRoot() { + return root; + } + + public List> getSubtrees() { + return subtrees; + } } private int count(int item) { if (Tree.isEmpty()) { @@ -20,3 +44,27 @@ private int count(int item) { } } + public void setRoot(T root) { + this.root = root; + } + + public void setSubtrees(List> subtrees) { + this.subtrees = subtrees; + } + + public boolean is_empty() { + return (this.root == null); + } + + public int length() { + if (this.is_empty()) { + return 0; + } else { + int size = 1; + for (Tree x : this.getSubtrees()) { + size += x.length(); + } + return size; + } + } +} \ No newline at end of file From c4fc50375a0a2d69901e7a60b24bb1b91eabd893 Mon Sep 17 00:00:00 2001 From: art33zy <47585282+art33zy@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:24:34 -0400 Subject: [PATCH 08/10] updated count method to work --- src/Tree.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tree.java b/src/Tree.java index 813f4f2..ee60c44 100644 --- a/src/Tree.java +++ b/src/Tree.java @@ -4,7 +4,7 @@ private class Node{ } private int count(int item) { - if (Tree.isEmpty()) { + if (this.isEmpty()) { return 0; } else { int num = 0; From 1527233e8d9fd9ac5c7a1e61440eaa960f49b968 Mon Sep 17 00:00:00 2001 From: kaviraj Date: Mon, 18 Sep 2023 20:25:16 -0400 Subject: [PATCH 09/10] average and equals --- src/Tree.java | 36 ++++++++++++++++++++++++++++++++++++ test/TreeTest.java | 4 ++++ 2 files changed, 40 insertions(+) diff --git a/src/Tree.java b/src/Tree.java index bbf7a57..1e3d822 100644 --- a/src/Tree.java +++ b/src/Tree.java @@ -3,5 +3,41 @@ public class Tree { private class Node{ } + + public double average(){ + if(this.is_empty()){ + return 0.0; + } + count = this.Count(); + size = this.length(); + return count / size; + + } + private int average_helper(){ + total = 0; + if(this.root){ + total += 1; + } + for(Tree i: this.subtrees){ + total += this.average_helper(); + } + return total; + } + @Override + public boolean equals(Object o) { + if (this.is_empty() & o.is_empty()) { + return true; + } else if (this.is_empty() || other.is_empty()) { + return false; + } else { + if (this.root != other._root) { + return false; + } + if (this.subtrees.length() != other._subtrees.length()) { + return false; + } + return self._subtrees == other._subtrees; + } + } } diff --git a/test/TreeTest.java b/test/TreeTest.java index 7c7af90..88d3f5c 100644 --- a/test/TreeTest.java +++ b/test/TreeTest.java @@ -14,4 +14,8 @@ public void dummyTest() { assertTrue(true); } + public void TestAverage(){ + Tree t = new Tree(); + assertTrue(t.average() == 0.0); + } } \ No newline at end of file From ac7b92325f2cb9194f444fd50f72342169890c91 Mon Sep 17 00:00:00 2001 From: Isaac Abell Date: Mon, 18 Sep 2023 20:27:03 -0400 Subject: [PATCH 10/10] fix {} --- src/Tree.java | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/Tree.java b/src/Tree.java index 695b75e..4375520 100644 --- a/src/Tree.java +++ b/src/Tree.java @@ -26,23 +26,6 @@ public T getRoot() { public List> getSubtrees() { return subtrees; } - } - private int count(int item) { - if (Tree.isEmpty()) { - return 0; - } else { - int num = 0; - if(this.root == item){ - num += 1; - } - for(subtree x : this.getSubtrees()){ - num += x.count(item); - } - return num; - - } - } -} public void setRoot(T root) { this.root = root; @@ -56,6 +39,21 @@ public boolean is_empty() { return (this.root == null); } + public int count(T item) { + if (this.is_empty()) { + return 0; + } else { + int num = 0; + if (this.root.equals(item)) { + num += 1; + } + for (Tree x : this.getSubtrees()) { + num += x.count(item); + } + return num; + } + } + public int length() { if (this.is_empty()) { return 0; @@ -67,4 +65,4 @@ public int length() { return size; } } -} \ No newline at end of file +}