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

Method iterate

src/tree/binary/traverse.rs:119–137  ·  view source on GitHub ↗

# Safety This is highly unsafe, due to pointer 时间复杂度 O(n), 空间复杂度 O(n)

(tree: &Tree<K, V>)

Source from the content-addressed store, hash-verified

117 /// This is highly unsafe, due to pointer
118 /// 时间复杂度 O(n), 空间复杂度 O(n)
119 pub unsafe fn iterate<K, V>(tree: &Tree<K, V>) -> Vec<K>
120 where
121 K: Copy,
122 {
123 let mut results = vec![];
124 let mut stack = vec![];
125 //point current node
126 let mut p = tree.root;
127 while let Some(node) = p {
128 results.push(node.as_ref().key); //visit result
129 for pp in [node.as_ref().right, node.as_ref().left].iter().flatten() {
130 stack.push(*pp);
131 }
132
133 p = stack.pop();
134 }
135
136 results
137 }
138
139 /// # Safety
140 ///

Callers

nothing calls this directly

Calls 10

pushMethod · 0.80
push_backMethod · 0.80
pop_frontMethod · 0.80
into_iterMethod · 0.80
iterMethod · 0.45
popMethod · 0.45
is_emptyMethod · 0.45
containsMethod · 0.45
insertMethod · 0.45
reverseMethod · 0.45

Tested by

no test coverage detected