Given a binary tree, return the preorder traversal of its nodes' values.
来源:互联网 发布:w7本地连接未识别网络 编辑:程序博客网 时间:2024/05/16 14:07
vector<int> tree::preorderTree(treeNode *root)
{
vector<int> result;
stack<treeNode*> tempStack;
treeNode *dummyRootNode = root;//不知道root值是否会被改变 所以用这种方式 要测试一下
if(dummyRootNode)
tempStack.push(dummyRootNode);
while(!tempStack.empty())
{
treeNode *tempNode = tempStack.top();
tempStack.pop();
result.push_back(tempNode->value);
if(tempNode->rchild) tempStack.push(tempNode->rchild);
if(tempNode->lchild) tempStack.push(tempNode->lchild);
}
return result;
}
{
vector<int> result;
stack<treeNode*> tempStack;
treeNode *dummyRootNode = root;//不知道root值是否会被改变 所以用这种方式 要测试一下
if(dummyRootNode)
tempStack.push(dummyRootNode);
while(!tempStack.empty())
{
treeNode *tempNode = tempStack.top();
tempStack.pop();
result.push_back(tempNode->value);
if(tempNode->rchild) tempStack.push(tempNode->rchild);
if(tempNode->lchild) tempStack.push(tempNode->lchild);
}
return result;
}
0 0
- Given a binary tree, return the preorder traversal of its nodes' values.
- Given a binary tree, return the preorder traversal of its nodes' values.
- Given a binary tree, return the postorder traversal of its nodes' values.
- LeetCode Given a binary tree, return the postorder traversal of its nodes' values.
- Given preorder and inorder traversal of a tree, construct the binary tree.
- 4 4 Given a binary search tree, design an algorithm which creates a linked list of all the nodes at
- LeetCode 之 preorder traversal of binary tree
- CareerCup Given preorder traversal array of a BST, recontruct the BST.
- Construct a special tree from given preorder traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Preorder Traversal
- 解决mysql数据库无法插入中文的问题
- 安装&连接memcached
- HTML 元素
- 我用webbench测试性能的过程
- Shortest Distance(20)
- Given a binary tree, return the preorder traversal of its nodes' values.
- 基于Token的WEB后台认证机制
- C语言文件操作
- 从Handler.post(Runnable r)再一次梳理Android的消息机制(以及handler的内存泄露)
- as中包,包名相关。
- kerberos使用中遇到的问题
- shell 脚本简单txt文本数据操作
- vim 使用(1)
- listview和button冲突