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