InOrder transversal in binary tree
Fri Jun 17 2022 10:52:15 GMT+0000 (Coordinated Universal Time)
Saved by
@KanishqJ8
#include <stdio.h>
#include <malloc.h>
struct node{
int data;
struct node*left;
struct node *right;
};
struct node* createNode(int data){
struct node *n;
n=(struct node *)malloc(sizeof(struct node));
n->data=data;
n->left=NULL;
n->right=NULL;
return n;
}
void InOrder(struct node*root){
if(root!=NULL){
InOrder(root->left);
printf("%d ",root->data);
InOrder(root->right);
}
}
int main() {
struct node*p=createNode(4);
struct node*p1=createNode(1);
struct node*p2=createNode(6);
struct node*p3=createNode(5);
struct node*p4=createNode(2);
p->left=p1;
p->right=p2;
p1->left=p3;
p1->right=p4;
InOrder(p);
return 0;
}
content_copyCOPY
Comments