MCPcopy Create free account
hub / github.com/douchuan/algorithm / t_rotate_right

Function t_rotate_right

src/tree/binary/rb.rs:346–364  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

344
345#[test]
346fn t_rotate_right() {
347 use crate::tree::binary::traverse::{InOrderVisitor, PreOrderVisitor};
348 use crate::tree::binary::Tree;
349
350 let mut tree = Tree::default();
351 for v in vec![10, 5, 15, 14, 16] {
352 let p = unsafe { bst::insert(tree.root, v, v).ok() };
353 if tree.root.is_none() {
354 tree.root = p;
355 }
356 }
357
358 unsafe {
359 tree.root = rotate_left(tree.root, tree.root.unwrap());
360 tree.root = rotate_right(tree.root, tree.root.unwrap());
361 assert_eq!(PreOrderVisitor::recursive(&tree), vec![10, 5, 15, 14, 16]);
362 assert_eq!(InOrderVisitor::recursive(&tree), vec![5, 10, 14, 15, 16]);
363 }
364}

Callers

nothing calls this directly

Calls 4

is_noneMethod · 0.80
insertFunction · 0.70
rotate_leftFunction · 0.70
rotate_rightFunction · 0.70

Tested by

no test coverage detected