fix patern
This commit is contained in:
@@ -9,7 +9,6 @@ public class Tree {
|
|||||||
Tree (String exp){
|
Tree (String exp){
|
||||||
this.exp = exp;
|
this.exp = exp;
|
||||||
root = tree(0);
|
root = tree(0);
|
||||||
display();
|
|
||||||
findPatern(root);
|
findPatern(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +82,11 @@ public class Tree {
|
|||||||
|
|
||||||
Node notlc = new Node(null,lc,null,'!', lc.getLvl() +1);
|
Node notlc = new Node(null,lc,null,'!', lc.getLvl() +1);
|
||||||
Node notrc = new Node(null,rc,null,'!', rc.getLvl() +1);
|
Node notrc = new Node(null,rc,null,'!', rc.getLvl() +1);
|
||||||
|
|
||||||
|
notlc.setPos(1);
|
||||||
|
notrc.setPos(2);
|
||||||
|
rc.setPos(1);
|
||||||
|
|
||||||
lc.setFather(notlc);
|
lc.setFather(notlc);
|
||||||
rc.setFather(notrc);
|
rc.setFather(notrc);
|
||||||
|
|
||||||
@@ -100,6 +104,10 @@ public class Tree {
|
|||||||
lc_2.setFather(notlc_2);
|
lc_2.setFather(notlc_2);
|
||||||
rc_2.setFather(notrc_2);
|
rc_2.setFather(notrc_2);
|
||||||
|
|
||||||
|
notlc_2.setPos(1);
|
||||||
|
notrc_2.setPos(2);
|
||||||
|
rc_2.setPos(1);
|
||||||
|
|
||||||
Node greatfather_2 = new Node(father.getFather(),notlc_2,notrc_2,'|',notlc_2.getLvl() + notrc_2.getLvl() +1);
|
Node greatfather_2 = new Node(father.getFather(),notlc_2,notrc_2,'|',notlc_2.getLvl() + notrc_2.getLvl() +1);
|
||||||
notlc_2.setFather(greatfather_2);
|
notlc_2.setFather(greatfather_2);
|
||||||
notrc_2.setFather(greatfather_2);
|
notrc_2.setFather(greatfather_2);
|
||||||
@@ -112,6 +120,9 @@ public class Tree {
|
|||||||
Node notrc_3 = new Node(null,rc_3,null,'!', rc_3.getLvl() +1);
|
Node notrc_3 = new Node(null,rc_3,null,'!', rc_3.getLvl() +1);
|
||||||
rc_3.setFather(notrc_3);
|
rc_3.setFather(notrc_3);
|
||||||
|
|
||||||
|
notrc_3.setPos(2);
|
||||||
|
rc_3.setPos(1);
|
||||||
|
|
||||||
Node greatfather_3 = new Node(father.getFather(),lc_3,notrc_3,'&',lc_3.getLvl() + notrc_3.getLvl() +1);
|
Node greatfather_3 = new Node(father.getFather(),lc_3,notrc_3,'&',lc_3.getLvl() + notrc_3.getLvl() +1);
|
||||||
lc_3.setFather(greatfather_3);
|
lc_3.setFather(greatfather_3);
|
||||||
notrc_3.setFather(greatfather_3);
|
notrc_3.setFather(greatfather_3);
|
||||||
@@ -125,7 +136,7 @@ public class Tree {
|
|||||||
case '>' :
|
case '>' :
|
||||||
Node notlc = new Node(null,leftChild,null,'!', leftChild.getLvl() +1);
|
Node notlc = new Node(null,leftChild,null,'!', leftChild.getLvl() +1);
|
||||||
leftChild.setFather(notlc);
|
leftChild.setFather(notlc);
|
||||||
|
notlc.setPos(1);
|
||||||
Node greatfather = new Node(father.getFather(),notlc,rightChild,'|',notlc.getLvl() + rightChild.getLvl() +1);
|
Node greatfather = new Node(father.getFather(),notlc,rightChild,'|',notlc.getLvl() + rightChild.getLvl() +1);
|
||||||
notlc.setFather(greatfather);
|
notlc.setFather(greatfather);
|
||||||
rightChild.setFather(greatfather);
|
rightChild.setFather(greatfather);
|
||||||
@@ -141,12 +152,15 @@ public class Tree {
|
|||||||
if (father.getPos() == 1) {
|
if (father.getPos() == 1) {
|
||||||
father.getFather().setLeftChild(greatFather);
|
father.getFather().setLeftChild(greatFather);
|
||||||
greatFather.setFather(father);
|
greatFather.setFather(father);
|
||||||
|
greatFather.setPos(1);
|
||||||
} else if (father.getPos() == 2) {
|
} else if (father.getPos() == 2) {
|
||||||
father.getFather().setRigthChild(greatFather);
|
father.getFather().setRigthChild(greatFather);
|
||||||
greatFather.setFather(father);
|
greatFather.setFather(father);
|
||||||
|
greatFather.setPos(2);
|
||||||
} else {
|
} else {
|
||||||
root = greatFather;
|
root = greatFather;
|
||||||
greatFather.setFather(null);
|
greatFather.setFather(null);
|
||||||
|
greatFather.setPos(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user