Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

#include<stdio.

h>
#include<stdlib.h>
struct node{
int data;
struct node *left,*right;
};
struct node *new(int new_data){
struct node* temp=(struct node*)malloc(sizeof(struct node));
temp->data=new_data;
temp->left=temp->right=NULL;
return temp;
}
void left_view(struct node*root,int level,int *highest_level){
if(root==NULL)
return;
if(*highest_level<level){
printf("%d\t",root->data);
*highest_level=level;
}
left_view(root->left,level+1,highest_level);
left_view(root->right,level+1,highest_level);
}
int main()
{
printf("left view of a binary tree is:");
struct node*root=new(1);
root->left=new(0);
root->right=new(3);
root->right->left=new(2);
root->right->right=new(4);
left(root);
return 0;
}

You might also like