(6.2.1)--ch6-2二叉树的遍历.pdf
《(6.2.1)--ch6-2二叉树的遍历.pdf》由会员分享,可在线阅读,更多相关《(6.2.1)--ch6-2二叉树的遍历.pdf(11页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、 Data Structures and AlgorithmsBinary Tree TraversalData Structures and Algorithms Data Structures and Algorithms Trees and Binary TreesTrees and Binary TreesTraversal:Each node in the binary tree is visited along a certain search path,so that each node is visited once and only once.The meaning of v
2、isit can be very broad,for example:print the information of nodes,etc.6.3 Binary Tree Traversal DLR DRL LDR RDL LRD RLDFrom left to rightFrom left to rightData Structures and Algorithms Data Structures and Algorithms Trees and Binary TreesTrees and Binary Treesfirst-order traversal mid-order travers
3、allast-order traversalDLR:LDR:LRD:6.3 Binary Tree TraversalData Structures and Algorithms Data Structures and Algorithms Trees and Binary TreesTrees and Binary TreesABCDEFGThe result of first-order traversal:ABDGCEFIf the binary tree is empty,no action will be taken;Otherwise:(1)D:Visit the root nod
4、e;(2)L:The left subtree in first-order;(3)R:The right subtree in first-order.first-order traversal algorithmA B D G C E F6.3 Binary Tree TraversalData Structures and Algorithms Data Structures and Algorithms Trees and Binary TreesTrees and Binary Treesvoid PreOrder(BiTree root)if(root!=NULL)visit(ro
5、ot-data);PreOrder(root-lchild);PreOrder(root-rchild);printf(“%c”,root-data);first-order traversal algorithm6.3 Binary Tree TraversalData Structures and Algorithms Data Structures and Algorithms Trees and Binary TreesTrees and Binary TreesThe result of mid-order traversal:If the binary tree is empty,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 6.2 ch6 二叉 遍历
限制150内