Guest User

Untitled

a guest
Apr 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. private static Node root;
  2.  
  3. public static void makeTree(String input) {
  4.  
  5. Node newNode = new Node();
  6. newNode.data = input.charAt(0);
  7.  
  8. for (int i = 0; i < input.length(); i++) {
  9.  
  10. if (root == null && (input.charAt(i) == '*' || input.charAt(i) == '/' || input.charAt(i) == '%')) {
  11.  
  12. root.data = input.charAt(i);
  13. root.leftChild.data = input.charAt(i - 2);
  14. root.rightChild.data = input.charAt(i - 1);
  15. removeCharAt(input, i);
  16. removeCharAt(input, i - 1);
  17. removeCharAt(input, i - 1);
  18.  
  19. }
  20.  
  21. if (input.charAt(i) == '*' || input.charAt(i) == '/' || input.charAt(i) == '%') {
  22.  
  23. root.rightChild = root;
  24. root.data = input.charAt(i);
  25. root.leftChild.data = input.charAt(i - 1);
  26. removeCharAt(input, i);
  27. removeCharAt(input, i - 1);
  28.  
  29. }
  30.  
  31. if (input.charAt(i) == '+' || input.charAt(i) == '-') {
  32.  
  33. root.rightChild.data = root.data;
  34. root.data = input.charAt(i);
  35. root.leftChild.data = input.charAt(0);
  36. removeCharAt(input, i);
  37. removeCharAt(input, 0);
  38.  
  39. }
  40. }
  41. }
  42.  
  43. public class Node {
  44.  
  45. int data;
  46. Node leftChild;
  47. Node rightChild;
  48.  
  49. }
Add Comment
Please, Sign In to add comment