5.二叉树
一、二叉树的遍历
先序、中序、后序遍历
不用递归实现二叉树的先序遍历
class Solution {
public:
vector<int> preorderTraversal(TreeNode* root) {
//不以递归实现 栈
vector<int> v;
if(!root) return v;
stack<TreeNode*> s;
s.push(root);
while(!s.empty())
{
TreeNode* cur=s.top();
v.push_back(cur->val);
s.pop();
if(cur->right) s.push(cur->right);
if(