以下是二叉树类型的,如果还要,我可以帮你改。
#include "stdio.h"
#include "conio.h"
typedef struct node
{
struct node *l,*r;
}Node;
int getTreeNum(Node * k)
{
if(k!=0)
return 1+getTreeNum(k->l)+getTreeNum(k->r);
else
return 0;
}
int main()
{
Node *root=(Node*)malloc(sizeof(Node));
root->l=(Node*)malloc(sizeof(Node));
root->r=(Node*)malloc(sizeof(Node));
root->r->l=0;
root->r->r=0;
root->l->r=0;
root->l->l=(Node*)malloc(sizeof(Node));
root->l->l->l=0;
root->l->l->r=0;
printf("%d",getTreeNum(root));
getch();
}