Skip to content
Snippets Groups Projects
Commit 1d273c14 authored by tim's avatar tim
Browse files

ausgabe hinzugefügt

parent 5ad2592a
No related branches found
No related tags found
No related merge requests found
......@@ -6,4 +6,8 @@ public class Ahne{
name = pName;
geschlecht = pGeschlecht;
}
public String toString(){
return(name);
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@ public class Main{
private BinaryTree<Ahne> lisasAhnenbaum;
public void Main(){
public Main(){
BinaryTree<Ahne> b1 = new BinaryTree<Ahne>(new Ahne("Jacueline Bouvier", 'w'));
BinaryTree<Ahne> b2 = new BinaryTree<Ahne>(new Ahne("Clancy Bouvier", 'm'));
BinaryTree<Ahne> b3 = new BinaryTree<Ahne>(new Ahne("Marge Simpson", 'w'), b1, b2);
......@@ -11,4 +11,46 @@ public class Main{
BinaryTree<Ahne> b6 = new BinaryTree<Ahne>(new Ahne("Homer Simpson", 'm'), b4, b5);
lisasAhnenbaum = new BinaryTree<Ahne>(new Ahne("Lisa Simpson", 'w'), b3, b6);
}
public void ausgabeAhnenbaum(){
System.out.println("\npreorder:");
preorder(lisasAhnenbaum);
System.out.println("\npostorder:");
postorder(lisasAhnenbaum);
System.out.println("\ninorder:");
inorder(lisasAhnenbaum);
}
public void preorder(BinaryTree<Ahne> tree){
preorderIntern(tree);
}
private void preorderIntern(BinaryTree<Ahne> tree){
if(!tree.isEmpty()){
System.out.println(tree.getContent());
preorderIntern(tree.getLeftTree());
preorderIntern(tree.getRightTree());
}
}
public void postorder(BinaryTree<Ahne> tree){
postorderIntern(tree);
}
private void postorderIntern(BinaryTree<Ahne> tree){
if(!tree.isEmpty()){
postorderIntern(tree.getLeftTree());
postorderIntern(tree.getRightTree());
System.out.println(tree.getContent());
}
}
public void inorder(BinaryTree<Ahne> tree){
inorderIntern(tree);
}
private void inorderIntern(BinaryTree<Ahne> tree){
if(!tree.isEmpty()){
inorderIntern(tree.getLeftTree());
System.out.println(tree.getContent());
inorderIntern(tree.getRightTree());
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment