diff --git a/.idea/misc.xml b/.idea/misc.xml index eb8da6d..125614e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/L24.java b/src/L24.java new file mode 100644 index 0000000..ad466d7 --- /dev/null +++ b/src/L24.java @@ -0,0 +1,34 @@ +import utils.BinNode; + +public class L24 extends Main { + + public static void printAll(BinNode root) { + printAll(root, 0); + } + + public static void printAll(BinNode root, int n){ + if (root != null) { + if (isLeaf(root)) { + System.out.println(root.getValue() + n * 10); + } else { + n = n*10 + root.getValue(); + if (root.hasLeft()) { + printAll(root.getLeft(), n); + } + if (root.hasRight()) { + printAll(root.getRight(), n); + } + } + } + } + + + + public static void main(String[] args) { + BinNode root = buildTree(10); + printMeTree(root); + printAll(root); + + } + +} diff --git a/src/Test1B.png b/src/Test1B.png new file mode 100644 index 0000000..5d74ec0 Binary files /dev/null and b/src/Test1B.png differ diff --git a/src/classes/Card.java b/src/classes/Card.java new file mode 100644 index 0000000..231eb89 --- /dev/null +++ b/src/classes/Card.java @@ -0,0 +1,4 @@ +package classes; + +public record Card(String color, int num) { +} diff --git a/src/classes/MyBaseA.java b/src/classes/MyBaseA.java new file mode 100644 index 0000000..31808e0 --- /dev/null +++ b/src/classes/MyBaseA.java @@ -0,0 +1,66 @@ +package classes; + +import utils.HelpCommands; +import utils.Node; + +public class MyBaseA { + + private Node first; + private Node last; + + public MyBaseA() { + this.first = null; + } + + public void insert(int x) { + if (first == null) { + this.first = new Node<>(x); + } + if (x > first.getValue()) { + this.first = new Node<>(x, this.first); + } else { + Node temp = first; + while (temp.getNext() != null) { + if (x > temp.getNext().getValue()) { + temp.setNext(new Node<>(x, temp.getNext())); + } + } + } + + this.last = HelpCommands.getLast(first); + } + + public boolean exists(int x) { + Node temp = first; + while (temp != null) { + if (temp.getValue() == x) { + return true; + } + temp = temp.getNext(); + } + return false; + } + + public Node showMin() { + return last; + } + + public int getMax() { + int max = first.getValue(); + this.first = first.getNext(); + return max; + } + + public String toString() { + String str = "["; + Node pos = this.first; + while (pos != null) { + str = str + pos.getValue().toString(); + if (pos.getNext() != null) + str = str + " , "; + pos = pos.getNext(); + } + str = str + "]"; + return str; + } +} diff --git a/src/classes/MyBaseB.java b/src/classes/MyBaseB.java new file mode 100644 index 0000000..8bc92b9 --- /dev/null +++ b/src/classes/MyBaseB.java @@ -0,0 +1,64 @@ +package classes; + +import utils.HelpCommands; +import utils.Node; + +public class MyBaseB { + + private Node first; + private Node last; + + private int div7; + + public MyBaseB() { + this.first = null; + } + + public void insert(int x) { + if (x % 7 == 0) { + div7++; + } + if (first == null) { + this.first = new Node<>(x); + } + if (x > first.getValue()) { + this.first = new Node<>(x, this.first); + } else { + Node temp = first; + while (temp.getNext() != null) { + if (x > temp.getNext().getValue()) { + temp.setNext(new Node<>(x, temp.getNext())); + } + } + } + + this.last = HelpCommands.getLast(first); + } + + public int getMax() { + int max = first.getValue(); + this.first = first.getNext(); + if (max % 7 == 0) { + div7--; + } + return max; + } + + public boolean div7(){ + return div7 > 0; + } + + public String toString() { + String str = "["; + Node pos = this.first; + while (pos != null) { + str = str + pos.getValue().toString(); + if (pos.getNext() != null) + str = str + " , "; + pos = pos.getNext(); + } + str = str + "]"; + return str; + } + +} diff --git a/src/classes/kaufmanIsTheGoart.java b/src/classes/kaufmanIsTheGoart.java new file mode 100644 index 0000000..66d1518 --- /dev/null +++ b/src/classes/kaufmanIsTheGoart.java @@ -0,0 +1,12 @@ +package classes; + +import utils.BinNode; + +public void main() { +} + +public static BinNode buildTree(int[] preorder, int[] inorder) { + int i = 0; + BinNode tree = new BinNode<>(preorder[i]); + +} \ No newline at end of file diff --git a/src/utils/HelpCommands.java b/src/utils/HelpCommands.java index 1440b72..217951c 100644 --- a/src/utils/HelpCommands.java +++ b/src/utils/HelpCommands.java @@ -646,6 +646,20 @@ public static void addLast(Node node, T value) { node.setValue(value); } + public static Node getLast(Node node){ + while (node.getNext() != null) { + node = node.getNext(); + } + return node; + } + + public static void setByIndex(Node node, T value, int index){ + for (int i = 0; i < index - 1; i++) { + node = node.getNext(); + } + node.setNext(new Node<>(value, node.getNext())); + } + public static BinNode buildBinNode(int n) { BinNode root = new BinNode((int) (Math.random() * 99) + 1); BinNode bn = root;