Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions src/L24.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import utils.BinNode;

public class L24 extends Main {

public static void printAll(BinNode<Integer> root) {
printAll(root, 0);
}

public static void printAll(BinNode<Integer> 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<Integer> root = buildTree(10);
printMeTree(root);
printAll(root);

}

}
Binary file added src/Test1B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/classes/Card.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package classes;

public record Card(String color, int num) {
}
66 changes: 66 additions & 0 deletions src/classes/MyBaseA.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package classes;

import utils.HelpCommands;
import utils.Node;

public class MyBaseA {

private Node<Integer> first;
private Node<Integer> 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<Integer> 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<Integer> temp = first;
while (temp != null) {
if (temp.getValue() == x) {
return true;
}
temp = temp.getNext();
}
return false;
}

public Node<Integer> showMin() {
return last;
}

public int getMax() {
int max = first.getValue();
this.first = first.getNext();
return max;
}

public String toString() {
String str = "[";
Node<Integer> pos = this.first;
while (pos != null) {
str = str + pos.getValue().toString();
if (pos.getNext() != null)
str = str + " , ";
pos = pos.getNext();
}
str = str + "]";
return str;
}
}
64 changes: 64 additions & 0 deletions src/classes/MyBaseB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package classes;

import utils.HelpCommands;
import utils.Node;

public class MyBaseB {

private Node<Integer> first;
private Node<Integer> 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<Integer> 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<Integer> pos = this.first;
while (pos != null) {
str = str + pos.getValue().toString();
if (pos.getNext() != null)
str = str + " , ";
pos = pos.getNext();
}
str = str + "]";
return str;
}

}
12 changes: 12 additions & 0 deletions src/classes/kaufmanIsTheGoart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package classes;

import utils.BinNode;

public void main() {
}

public static BinNode<Integer> buildTree(int[] preorder, int[] inorder) {
int i = 0;
BinNode<Integer> tree = new BinNode<>(preorder[i]);

}
14 changes: 14 additions & 0 deletions src/utils/HelpCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,20 @@ public static <T> void addLast(Node<T> node, T value) {
node.setValue(value);
}

public static <T> Node<T> getLast(Node<T> node){
while (node.getNext() != null) {
node = node.getNext();
}
return node;
}

public static <T> void setByIndex(Node<T> 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<Integer> buildBinNode(int n) {
BinNode<Integer> root = new BinNode<Integer>((int) (Math.random() * 99) + 1);
BinNode<Integer> bn = root;
Expand Down