Partial exercise 2 and 3

This commit is contained in:
Simon Giesel 2019-05-13 22:06:56 +02:00
parent 0956126750
commit ce78232cf4
8 changed files with 143 additions and 13 deletions

Binary file not shown.

BIN
bin/app/BinaryNode.class Normal file

Binary file not shown.

BIN
bin/app/LinkedList.class Normal file

Binary file not shown.

BIN
bin/app/Node.class Normal file

Binary file not shown.

View file

@ -3,20 +3,130 @@ package app;
public class App { public class App {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
/** Aufgabe 1.1 - 1.3 */ /** Aufgabe 1.1 - 1.3 */
System.out.println("++++ Aufgabe 1.1 - 1.3 ++++"); // System.out.println("++++ Aufgabe 1.1 - 1.3 ++++");
MyStack<String> stack = new MyStack<String>(); // MyStack<String> stack = new MyStack<String>();
stack.push("hello"); // stack.push("hello");
stack.push("world"); // stack.push("world");
stack.push("123"); // stack.push("123");
System.out.println(stack.pop()); // System.out.println(stack.pop());
System.out.println(stack.pop()); // System.out.println(stack.pop());
System.out.println(stack.pop()); // System.out.println(stack.pop());
/** Aufgabe 1.4 */ // /** Aufgabe 1.4 */
System.out.println("++++ Aufgabe 1.4 ++++"); // System.out.println("++++ Aufgabe 1.4 ++++");
tokenizeAndCalc("( 2 + 3 )"); // tokenizeAndCalc("( 2 + 3 )");
tokenizeAndCalc("( 3 - ( 2 * 3 ) )"); // tokenizeAndCalc("( 3 - ( 2 * 3 ) )");
tokenizeAndCalc("( ( 5 * 4 ) - ( 2 * ( 3 / 4 ) ) )"); // tokenizeAndCalc("( ( 5 * 4 ) - ( 2 * ( 3 / 4 ) ) )");
// /** Aufgabe 2.1 - 2.2 */
// System.out.println("++++ Aufgabe 2.1 - 2.2 ++++");
// Node<Integer> n1 = new Node<Integer>();
// Node<Integer> n2 = new Node<Integer>();
// Node<Integer> n3 = new Node<Integer>();
// Node<Integer> n4 = new Node<Integer>();
// n1.item = 1;
// n2.item = 2;
// n3.item = 3;
// n4.item = 4;
// n1.last = null;
// n1.next = n2;
// n2.last = n1;
// n2.next = n3;
// n3.last = n2;
// n3.next = n4;
// n4.last = n3;
// n4.next = null;
// n3.item = null;
// n2.next = n4;
// System.out.println(n1.item);
// System.out.println(n1.next.item);
// System.out.println(n1.next.next.item);
/** Aufgabe 3.1 */
System.out.println("++++ Aufgabe 3.1 ++++");
BinaryNode ba1 = new BinaryNode();
BinaryNode ba2 = new BinaryNode();
BinaryNode ba3 = new BinaryNode();
ba1.item = "+";
ba2.item = "2";
ba3.item = "3";
ba2.parent = ba1;
ba3.parent = ba1;
ba1.left = ba2;
ba1.right = ba2;
BinaryNode bb1 = new BinaryNode();
BinaryNode bb2 = new BinaryNode();
BinaryNode bb3 = new BinaryNode();
BinaryNode bb4 = new BinaryNode();
BinaryNode bb5 = new BinaryNode();
bb1.item = "*";
bb2.item = "5";
bb3.item = "+";
bb4.item = "2";
bb5.item = "3";
bb2.parent = bb1;
bb3.parent = bb1;
bb4.parent = bb3;
bb5.parent = bb3;
bb1.left = bb2;
bb1.right = bb3;
bb3.left = bb4;
bb3.left = bb5;
BinaryNode bc1 = new BinaryNode();
BinaryNode bc2 = new BinaryNode();
BinaryNode bc3 = new BinaryNode();
BinaryNode bc4 = new BinaryNode();
BinaryNode bc5 = new BinaryNode();
BinaryNode bc6 = new BinaryNode();
BinaryNode bc7 = new BinaryNode();
bc1.item = "+";
bc2.item = "*";
bc3.item = "2";
bc4.item = "3";
bc5.item = "*";
bc6.item = "4";
bc7.item = "5";
bc2.parent = bc1;
bc3.parent = bc2;
bc4.parent = bc2;
bc5.parent = bc1;
bc6.parent = bc5;
bc7.parent = bc5;
bc1.left = bc2;
bc1.right = bc5;
bc2.left = bc3;
bc2.right = bc4;
bc5.left = bc6;
bc5.right = bc7;
BinaryNode bd1 = new BinaryNode();
BinaryNode bd2 = new BinaryNode();
BinaryNode bd3 = new BinaryNode();
BinaryNode bd4 = new BinaryNode();
BinaryNode bd5 = new BinaryNode();
BinaryNode bd6 = new BinaryNode();
BinaryNode bd7 = new BinaryNode();
bd1.item = "*";
bd2.item = "2";
bd3.item = "+";
bd4.item = "3";
bd5.item = "4";
bd6.item = "*";
bd7.item = "5";
bd2.parent = bd1;
// bd3.parent = // Nicht möglich. Da Braum 3 Zweige benötigt.
}
private static boolean find(BinaryNode tree, String find) {
if (tree.item == find)
return true;
else {
// TODO: implement walk algorithm
return false || true;
}
} }
private static void tokenizeAndCalc(String in) { private static void tokenizeAndCalc(String in) {

8
src/app/BinaryNode.java Normal file
View file

@ -0,0 +1,8 @@
package app;
public class BinaryNode {
String item;
BinaryNode parent;
BinaryNode left;
BinaryNode right;
}

5
src/app/LinkedList.java Normal file
View file

@ -0,0 +1,5 @@
package app;
public class LinkedList<Item> {
// TODO:
}

7
src/app/Node.java Normal file
View file

@ -0,0 +1,7 @@
package app;
public class Node<Item> {
Item item;
Node<Item> next;
Node<Item> last;
}