Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void unionAux(Iterator<Node> unionIt, Iterator<Node> it1, Iterator<Node> it2)
- {
- if (it2.getValue().state == 1 || it1.getValue().state == 1)
- unionIt.addValue(Node.valueOf(1));
- else if (it1.nodeType() == NodeType.DOUBLE || it2.nodeType() == NodeType.DOUBLE)
- {
- unionIt.addValue(Node.valueOf(2));
- if (it1.nodeType() == NodeType.LEAF && it2.nodeType() == NodeType.DOUBLE)
- {
- unionIt.goLeft();
- it2.goLeft();
- unionAux(unionIt, it1, it2);
- int val1 = unionIt.getValue().state;
- unionIt.goUp();
- it2.goUp();
- unionIt.goRight();
- it2.goRight();
- unionAux(unionIt, it1, it2);
- int val2 = unionIt.getValue().state;
- unionIt.goUp();
- it2.goUp();
- if (val1 == val2 && val1 != 2)
- {
- unionIt.clear();
- unionIt.addValue(Node.valueOf(val1));
- }
- }
- else if (it2.nodeType() != NodeType.LEAF || it1.nodeType() != NodeType.DOUBLE)
- {
- unionIt.goLeft();
- it1.goLeft();
- it2.goLeft();
- unionAux(unionIt, it1, it2);
- int val1 = unionIt.getValue().state;
- unionIt.goUp();
- it1.goUp();
- it2.goUp();
- unionIt.goRight();
- it1.goRight();
- it2.goRight();
- unionAux(unionIt, it1, it2);
- int val2 = unionIt.getValue().state;
- unionIt.goUp();
- it1.goUp();
- it2.goUp();
- if (val1 == val2 && val1 != 2)
- {
- unionIt.clear();
- unionIt.addValue(Node.valueOf(val1));
- }
- }
- else
- {
- unionIt.goLeft();
- it1.goLeft();
- unionAux(unionIt, it1, it2);
- int val1 = unionIt.getValue().state;
- unionIt.goUp();
- it1.goUp();
- unionIt.goRight();
- it1.goRight();
- unionAux(unionIt, it1, it2);
- int val2 = unionIt.getValue().state;
- unionIt.goUp();
- it1.goUp();
- if (val1 == val2 && val1 != 2)
- {
- unionIt.clear();
- unionIt.addValue(Node.valueOf(val1));
- }
- }
- }
- else
- {
- Node newValue = Node.valueOf(it1.getValue().state);
- unionIt.addValue(newValue);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement