45 45 40 22 48 80 22 40 48 80
78 ËÄ¡¢±à³ÌÌâ
1.¸ù¾Ýº¯ÊýµÄ¶¨Ò壬ÀûÓõݹéÍê³É¼ÆËã¶þ²æÊ÷´óСºÍ¸ß¶ÈµÄº¯Êý¡£ £¨1£©intBinaryTree
return 1 + Size ( t¡úleftChild )
+ Size ( t¡úrightChild );
}
£¨2£©intBinaryTree
else return 1 + Max ( Depth ( t¡úleftChild ),
Depth ( t¡úrightChild ) ); }
2.ʵÏÖÔÚÁ´±íÉϽøÐвåÈë²Ù×÷µÄ¹¦Äܺ¯Êý¡£ intList::Insert ( constintx, constinti ) {
// Insert a node with data equal to x after the i-1¡¯th ListNode*p = first; intk = 0; while ( p != NULL && k { p = p¡úlink; k++; } // Locate i-1¡¯th element if ( i<0 || p == NULL&&i!=0) { cout<< ¡°ÎÞЧµÄ²åÈëλÖÃ!\\n¡±; return 0; } ListNode *newnode= new ListNode(x, NULL); // Allocate memory for the new node if (i == 0 ) { //Insert in the front of list newnode¡úlink = first; first = newnode; } else { //else newnode¡úlink = p¡úlink; p¡úlink = newnode; } if(newnode->link==NULL) last=newnode; return 1; } 3.½èÖúÕ»£¬ÊµÏÖ¶þ²æÊ÷µÄÖÐÐò±éÀú¡£ template S.makeEmpty( ); p = root; //³õʼ»¯ do{ while ( p ) { S.push(p); p = p¡úleftChild; } if ( !S.empty( ) ) { //Õ»·Ç¿Õ p = S.top( ); S.pop( ); //ÍËÕ» cout< p = p¡úrightChild; //ÏòÓÒÁ´×ß } } while ( p || !S.empty( ) ); }

