阅读以下C++实现的二叉树深度优先搜索迭代版代码,横线上应填写的正确代码是?
void dfs(TreeNode* root) {
if (root == nullptr)
return;
stack<TreeNode*> s;
s.push(root);
while (!s.empty()) {
________________________ // 在此处填入代码
cout << node->value << " ";
if (node->right) s.push(node->right);
if (node->left) s.push(node->left);
}
}
正在加载题目数据…
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析