Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Tnode buildFromRPN (String pol) {
- List<Tnode> tList = correctExpression(pol);
- int counter = 0;
- while (tList.size() > 1) {
- if (tList.size() < 3) {
- throw new RuntimeException("Few invoices in statement");
- }
- if (isDigit(tList.get(counter)) || tList.get(counter).getFirstChild() != null) {
- if (isDigit(tList.get(counter + 1)) || tList.get(counter + 1).getFirstChild() != null) {
- if (!isDigit(tList.get(counter + 2)) && tList.get(counter + 2).getFirstChild() == null) {
- Tnode top = tList.get(counter + 2);
- Tnode left = tList.get(counter);
- Tnode right = tList.get(counter + 1);
- left.setNextSibling(right);
- top.setFirstChild(left);
- tList.remove(counter + 1);
- tList.remove(counter);
- counter = 0;
- continue;
- }
- }
- }
- counter++;
- }
- return tList.get(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement