diff --git a/src/main/java/de/joethei/hs/java2/praktikum/praktikum2/CharCollection.java b/src/main/java/de/joethei/hs/java2/praktikum/praktikum2/CharCollection.java index dcc4a5f..1e1ad55 100644 --- a/src/main/java/de/joethei/hs/java2/praktikum/praktikum2/CharCollection.java +++ b/src/main/java/de/joethei/hs/java2/praktikum/praktikum2/CharCollection.java @@ -28,11 +28,11 @@ public class CharCollection implements Cloneable{ } public int count(char c) { - int rueckgabe = 0; + int result = 0; for(char b:list) { - if(b == c)rueckgabe ++; + if(b == c)result ++; } - return rueckgabe; + return result; } public int different() { @@ -59,7 +59,7 @@ public class CharCollection implements Cloneable{ } */ public char top() { - if(list.size() == 0) return 0; + if(list.isEmpty()) return 0; int max = 0; char character ='_'; for(char c : list) { @@ -72,12 +72,45 @@ public class CharCollection implements Cloneable{ return character; } - public CharCollection moreThan(int n) { - CharCollection result = new CharCollection(list); - for (int i = 0; i < result.size(); i++) { - if(result.count(result.list.get(i)) < n) result.list.remove(i); + public CharCollection moreThan(int m) { + ArrayList list2 = new ArrayList<>(); + for(char c:this.list){ + if(this.count(c) > m) { + list2.add(c); + } } - return result; + StringBuilder s = new StringBuilder(); + for(char c:list2) s.append(c); + return new CharCollection(s.toString()); + } + + public CharCollection except(CharCollection cc) { + ArrayList list= new ArrayList<>(this.list); + boolean removeCharacterOnce = false; + for(int i=0; i list2 = new ArrayList<>(this.list); + for(char c:cc.list) { + if(!list2.contains(c)) return false; + else list2.remove(list2.indexOf(c)); + } + return true; } @Override diff --git a/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Node.java b/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Node.java new file mode 100644 index 0000000..0ea3487 --- /dev/null +++ b/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Node.java @@ -0,0 +1,47 @@ +package de.joethei.hs.java2.vorlesungen.binaryTree; + +public class Node { + + private T value; + private Node left; + private Node right; + + public Node() { + } + + public Node(T value) { + this.value = value; + } + + public Node(T value, Node left, Node right) { + this.value = value; + this.left = left; + this.right = right; + } + + public T getValue() { + return value; + } + + public Node getLeft() { + return left; + } + + public Node getRight() { + return right; + } + + @Override + public String toString() { + return super.toString(); + } + + @Override + public boolean equals(Object obj) { + if(obj instanceof Node) { + Node node = (Node) obj; + return node.value.equals(this.value) && node.left.equals(this.left) && node.right.equals(this.right); + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Tree.java b/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Tree.java new file mode 100644 index 0000000..380691b --- /dev/null +++ b/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Tree.java @@ -0,0 +1,14 @@ +package de.joethei.hs.java2.vorlesungen.binaryTree; + +public class Tree { + + private Node root; + + public Tree(Node root) { + this.root = root; + } + + public Node getRoot() { + return root; + } +} \ No newline at end of file diff --git a/src/test/java/de/joethei/hs/java2/tests/CharCollectionTest.java b/src/test/java/de/joethei/hs/java2/tests/CharCollectionTest.java index 33ec209..d3ccf5b 100644 --- a/src/test/java/de/joethei/hs/java2/tests/CharCollectionTest.java +++ b/src/test/java/de/joethei/hs/java2/tests/CharCollectionTest.java @@ -50,15 +50,14 @@ public class CharCollectionTest { assertEquals(new CharCollection("llo"), new CharCollection("lol")); } - /* @Test public void except() { - assertEquals(new CharCollection("Hao"), new CharCollection("Hallo").except("l")); + assertEquals(new CharCollection("Halo"), new CharCollection("Hallo").except(new CharCollection("l"))); } @Test public void isSubsect() { - assertTrue(new CharCollection("Hallo").isSubset("Hao")); + assertTrue(new CharCollection("Hallo").isSubset(new CharCollection("Hao"))); } - */ + } \ No newline at end of file diff --git a/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java b/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java index c3ee50d..198b7be 100644 --- a/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java +++ b/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java @@ -1,6 +1,8 @@ package de.joethei.hs.java2.tests; import de.joethei.hs.java2.vorlesungen.Sieb; +import de.joethei.hs.java2.vorlesungen.binaryTree.Node; +import de.joethei.hs.java2.vorlesungen.binaryTree.Tree; import org.junit.Test; import java.util.Arrays; @@ -17,4 +19,14 @@ public class VorlesungsTest { Set set = new TreeSet<>(Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19)); assertEquals(set, new Sieb(20).getPrimzahl()); } + + @Test + public void binaryTree() { + + + Tree tree = new Tree<>(new Node<>(45, new Node<>(14), new Node<>(16))); + assertEquals(Integer.valueOf(45), tree.getRoot().getValue()); + assertEquals(Integer.valueOf(14), tree.getRoot().getLeft().getValue()); + assertEquals(Integer.valueOf(16), tree.getRoot().getRight().getValue()); + } } \ No newline at end of file