题目( 判断题 )
对如下结构的树,执行 travel 函数,输出结果是 1 2 3 4 5 。( )

|
struct Node { int val; Node* left, * right; Node(int v) : val(v), left(nullptr), right(nullptr) {} }; void travel(Node* root) { if (!root) return; stack<Node*> s; s.push(root); while (!s.empty()) { Node* cur = s.top(); s.pop(); cout << cur->val << " "; if (cur->right) s.push(cur->right); if (cur->left) s.push(cur->left); } } |

关注我们