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

Function t_build_tree

src/tree/binary/builder/tournament.rs:133–166  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

131
132#[test]
133fn t_build_tree() {
134 /*
135 16
136 / \
137 16 14
138 / \ / \
139 16 13 10 14
140 / \ / \ / \ / \
141 7 16 8 13 10 9 12 14
142 / \ / \ / \ / \ / \ / \ / \ / \
143 7 6 15 16 8 4 13 3 5 10 9 1 12 2 11 14
144
145 */
146 let a = &[7, 6, 15, 16, 8, 4, 13, 3, 5, 10, 9, 1, 12, 2, 11, 14];
147
148 let tree: Tree<i32, i32> = do_build(a);
149 let r = unsafe { crate::tree::binary::traverse::PreOrderVisitor::recursive(&tree) };
150 assert_eq!(
151 r,
152 vec![
153 16, 16, 16, 7, 7, 6, 16, 15, 16, 13, 8, 8, 4, 13, 13, 3, 14, 10, 10, 5, 10, 9, 9, 1,
154 14, 12, 12, 2, 14, 11, 14
155 ]
156 );
157
158 let r = unsafe { crate::tree::binary::traverse::InOrderVisitor::recursive(&tree) };
159 assert_eq!(
160 r,
161 vec![
162 7, 7, 6, 16, 15, 16, 16, 16, 8, 8, 4, 13, 13, 13, 3, 16, 5, 10, 10, 10, 9, 9, 1, 14,
163 12, 12, 2, 14, 11, 14, 14
164 ]
165 );
166}
167
168#[test]
169fn t_pop() {

Callers

nothing calls this directly

Calls 1

do_buildFunction · 0.85

Tested by

no test coverage detected