Article View: comp.lang.java
Article #434Re: Finding 2 biggest numbers in a row
From: Yvo Volders
Date: Wed, 15 Nov 2000 00:00
Date: Wed, 15 Nov 2000 00:00
73 lines
3534 bytes
3534 bytes
Why easy if you can do it the hard way?
I should create a database with a table (CREATE TABLE...), and put al the
numbers into it by running through the elements and inserting them into a
table (INSERT INTO table (number) VALUE ..). On the insert I should write a
trigger to check if the number exists allready in the database. If so, I do
not execute the insert.
Then I should write an SQL-statement to get the biggest number (SELECT
MAX(number)..). Second I should write a select to get the second number
(SELECT MAX(number) FROM table WHERE number < biggestnumber).
When I got all this, I should go through the table (SELECT * FROM TABLE
ORDER BY number) and delete each element (DELETE FROM TABLE WHERE number =
..).
At the end I should drop the index (DROP INDEX...) and the table (DROP
TABLE..).
Then I should write a program to do it the easy way, just run through the
array.
Bart Vandewoestyne wrote in message <3A11B99A.2BB2E1E7@skynet.be>...
>I am trying to write a program that implements an algorithm to find the two
>largest integers out of a row of numbers.
>My algorithm should work this way:
>
>The number of elements in the row is a power of 2.
>
>I separate the row in two halves, and then i apply the same algorithm
recursivly
>to the two new rows. If I have the two biggest numbers of these new rows,
then
>i can find the two biggest of the total with maximum 2 comparisons.
>
>The alorithm I implemented so far is located at:
>
>http://users.skynet.be/vandewoestyne/downloads/Searcher.java
>
>and
>
>http://users.skynet.be/vandewoestyne/downloads/BigThings.java
>
>But it seems to have a mistake in it, because this was an example of an
>incorrect output I got ('links' = left, 'rechts' = right, 'Grootste waarde
=
>Biggest value', 'Tweede grootste waarde='second largest value'):
>
>Heaven:~/projecten/ontwerpen02$ java Searcher
>78 67 51 15 34 28 31 53 35 50 68 1 33 92 95 13
>
>links : 78 67 51 15 34 28 31 53
>rechts: 35 50 68 1 33 92 95 13
>links : 78 67 51 15
>rechts: 34 28 31 53
>links : 78 67
>rechts: 51 15
>links : 34 28
>rechts: 31 53
>links : 35 50 68 1
>rechts: 33 92 95 13
>links : 35 50
>rechts: 68 1
>links : 33 92
>rechts: 95 13
>Grootste waarde: 95
>
>Tweede grootste waarde: 78
>
>--
>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:
<8uu397$95e$1@news0.skynet.be>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3A11B99A.2BB2E1E7@skynet.be>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113ae9,470c011dba4db9c3 X-Google-Attributes: gid113ae9,public X-Google-Thread: f5d71,470c011dba4db9c3 X-Google-Attributes: gidf5d71,public X-Google-Thread: fcea4,470c011dba4db9c3 X-Google-Attributes: gidfcea4,public X-Google-Thread: 10a146,470c011dba4db9c3 X-Google-Attributes: gid10a146,public From: "Yvo Volders" <yvo.volders@skynet.be> Subject: Re: Finding 2 biggest numbers in a row Date: 2000/11/15 Message-ID: <8uu397$95e$1@news0.skynet.be> X-Deja-AN: 693889706 References: <3A11B99A.2BB2E1E7@skynet.be> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 X-Complaints-To: abuse@skynet.be X-Trace: news0.skynet.be 974295143 9390 195.238.22.102 (15 Nov 2000 13:32:23 GMT) Organization: Belgacom Skynet SA/NV NNTP-Posting-Date: 15 Nov 2000 13:32:23 GMT Newsgroups: comp.lang.java,comp.lang.java.help,comp.lang.java.programmer,be.comp.programming