mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-06 14:27:26 +08:00
make dfs same as c/c++ and other small improvement (#1543)
This commit is contained in:
@ -49,18 +49,11 @@ impl ArrayBinaryTree {
|
||||
|
||||
/* 层序遍历 */
|
||||
fn level_order(&self) -> Vec<i32> {
|
||||
let mut res = vec![];
|
||||
// 直接遍历数组
|
||||
for i in 0..self.size() {
|
||||
if let Some(val) = self.val(i) {
|
||||
res.push(val)
|
||||
}
|
||||
}
|
||||
res
|
||||
self.tree.iter().filter_map(|&x| x).collect()
|
||||
}
|
||||
|
||||
/* 深度优先遍历 */
|
||||
fn dfs(&self, i: i32, order: &str, res: &mut Vec<i32>) {
|
||||
fn dfs(&self, i: i32, order: &'static str, res: &mut Vec<i32>) {
|
||||
if self.val(i).is_none() {
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user