// ¾ß°£¿ë 4¹ø ¹®Á¦ #include #define NIL (0) class TreeNode { public: int data; TreeNode *lc; TreeNode *rc; TreeNode(int d) { data = d; lc = NIL; rc = NIL; } int getValue() { int x = 0; int y = 0; if (lc != NIL) x = 1 + lc->getValue(); if (rc != NIL) y = 1 + rc->getValue(); return x+y; } }; void main() { int data[5] = { 0, 1, 2, 3, 4 }; TreeNode *p0 = new TreeNode(data[0]); TreeNode *p1 = new TreeNode(data[1]); TreeNode *p2 = new TreeNode(data[2]); TreeNode *p3 = new TreeNode(data[3]); TreeNode *p4 = new TreeNode(data[4]); p0->lc = p1; p0->rc = p2; p2->lc = p3; p2->rc = p4; printf("%d\n",p0->getValue()); }