#include<stdio.h>
#include<stdlib.h>
//#include<conio.h>
struct treenode
{
int ele;
struct treenode *l_child, *r_child;
};
struct treenode *insert_node(struct treenode *t,int a);
void TraverseInorder(struct treenode *t);
void TraversePreorder(struct treenode *t);
void TraversePostorder(struct treenode *t);
/*main function*/
int main()
{
struct treenode *root_node = NULL;
int num,value;
int choice;
//clrscr();
printf("----------------------------------------------------\n");
printf("\t\t\tMENU\n");
printf("-----------------------------------------------------\n");
printf("[1] Create a Binary Tree and Use Inorder Traversal\n");
printf("[2] Create a Binary Tree and Use Preorder Traversal\n");
printf("[3] Create a Binary Tree and Use Postorder Traversal\n");
printf("-----------------------------------------------------\n");
printf("Enter your choice:");
scanf("%d",&choice);
if(choice>0 & choice<=3)
{
printf("\nEnter the number of nodes:");
scanf("%d",&num);
while(num-- > 0)
{
printf("\n\nEnter the data value:");
scanf("%d",&value);
root_node = insert_node(root_node,value);
}
switch(choice)
{
case 1:
printf("\n\nBinary tree using Inorder Traversal : ");
TraverseInorder(root_node);
getch();
break;
case 2:
printf("\n\nBinary tree using Preorder Traversal : ");
TraversePreorder(root_node);
getch();
break;
case 3:
printf("\n\nBinary tree using Postorder Traversal : ");
TraversePostorder(root_node);
getch();
break;
default:
printf("Invalid Choice");
break;
}
}
}
/*end main*/
/* Function to create a Binary Tree of integers data */
struct treenode *insert_node(struct treenode *t,int a)
{
struct treenode *temp_node1,*temp_node2;
if(t NULL)
{
printf("Value cannot be allocated.\n");
exit(0);
}
temp_node2->ele = a;
temp_node2->l_child=temp_node2->r_child = NULL;
}
}
return(t);
}
/* Function for Traversing the binary tree in inorder. */
void TraverseInorder(struct treenode *t)
{
if(t != NULL)
{
TraverseInorder(t->l_child);
printf("%d\t",t->ele);
in_order(t->r_child);
}
}
/* Function for Traversing the binary tree in preorder. */
void TraversePreorder(struct treenode *t)
{
if(t != NULL)
{
printf("%d\t",t->ele);
TraversePreorder(t->l_child);
TraversePreorder(t->r_child);
}
}
/* Function for Traversing the binary tree in postorder. */
void TraversePostorder(struct treenode *t)
{
if(t != NULL)
{
TraversePostorder(t->l_child);
TraversePostorder(t->r_child);
printf("%d\t",t->ele);
}
}
A binary tree is simply a way to create a flow chart for decisions. An example of a real life binary tree is anything that requires a series of yes or no answers.
any body can help on this ?
tell me , how we create a username & password for many users in c language.
A binary tree is type of tree with finite number of elements and is divided into three main parts. the first part is called root of the tree and itself binary tree which exists towards left and right of the tree. There are a no. of binary trees and these are as follows : 1) rooted binary tree 2) full binary tree 3) perfect binary tree 4) complete binary tree 5) balanced binary tree 6) rooted complete binary tree
Is another binary tree.
Yes.
A full binary tree is a type of binary tree where each node has either 0 or 2 children. A complete binary tree is a binary tree where all levels are fully filled except possibly for the last level, which is filled from left to right. So, a full binary tree can be a complete binary tree, but not all complete binary trees are full binary trees.
will remain same
no they are not same
What are the applications of Binary Tree.
a binary tree with only left sub trees is called as left skewed binary tree
Incomplete Binary Tree is a type of binary tree where we do not apply the following formula: 1. The Maximum number of nodes in a level is 2