fix tree
This commit is contained in:
@@ -15,7 +15,6 @@ public class Expression {
|
||||
public Expression(){
|
||||
readExpression();
|
||||
parse();
|
||||
negExpressionPrefixe();
|
||||
}
|
||||
|
||||
public void readExpression(){
|
||||
@@ -103,7 +102,6 @@ public class Expression {
|
||||
reversePrefix += stack.pollLast();
|
||||
|
||||
expressionPrefixe = reverseExpression(reversePrefix);
|
||||
System.out.println(expressionPrefixe);
|
||||
}
|
||||
|
||||
public String getExpression() {
|
||||
@@ -114,12 +112,16 @@ public class Expression {
|
||||
return expressionPrefixe;
|
||||
}
|
||||
|
||||
private void negExpressionPrefixe (){
|
||||
public void negExpressionPrefixe (){
|
||||
expressionPrefixe = "!" + expressionPrefixe;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Expression e = new Expression();
|
||||
e.negExpressionPrefixe();
|
||||
System.out.println(e.getExpressionPrefixe());
|
||||
System.out.println();
|
||||
|
||||
Tree t = new Tree(e.getExpressionPrefixe());
|
||||
t.display();
|
||||
}
|
||||
|
||||
@@ -20,14 +20,14 @@ public class Tree {
|
||||
Node f = new Node(null, fils, null, item, 1+fils.getLvl());
|
||||
fils.setFather(f);
|
||||
return f;
|
||||
}
|
||||
|
||||
} else {
|
||||
Node filsG = tree(pos+1);
|
||||
Node filsD = tree(pos+filsG.getLvl());
|
||||
Node filsD = tree(pos+filsG.getLvl()+1);
|
||||
Node f = new Node(null, filsG, filsD, item, filsG.getLvl() + filsD.getLvl()+1);
|
||||
filsG.setFather(f);
|
||||
filsD.setFather(f);
|
||||
return f;
|
||||
}
|
||||
} else {
|
||||
return new Node(null, null, null, item, 1);
|
||||
}
|
||||
@@ -40,6 +40,7 @@ public class Tree {
|
||||
private void displayNode(Node n, int lvl){
|
||||
for (int i = 0; i < lvl; i++)
|
||||
System.out.print("-");
|
||||
|
||||
n.display();
|
||||
if (n.getLeftChild() != null)
|
||||
displayNode(n.getLeftChild(),lvl+1);
|
||||
|
||||
Reference in New Issue
Block a user