🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java
Article #430

Re: Finding 2 biggest numbers in a row

#430
From: Bart Vandewoestyne
Date: Wed, 15 Nov 2000 00:07
74 lines
3976 bytes
Andy Zaidman wrote:
> 
> Well, it seems to me as if this algo just doesn't do the job... The problem
> is that in your example the 2 biggest values are in the upper half of your
> list of numbers... So, when you divide the list in 2, it will return the
> biggest numbers of each of the halves... and not the biggest numbers of the
> entire list...

OK, I think I have found my problem:

I should replace this...
	
<BEGIN OLD CODE>
	
	    /* 
	     * Recursive function call on left and right side
	     */
	    BigThings leftBigThings = left.searchTwoBiggest();
	    BigThings rightBigThings = right.searchTwoBiggest();
	    
	    if (leftBigThings.getBiggest()>rightBigThings.getBiggest()) {
		$values.setBiggest(leftBigThings.getBiggest());
		if (leftBigThings.getSecondBiggest()>rightBigThings.getBiggest())
		    $values.setSecondBiggest(leftBigThings.getSecondBiggest());
	    }
	    else {
		$values.setBiggest(rightBigThings.getBiggest());
		if (rightBigThings.getSecondBiggest()>leftBigThings.getBiggest())
		    $values.setSecondBiggest(rightBigThings.getSecondBiggest());
	    }
	}

<END OLD CODE>

With this...

<BEGIN NEW CODE>
	
	    /* 
	     * Recursive function call on left and right side
	     */
	    BigThings leftBigThings = left.searchTwoBiggest();
	    BigThings rightBigThings = right.searchTwoBiggest();
	    
	    if (leftBigThings.getBiggest()>rightBigThings.getBiggest()) {
		$values.setBiggest(leftBigThings.getBiggest());
		if (leftBigThings.getSecondBiggest()>rightBigThings.getBiggest())
		    $values.setSecondBiggest(leftBigThings.getSecondBiggest());
		else
		    $values.setSecondBiggest(rightBigThings.getBiggest());
	    }
	    else {
		$values.setBiggest(rightBigThings.getBiggest());
		if (rightBigThings.getSecondBiggest()>leftBigThings.getBiggest())
		    $values.setSecondBiggest(rightBigThings.getSecondBiggest());
		else 
		    $values.setSecondBiggest(leftBigThings.getBiggest());
	    } 

<END NEW CODE>

I think adding these two 'else' clauses at the end of both cases solves my
problem because this way the second biggest value is always set.
Could somebody verify this?

Greetzzz,
mc303

--
Ing. Bart Vandewoestyne			  Bart.Vandewoestyne@skynet.be
Hugo Verrieststraat 48			       GSM: +32 (0)478 397 697
B-8550 Zwevegem					 http://hello.to/MC303
----------------------------------------------------------------------
"Any fool can know, the point is to understand." - Albert Einstein
Technical Details
Message-ID: <3A11D3D9.E6452334@skynet.be>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!isdnet!newsfeeds.belnet.be!naxos.belnet.be!news.belnet.be!not-for-mail
References: <3A11B99A.2BB2E1E7@skynet.be> <8usf9t$fod$1@news1.skynet.be>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f5d71,470c011dba4db9c3
X-Google-Attributes: gidf5d71,public
X-Google-Thread: fcea4,470c011dba4db9c3
X-Google-Attributes: gidfcea4,public
X-Google-Thread: 113ae9,470c011dba4db9c3
X-Google-Attributes: gid113ae9,public
X-Google-Thread: 10a146,470c011dba4db9c3
X-Google-Attributes: gid10a146,public
X-Google-ArrivalTime: 2000-11-14 16:05:25 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!isdnet!newsfeeds.belnet.be!naxos.belnet.be!news.belnet.be!not-for-mail
From: Bart Vandewoestyne <Bart.Vandewoestyne@skynet.be>
Newsgroups: comp.lang.java,comp.lang.java.help,comp.lang.java.programmer,be.comp.programming
Subject: Re: Finding 2 biggest numbers in a row
Date: Wed, 15 Nov 2000 01:07:53 +0100
Organization: MyHome
Lines: 74
Message-ID: <3A11D3D9.E6452334@skynet.be>
References: <3A11B99A.2BB2E1E7@skynet.be> <8usf9t$fod$1@news1.skynet.be>
NNTP-Posting-Host: marvin.kulnet.kuleuven.ac.be
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: naxos.belnet.be 974246724 678 134.58.127.3 (15 Nov 2000 00:05:24 GMT)
X-Complaints-To: abuse@belnet.be
NNTP-Posting-Date: Wed, 15 Nov 2000 00:05:24 +0000 (UTC)
X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.4.0-test10 i686)
X-Accept-Language: nl-BE, nl, en, de
Cache-Post-Path: marvin!unknown@kn-10-0-53-046.kotnet.kuleuven.ac.be
X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/)