度为二的结点,即含有左子树和右子树
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int count = 0;
typedef struct BiTNode
{
char data;
struct BiTNode *lchild, *rchild;
}BiTNode, *BiTree;
//创建二叉树
void CreateBiTree(BiTree *bt)
{
char ch;
ch = getchar();
if (ch == '^')
*bt = NULL;
else
{
*bt = (BiTree)malloc(sizeof(BiTNode));
(*bt)->data = ch;
CreateBiTree(&((*bt)->lchild));
CreateBiTree(&((*bt)->rchild));
}
}
int InorderPrintNodes(BiTree T)
{
if (T == NULL)
return 0;
else if (T != NULL)
{
InorderPrintNodes(T->lchild);
if (T->lchild != NULL && T->rchild != NULL)
printf("%c", T->data);
InorderPrintNodes(T->rchild);
}
return 1;
}
int Preorder(BiTree T)
{
if (T == NULL)
return 0;
else if (T != NULL)
{
if (T->lchild != NULL && T->rchild != NULL)
count++;
Preorder(T->rchild);
Preorder(T->lchild);
}
return count;
}
int main()
{
BiTree T;
CreateBiTree(&T);
printf("Node are:");
InorderPrintNodes(T);
Preorder(T);
printf(" count is :%d\n", count);
system("pause");
return 0;
}