**Binary tree **is acylic graph with n nodes and v vertices,where
n nodes are connected by v edges with the following properties-

-First node is called as root node.

-All other nodes are divided into different subsets where each subset is called as binary tree.

-Each node contains either zero,one or two subtrees.

Hence,a binary tree is a tree in which each node is having at the most two subtrees.

This program shows how to **count leaf nodes and non-leaf nodes**
of binary tree.First the binary tree is created.While counting the
nodes,both the leaf nodes and non-leaf nodes are considered.Each
and every node is parsed till it reaches NULL.The counter is incremented
as per the node.

#include < stdio.h > #include < conio.h > #include < alloc.h > #define new_node (struct node*)malloc(sizeof (struct node)) struct node { int data; struct node *lchild; struct node *rchild; }; struct node *create_bin_rec(); void print_bin_pre_rec(struct node *t); void cnt_nodes(struct node *t, int *l, int *nl); void main() { struct node *root; int leaf,nonleaf; clrscr(); printf("\nCreate a binary tree \n"); root = create_bin_rec(); printf("\n Binary tree is "); print_bin_pre_rec(root); leaf = nonleaf = 0; cnt_nodes(root,&leaf,&nonleaf); printf("\n Total leaf nodes are : %d ",leaf); printf("\n Total non leaf nodes are : %d ",nonleaf); } // main struct node *create_bin_rec() { int data; struct node *t; printf("\nData ( -1 to exit ) : "); scanf("%d",&data); if( data == -1) return(NULL); else { t = new_node; t->data = data; t->lchild =create_bin_rec(); t->rchild =create_bin_rec(); return(t); } //else } // create void print_bin_pre_rec(struct node *t) { if( t != NULL) { printf("%4d",t->data); print_bin_pre_rec(t->lchild); print_bin_pre_rec(t->rchild); } // if } // print bin pre rec void cnt_nodes(struct node *t, int *l, int *nl) { if( t != NULL) { if( t->lchild == NULL && t->rchild == NULL) (*l)++; else (*nl)++; cnt_nodes(t->lchild,l,nl); cnt_nodes(t->rchild,l,nl); } // if } // cnt nodes