Helsong
Smash Ace
Dumb Questions continued: Are you changing the tree when you do rotateRight(node)? after all, since root is a global variable(I'm assuming referencing the root of the splay tree), then root=rotateRight(root); would work, given that your method is working as it should. Sounds like it is.it works if i directly set the root. root is a global variable of the SplayTree object. doing something like root = rotateRight(root); affects the tree just fine.
my splay function takes in a node. doing something like node = rotateRight(node); does not affect the tree
my rotateRight method:
The returned node from rotateRight is exactly what i need to set the passed in node toCode:private SplayNode<E> rotateRight(SplayNode node) { SplayNode tmp = node.getLeft(); node.setLeft(tmp.getRight()); tmp.setRight(node); node.setParent(tmp); return tmp; }
So, I'd imagine the problem is that using node = rotateRight(node); doesn't actually touch the tree itself, but rather just a node object that's a copy of a part of the tree? You may need to reference the tree using root to affect the tree itself. Finding the node you want to change and then sending in that node doesn't quite work, as you're then sending in a node that's a copy of that section of the tree, not the tree itself. At least, that's my best guess.
@
![eideeiit](/data/avatars/s/247/247752.jpg?1480685067)
Last edited: