#include<stdio.h>

#include<stdlib.h>


#define MAX_QUEUE_SIZE 100


typedef struct TreeNode{

int data;

struct TreeNode *left, *right;

}TreeNode;


TreeNode n1={1 , NULL, NULL};

TreeNode n2={4 , &n1, NULL};

TreeNode n3={16 , NULL, NULL};

TreeNode n4={25 , NULL, NULL};

TreeNode n5={20 , &n3, &n4};

TreeNode n6={15 , &n2, &n5};

TreeNode *root=&n6;


int get_node_count(TreeNode *root){

int count =0;

if( root != NULL)

count = 1 + get_node_count(root->left) + get_node_count(root->right);

return count;

}//노드개수



int get_leaf_count(TreeNode *root){   

int count = 0;

if( root != NULL){

if(root->left ==NULL && root->right ==NULL)

return 1;

else

return count = get_leaf_count(root->left)+get_leaf_count(root->right);

}

return count;

}//단말노드개수




int main(void){

printf("%d\n",get_node_count(root));

printf("%d\n",get_leaf_count(root));


return 0;

}

'개발 > Algorithm' 카테고리의 다른 글

실습과제 #1  (0) 2014.09.19
원을 만드는 것  (0) 2014.09.12
레벨 순회 프로그램  (0) 2014.06.02
정적->동적 트리 미완성  (0) 2014.05.28
배열 트리  (0) 2014.05.26
블로그 이미지

잉비니

,