This commit is contained in:
2022-11-24 15:17:33 +01:00
parent b7f44474fc
commit b18f49ddd5
13 changed files with 412 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
import java.util.ArrayList;
import java.util.List;
public class Node<T> {
private T value;
private List<Node<T>> subNodes;
public Node(T value) {
this.value = value;
this.subNodes = new ArrayList<>();
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
public List<Node<T>> getSubNodes() {
return this.subNodes;
}
public boolean addSubNode(Node<T> node) {
return subNodes.add(node);
}
public boolean remSubNode(Node<T> node) {
return subNodes.remove(node);
}
public void showNode() {
System.out.print(value.toString() + " ");
for (Node<T> subNode : subNodes) {
subNode.showNode();
}
}
}

View File

@@ -0,0 +1,34 @@
import java.util.ArrayDeque;
/**
* Arithmetique
*/
public class Prefixe {
public static void main(String[] args) {
ArrayDeque<Node<String>> pile = new ArrayDeque<>();
for (String arg : args) {
try {
Integer.parseInt(arg);
pile.addFirst(new Node<String>(arg));
} catch (NumberFormatException e) {
if (pile.size() < 2) {
System.err.println("Invalid stack size.");
return;
}
Node<String> n2 = pile.pollFirst();
Node<String> n1 = pile.pollFirst();
Node<String> n3 = new Node<String>(arg);
n3.addSubNode(n1);
n3.addSubNode(n2);
pile.addFirst(n3);
}
}
pile.pollFirst().showNode();
System.out.println("");
}
}

View File

@@ -0,0 +1,19 @@
public class Tree<T> {
private Node<T> rootNode;
public Tree() {
rootNode = new Node<T>(null);
}
public void setRootNode(Node<T> rootNode) {
this.rootNode = rootNode;
}
public Node<T> getRootNode() {
return rootNode;
}
public void showTree() {
rootNode.showNode();
}
}