0% found this document useful (0 votes)
18 views2 pages

TRAVERSal S14

The document contains a C program that implements a binary tree with functions for inorder, preorder, and postorder traversals. It defines a structure for tree nodes and includes functions to create nodes and insert them into the tree. The main function demonstrates the creation of a binary tree and prints the results of the different traversal methods.

Uploaded by

anishwarushe0725
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

TRAVERSal S14

The document contains a C program that implements a binary tree with functions for inorder, preorder, and postorder traversals. It defines a structure for tree nodes and includes functions to create nodes and insert them into the tree. The main function demonstrates the creation of a binary tree and prints the results of the different traversal methods.

Uploaded by

anishwarushe0725
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

ASSIGNMEMENT

NO.9

NAME - PRATHAMESH WALVEKAR

ROLL NO-14

PRN-2122000117

#include <stdio.h>
#include<stdlib.h>
struct node{
int item;
struct node*left,*right;

};
void inorder(struct node*root){
if(root==NULL) return;
inorder(root->left);
printf("%d",root->item);
inorder(root->right);
}
void preorder(struct node*root){
if(root==NULL) return;
printf("%d",root->item);
preorder(root->left);
preorder(root->right);

}
void postorder(struct node*root){
if(root==NULL) return;
postorder(root->left);
postorder(root->right);
printf("%d",root->item);
}
struct node*createnode(value){
struct node*newnode=malloc(sizeof(struct node));
newnode->left=NULL;
newnode->right=NULL;
newnode->item=value;

}
struct node*insertleft(struct node*root,int value){
root->left=createnode(value);
return root->left;
}
struct node*insertright(struct node*root,int value){
root->right=createnode(value);
return root->right;

}
int main(){
struct node* root = createnode(1);
insertleft(root, 12);
insertright(root, 9);

insertleft(root->left, 5);
insertright(root->left, 6);
printf("Inorder traversal \n");
inorder(root);

printf("\nPreorder traversal \n");


preorder(root);

printf("\nPostorder traversal \n");


postorder(root);

OUTPUT-

Inorder traversal
512619
Preorder traversal
112569
Postorder traversal
561291

You might also like