Given a Binary Tree, print left view of it. Left view of a Binary Tree is set of nodes visible when tree is visited from left side. Left view of following tree is 12, 10, 25.
12 / \ 10 30 / \ 25 40
The left view contains all nodes that are first nodes in their levels. A simple solution is to do level order traversal and print the first node in every level.
The problem can also be solved using simple recursive traversal. We can keep track of level of a node by passing a parameter to all recursive calls. The idea is to keep track of maximum level also. Whenever we see a node whose level is more than maximum level so far, we print the node because this is the first node in its level (Note that we traverse the left subtree before right subtree). Following is C implementation of this approach.
相关推荐
先序二叉树(树状打印) 将二叉树以先序输出,并且图状打印
BinaryTree-BinaryTree
This is a binary tree search implementation.
binary tree 的C语言实现算法,需要在linux环境下编译
BinaryTree-源码.rar
懂的人自然懂:) 用C#写的binarytree
Construct Binary Tree from Preorder and Inorder Traversal 根据先序,中序建立二叉树
2.binaryTree树 标准的二叉树。 实现了各种算法,增删查改等等
BinaryTreeSort的java实现,简单的二叉树排序
心希盼 C++ STL 二叉树 详细请看“心希盼 binaryTree.doc”
二叉树的实现,各种方法,构造函数,析构函数,前序遍历,中序遍历,后续遍历,层次序遍历
constructing a binary tree
A Complete Binary Tree (CBT) is a tree that is completely filled, with the possible exception of the bottom level, which is filled from left to right. Now given a sequence of distinct non-negative ...
C++实现 操作函数包括先序、中序、后序遍历,求深度,深度、广度遍历 构建二叉树
BinaryTree: 用于学习二叉树的Python库
An inorder binary tree traversal ... Then a unique binary tree (shown in Figure 1) can be generated from this sequence of operations. Your task is to give the postorder traversal sequence of this tree.
二叉树的实现代码,我的博客“Java——二叉树的基础实现”的代码。 https://blog.csdn.net/J_fla/article/details/103236673
有序二叉树创建 有序二叉树查找 二叉树遍历 有序二叉树删除 类模版实现的有序二叉树
二叉树前序遍历,leetcode
数据结构教学课件:chapter5 A Binary Tree Node ADT.ppt