// ¾ß°£¿ë 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) { if (x == 0) return 100*data; if (lc != NIL) return lc->getValue(x-1); if (rc != NIL) return rc->getValue(x-1); return 0; } }; 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->rc = p1; p1->lc = p2; p2->rc = p3; p3->lc = p4; p4->rc = p0; printf("%d\n",p0->getValue(8)); }