# Safety This is highly unsafe, due to pointer 时间复杂度 O(n), 空间复杂度 O(n)
(tree: &Tree<K, V>)
| 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 | /// |