二叉树的遍历(Tree Traversals)参考极客
来源:互联网 发布:项目数据分析公司排名 编辑:程序博客网 时间:2024/06/07 04:51
树的遍历
不像线性数据结构(数组,链表,队列,栈),仅仅有一种逻辑方式遍历,树可以通过不同的方式遍历,中序遍历,先序遍历和后序遍历,宽度遍历也就是层次遍历,
// tree_tra.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <stdio.h>#include <stdlib.h>using namespace std;struct node{int data;struct node* left;struct node* right;};struct node* newNode(int data) {struct node* node = (struct node*)malloc(sizeof(struct node));node->data = data;node->left = NULL;node->right = NULL;return(node);}void printPostorder(struct node* node){if (node == NULL)return;printPostorder(node->left);printPostorder(node->right);printf("%d ", node->data);}void printInorder(struct node* node){if (node == NULL)return;printInorder(node->left);printf("%d ", node->data); printInorder(node->right);}void printPreorder(struct node* node){if (node == NULL)return;printf("%d ", node->data); printPreorder(node->left); printPreorder(node->right);} int main(){struct node *root = newNode(1);root->left = newNode(2);root->right = newNode(3);root->left->left = newNode(4);root->left->right = newNode(5); printf("\nPreorder traversal of binary tree is \n");printPreorder(root);printf("\nInorder traversal of binary tree is \n");printInorder(root); printf("\nPostorder traversal of binary tree is \n");printPostorder(root);getchar();return 0;}int _tmain(int argc, _TCHAR* argv[]){struct node *root = newNode(1);root->left = newNode(2);root->right = newNode(3);root->left->left = newNode(4);root->left->right = newNode(5);printf("\nPreorder traversal of binary tree is \n");printPreorder(root);printf("\nInorder traversal of binary tree is \n");printInorder(root);printf("\nPostorder traversal of binary tree is \n");printPostorder(root);getchar();return 0;}
0 0
- 二叉树的遍历(Tree Traversals)参考极客
- 数据结构之二叉树的遍历 HDU1710 Binary Tree Traversals
- hdu 1710 Binary Tree Traversals 二叉树的遍历
- HDU 1710(Binary Tree Traversals)二叉树的遍历
- HDOJ 1710Binary Tree Traversals 二叉树的遍历
- HDU1710 Binary Tree Traversals(DFS,二叉树的遍历)
- HDU---1710-Binary Tree Traversals (二叉树遍历)
- PAT 甲级 1020 Tree Traversals (二叉树遍历)
- HDU 1710 Binary Tree Traversals (二叉树遍历)
- hdu1710 Binary Tree Traversals(二叉树遍历)
- HDU--1710--Binary Tree Traversals(二叉树遍历)
- 杭电1710 Binary Tree Traversals(二叉树的遍历)
- hdoj 1710 Binary Tree Traversals(二叉树的建立及遍历)
- HDU 1710 Binary Tree Traversals(二叉树的后序遍历)
- HDU1710 Binary Tree Traversals【树的遍历】
- hdu 1710 binary tree traversals 二叉树遍历
- 二叉树 遍历 hdu-1710-Binary Tree Traversals
- HDU-1710 Binary Tree Traversals 二叉树遍历
- 权当是日记吧
- CentOS关闭休眠和屏保模式
- Kotlin在Android工程中的应用
- hexo博客搭建并上传github
- background 全屏解决方法
- 二叉树的遍历(Tree Traversals)参考极客
- 【博财老师】油价首次收线50之上,实时策略跟进
- 个人感想
- 基础SSH注解方式配置(ST2.1,SP3.1H4.14,JAVAEE6.0 JAVASE1.7)
- mysql —— 分表分区
- Number of 1 Bits
- 制作Swift Framework
- java处理日期时间的方法
- android layout_weight讲解