Advertisement
UniQuet0p1

Untitled

Oct 31st, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. public static Tnode buildFromRPN (String pol) {
  2. List<Tnode> tList = correctExpression(pol);
  3. int counter = 0;
  4.  
  5. while (tList.size() > 1) {
  6. if (tList.size() < 3) {
  7. throw new RuntimeException("Few invoices in statement");
  8. }
  9.  
  10. if (isDigit(tList.get(counter)) || tList.get(counter).getFirstChild() != null) {
  11. if (isDigit(tList.get(counter + 1)) || tList.get(counter + 1).getFirstChild() != null) {
  12. if (!isDigit(tList.get(counter + 2)) && tList.get(counter + 2).getFirstChild() == null) {
  13. Tnode top = tList.get(counter + 2);
  14. Tnode left = tList.get(counter);
  15. Tnode right = tList.get(counter + 1);
  16. left.setNextSibling(right);
  17. top.setFirstChild(left);
  18. tList.remove(counter + 1);
  19. tList.remove(counter);
  20. counter = 0;
  21. continue;
  22. }
  23. }
  24. }
  25. counter++;
  26. }
  27. return tList.get(0);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement