Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. private void unionAux(Iterator<Node> unionIt, Iterator<Node> it1, Iterator<Node> it2)
  2. {
  3. if (it2.getValue().state == 1 || it1.getValue().state == 1)
  4. unionIt.addValue(Node.valueOf(1));
  5.  
  6. else if (it1.nodeType() == NodeType.DOUBLE || it2.nodeType() == NodeType.DOUBLE)
  7. {
  8. unionIt.addValue(Node.valueOf(2));
  9.  
  10. if (it1.nodeType() == NodeType.LEAF && it2.nodeType() == NodeType.DOUBLE)
  11. {
  12. unionIt.goLeft();
  13. it2.goLeft();
  14.  
  15. unionAux(unionIt, it1, it2);
  16.  
  17. int val1 = unionIt.getValue().state;
  18.  
  19. unionIt.goUp();
  20. it2.goUp();
  21.  
  22. unionIt.goRight();
  23. it2.goRight();
  24. unionAux(unionIt, it1, it2);
  25. int val2 = unionIt.getValue().state;
  26. unionIt.goUp();
  27. it2.goUp();
  28.  
  29. if (val1 == val2 && val1 != 2)
  30. {
  31. unionIt.clear();
  32. unionIt.addValue(Node.valueOf(val1));
  33. }
  34. }
  35. else if (it2.nodeType() != NodeType.LEAF || it1.nodeType() != NodeType.DOUBLE)
  36. {
  37. unionIt.goLeft();
  38. it1.goLeft();
  39. it2.goLeft();
  40.  
  41. unionAux(unionIt, it1, it2);
  42.  
  43. int val1 = unionIt.getValue().state;
  44.  
  45. unionIt.goUp();
  46. it1.goUp();
  47. it2.goUp();
  48.  
  49. unionIt.goRight();
  50. it1.goRight();
  51. it2.goRight();
  52.  
  53. unionAux(unionIt, it1, it2);
  54.  
  55. int val2 = unionIt.getValue().state;
  56.  
  57. unionIt.goUp();
  58. it1.goUp();
  59. it2.goUp();
  60.  
  61. if (val1 == val2 && val1 != 2)
  62. {
  63. unionIt.clear();
  64. unionIt.addValue(Node.valueOf(val1));
  65. }
  66. }
  67. else
  68. {
  69. unionIt.goLeft();
  70. it1.goLeft();
  71.  
  72. unionAux(unionIt, it1, it2);
  73.  
  74. int val1 = unionIt.getValue().state;
  75.  
  76. unionIt.goUp();
  77. it1.goUp();
  78.  
  79. unionIt.goRight();
  80. it1.goRight();
  81.  
  82. unionAux(unionIt, it1, it2);
  83.  
  84. int val2 = unionIt.getValue().state;
  85.  
  86. unionIt.goUp();
  87. it1.goUp();
  88.  
  89. if (val1 == val2 && val1 != 2)
  90. {
  91. unionIt.clear();
  92. unionIt.addValue(Node.valueOf(val1));
  93. }
  94. }
  95. }
  96.  
  97. else
  98. {
  99. Node newValue = Node.valueOf(it1.getValue().state);
  100. unionIt.addValue(newValue);
  101.  
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement