Fuck la logique

This commit is contained in:
2017-03-29 10:06:05 +02:00
parent 7a70d6130e
commit cd186e292d
2 changed files with 0 additions and 115 deletions

View File

@@ -2,8 +2,6 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
/** /**
* Created by xawirses on 28/02/17. * Created by xawirses on 28/02/17.

View File

@@ -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);
findPatern(root);
} }
private Node tree(int pos) { private Node tree(int pos) {
@@ -51,116 +50,4 @@ public class Tree {
if (n.getRigthChild() != null) if (n.getRigthChild() != null)
displayNode(n.getRigthChild(),lvl+1); displayNode(n.getRigthChild(),lvl+1);
} }
private void findPatern (Node node) {
if (replacePatern(node)){
if (node.getFather() == null)
findPatern(root);
else
findPatern(node.getFather());
} else {
if( node.getLeftChild() != null)
findPatern(node.getLeftChild());
if( node.getRigthChild() != null)
findPatern(node.getRigthChild());
}
}
private boolean replacePatern (Node father) {
Node leftChild = father.getLeftChild();
Node rightChild = father.getRigthChild();
switch (father.getNode()) {
case '!' :
switch (leftChild.getNode()){
case '!':
Node child = leftChild.getLeftChild();
appliedGreatFather(father, child);
break;
case '|' :
Node lc = leftChild.getLeftChild();
Node rc = leftChild.getRigthChild();
Node notlc = new Node(null,lc,null,'!', lc.getLvl() +1);
Node notrc = new Node(null,rc,null,'!', rc.getLvl() +1);
notlc.setPos(1);
notrc.setPos(2);
rc.setPos(1);
lc.setFather(notlc);
rc.setFather(notrc);
Node greatfather = new Node(father.getFather(),notlc,notrc,'&',notlc.getLvl() + notrc.getLvl() +1);
notlc.setFather(greatfather);
notrc.setFather(greatfather);
appliedGreatFather(father, greatfather);
break;
case '&' :
Node lc_2 = leftChild.getLeftChild();
Node rc_2 = leftChild.getRigthChild();
Node notlc_2 = new Node(null,lc_2,null,'!', lc_2.getLvl() +1);
Node notrc_2 = new Node(null,rc_2,null,'!', rc_2.getLvl() +1);
lc_2.setFather(notlc_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);
notlc_2.setFather(greatfather_2);
notrc_2.setFather(greatfather_2);
appliedGreatFather(father, greatfather_2);
break;
case '>' :
Node lc_3 = leftChild.getLeftChild();
Node rc_3 = leftChild.getRigthChild();
Node notrc_3 = new Node(null,rc_3,null,'!', rc_3.getLvl() +1);
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);
lc_3.setFather(greatfather_3);
notrc_3.setFather(greatfather_3);
appliedGreatFather(father, greatfather_3);
break;
default:
return false;
}
break;
case '>' :
Node notlc = new Node(null,leftChild,null,'!', leftChild.getLvl() +1);
leftChild.setFather(notlc);
notlc.setPos(1);
Node greatfather = new Node(father.getFather(),notlc,rightChild,'|',notlc.getLvl() + rightChild.getLvl() +1);
notlc.setFather(greatfather);
rightChild.setFather(greatfather);
appliedGreatFather(father, greatfather);
break;
default:
return false;
}
return true;
}
private void appliedGreatFather (Node father, Node greatFather) {
if (father.getPos() == 1) {
father.getFather().setLeftChild(greatFather);
greatFather.setFather(father);
greatFather.setPos(1);
} else if (father.getPos() == 2) {
father.getFather().setRigthChild(greatFather);
greatFather.setFather(father);
greatFather.setPos(2);
} else {
root = greatFather;
greatFather.setFather(null);
greatFather.setPos(0);
}
}
} }