单选题 适中
#19793

下列代码实现了树的深度优先遍历,则横线处应填入( )。 struct TreeNode { int val ; TreeNode * left ; TreeNo…

下列代码实现了树的深度优先遍历,则横线处应填入( )。

struct TreeNode {
	int val;
	TreeNode* left;
	TreeNode* right;
	TreeNode(int x): val(x), left(nullptr), right(nullptr) {}
};
void dfs(TreeNode* root) {
	if (!root) return;
	stack<TreeNode*> st;
	st.push(root);
	while (!st.empty()) {
		TreeNode* node = st.top(); st.pop();
		cout << node->val << " ";
		if (node->right) st.push(node->right);
		________________________
	}
}
未登录也能判分,登录后才会记录
答案与解析
正确答案:A
这道题暂未补解析。