Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FHs_treeNode<E> splay( FHs_treeNode<E> root, E x )
- {
- FHs_treeNode rtTree = null;
- FHs_treeNode lftTree = null;
- FHs_treeNode rtTreeMin = null;
- FHs_treeNode lftTreeMax = null;
- int compareResult;
- while (root != null)
- {
- compareResult = x.compareTo(root.data);
- if (compareResult < 0)
- {
- if (root.lftChild == null)
- break;
- //Zig Zig left
- if (x.compareTo(root.lftChild.data) < 0)
- {
- rotateWithLeftChild(root);
- if (root.lftChild == null)
- break;
- }
- rtTreeMin.lftChild = root;
- rtTreeMin = root;
- root = root.lftChild;
- }
- else if (compareResult > 0)
- {
- if (root.rtChild == null)
- break;
- //Zig Zig left
- if (x.compareTo(root.rtChild.data) < 0)
- {
- rotateWithRightChild(root);
- if (root.lftChild == null)
- break;
- }
- lftTreeMax.rtChild = root;
- lftTreeMax = root;
- root = root.rtChild;
- }
- else
- break;
- }
- if (lftTree != null)
- {
- lftTreeMax.lftChild = root.lftChild;
- root.lftChild = lftTree;
- }
- if (rtTree != null)
- {
- rtTreeMin.rtChild = root.rtChild;
- root.rtChild = rtTree;
- }
- return root;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement