Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fn splay (&mut self, node: &mut Node<T>) {
enum SplayType {NoSplay, Zig, ZigZig, ZigZag};
loop {
let splayType = match node.get_parent() {
None => NoSplay,
Some(parent) => {
match parent.get_parent() {
None => Zig,
Some(_) => {
if parent.is_left() == node.is_left() {
ZigZig
} else {
ZigZag
}
}
}
}
};
match splayType {
NoSplay => return,
Zig => self.rotate_up(node),
ZigZag => {
self.rotate_up(node);
self.rotate_up(node);
}
ZigZig => {
self.rotate_up(node.get_parent_mut().unwrap());
self.rotate_up(node)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.