From cd186e292df5daa5afee78e805b367beadcc5054 Mon Sep 17 00:00:00 2001 From: Xawirses Date: Wed, 29 Mar 2017 10:06:05 +0200 Subject: [PATCH] Fuck la logique --- src/Expression.java | 2 - src/Tree.java | 113 -------------------------------------------- 2 files changed, 115 deletions(-) diff --git a/src/Expression.java b/src/Expression.java index 6ad25ad..a30b87d 100644 --- a/src/Expression.java +++ b/src/Expression.java @@ -2,8 +2,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; -import java.util.List; -import java.util.Stack; /** * Created by xawirses on 28/02/17. diff --git a/src/Tree.java b/src/Tree.java index bd84d5c..d90a95b 100644 --- a/src/Tree.java +++ b/src/Tree.java @@ -9,7 +9,6 @@ public class Tree { Tree (String exp){ this.exp = exp; root = tree(0); - findPatern(root); } private Node tree(int pos) { @@ -51,116 +50,4 @@ public class Tree { if (n.getRigthChild() != null) 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); - } - } } \ No newline at end of file