MESSAGE
DATE | 2015-02-25 |
FROM | Ruben Safir
|
SUBJECT | Re: [LIU Comp Sci] Binary tree Excersize
|
From owner-learn-outgoing-at-mrbrklyn.com Wed Feb 25 08:22:13 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id B3BEA161167; Wed, 25 Feb 2015 08:22:13 -0500 (EST) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id A44C3161169; Wed, 25 Feb 2015 08:22:13 -0500 (EST) Delivered-To: learn-at-mrbrklyn.com Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) by mrbrklyn.com (Postfix) with ESMTP id 0EA0C161167 for ; Wed, 25 Feb 2015 08:22:12 -0500 (EST) Received: from [10.0.0.19] (unknown [96.57.23.82]) by mailbackend.panix.com (Postfix) with ESMTPSA id 68690130B7 for ; Wed, 25 Feb 2015 08:22:10 -0500 (EST) Message-ID: <54EDCC82.2090800-at-panix.com> Date: Wed, 25 Feb 2015 08:22:10 -0500 From: Ruben Safir User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: learn-at-mrbrklyn.com Subject: Re: [LIU Comp Sci] Binary tree Excersize References: <54EB4BE9.6020505-at-panix.com> <54EBF7E1.2070605-at-panix.com> <54EBFCC9.8070605-at-my.liu.edu> <54EDCB27.5080904-at-my.liu.edu> In-Reply-To: <54EDCB27.5080904-at-my.liu.edu> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: owner-learn-at-mrbrklyn.com Precedence: bulk Reply-To: learn-at-mrbrklyn.com
On 02/25/2015 08:16 AM, Ruben wrote: > On 02/24/2015 12:32 PM, Maneesh Kongara wrote: >> int node_count(const BinTree& node) >>> { >>> int static count = 0; >>> if(node == 0) >>> { >>> return count; >>> } >>> node_count(node->left); >>> node_count(node->right); >>> count++; >>> return count; >>> } > > this is the part that was my solution for the homework. > > It is the extra credit part that is worthy of discussion. >
BTW - I don't like the use of statics in these functions. What if you have to count twice? It is better to declare the variable outside the function and then either pass it in by reference or use make an external reference or pointer to the external counter. This way you can zero it if you need to.
Ruben
|
|