MESSAGE
DATE | 2015-02-22 |
FROM | Ruben
|
SUBJECT | Re: [LIU Comp Sci] Binary tree Excersize
|
From owner-learn-outgoing-at-mrbrklyn.com Sun Feb 22 21:37:15 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id DE4CF161166; Sun, 22 Feb 2015 21:37:14 -0500 (EST) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id CEE03161190; Sun, 22 Feb 2015 21:37:14 -0500 (EST) Delivered-To: learn-at-nylxs.com Received: from mail-qc0-f178.google.com (mail-qc0-f178.google.com [209.85.216.178]) by mrbrklyn.com (Postfix) with ESMTP id EA3A5161166 for ; Sun, 22 Feb 2015 21:37:12 -0500 (EST) Received: by qcvp6 with SMTP id p6so9117801qcv.12 for ; Sun, 22 Feb 2015 18:37:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=rtiaQ7K8woSOtQtUgRrV/gVjxFdZVudUy+BlSoMgDhE=; b=ChtOYkmZAnV2h14KQfHHyIzxoCMDbuvtKB3RRbeZ2ZzE6+Zef/BPTsKrTr1Mzmk4cP jdmEZDVq2uSvF/fSZFqfb09gcxlJdLPB2uBz46EDObScf03ySrt+IKU/jcSHP6104f02 EsGWKuf5fSSHKwXlS4aawDzUKe4+6R1pi2gvkp57QTu08XY5plRSu7zH1octPWzHb0K3 b4DqCX7fk36GyDnVZK0rc4DSEzwbDyXAQQGkGFH4Z/ni1WuYn8AE/r2m8Qio5UyCg3Zt ySAkfpPepQx5Ic0wy9SXuSkRPio3XJt00tIJkK9taoQbni5ubB/aoIWQ/fGslPajiTDv LYEQ== X-Gm-Message-State: ALoCoQkojIFT2JfAI8YlR3khGUa9wmm19xUf+8VmdQNJEvSSBW1P0QVq0/lPSqKv2+tf2/JhBXU0 X-Received: by 10.140.34.204 with SMTP id l70mr19341560qgl.55.1424659031657; Sun, 22 Feb 2015 18:37:11 -0800 (PST) Received: from [10.0.0.19] ([96.57.23.82]) by mx.google.com with ESMTPSA id g6sm26168349qaq.26.2015.02.22.18.37.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Feb 2015 18:37:11 -0800 (PST) Message-ID: <54EA9256.7030409-at-my.liu.edu> Date: Sun, 22 Feb 2015 21:37:10 -0500 From: Ruben User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: jose.rodriguez-at-liu.edu Subject: Re: [LIU Comp Sci] Binary tree Excersize References: <54E986CC.1080008-at-panix.com> <54EA790A.3080304-at-my.liu.edu> In-Reply-To: <54EA790A.3080304-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/22/2015 07:49 PM, Ruben wrote: > On 02/22/2015 02:35 AM, Ruben Safir wrote: >> I'm attaching a example of the Binary Tree which is based on Dr >> Rodriquez's example EXCEPT, well this one is much easier to learn about >> binary trees from and I strongly recommend looking it over and trying it >> out. >> >> Ruben >> > > This sample from the notes doesn't work... > > The reason it doesn't work is because it is called recursively and at > the end of tree the root is 0 (null) and then it returns -1. > > Ruben > > > int Height(BinTree& root) > { > if (root == 0) > return -1; > int hl = Height(root->left); > int hr = Height(root->right); > return 1 + ((hl < hr)?hr:hl); > } >
I stand correct. This seems to be fine because the recursion unravels from the bottom to the top. I was having problems with precedence
return 1 + ((hl < hr)?hr:hl);
is not equal to
return 1 + (hl < hr)?hr:hl;
|
|