Need helps on finding Max and Min

Can any one help me to find the largest and smallest value in the sequence of intergers ... and print the position of the smallest and largest number after each number is entered.? Users will input sequence of nonzero inteters. Thank You Very Much!
[271 byte] By [snguyent4javaa] at [2007-9-29 12:22:11]
# 1
Oh for heaven's sake. How would you do this in real life? Imagine if I had a stack of 3*5 cards with numbers on them, and handed them to you one at a time. How would you go about working out which was the largest and the smallest?
pmuurray@bigpond.coma at 2007-7-15 2:12:17 > top of Java-index,Other Topics,Algorithms...
# 2

> Can any one help me to find the largest and smallest

> value in the sequence of intergers ... and print the

> position of the smallest and largest number after each

> number is entered.?

>

> Users will input sequence of nonzero inteters.

>

> Thank You Very Much!

I find this request for help rediculous. It is obviously a school/college assignment and the solution is almost trivial.

If someone posts a solution, is the author going to present it as his own work?

Roger

sabre150a at 2007-7-15 2:12:17 > top of Java-index,Other Topics,Algorithms...
# 3

There's no need to over-react to homework questions. :-)

Certainly don't answer, but there's nothing wrong with

giving a hint--even for problems this trivial.

The naive way would be to store all past data and search

it each time a new number is added to the list.

The smart way is to compare the new number to the previous

min and max values.

I guess the difficulty wasn't really in coming up with the

algorithm (unless the poster is verrry dumb) but in putting

it into Java. That just comes with practice. Read a few

small programs and get to understand them.

TerryMoorea at 2007-7-15 2:12:17 > top of Java-index,Other Topics,Algorithms...
# 4

It's quite interesting. Do you have to find just first lowest number and it's position, or write all lowest nubers to array with theirs position?

Are that nubers in some kind of tree, or are they as an surface of Voronoi you know what one part of Voronoi diagram?

And by the way at what school do you study, just out of curiosity.

Just wait if they are really sadistic and wanna to prepare you at career of game developer they would give you ray to plane intersection, or ray to 4D object intersection, it would be fun.

Lord_of_the_chaosa at 2007-7-15 2:12:17 > top of Java-index,Other Topics,Algorithms...
# 5

> It's quite interesting. Do you have to find just first

> lowest number and it's position, or write all lowest

> nubers to array with theirs position?

I suspect it's just an excruciatingly simple problem.

The sort of exercise a beginner is given:

read a number; print it; read another;

print the smaller, then the greater;

read another;

print the smaller of the new number and previous minimum,

then the greater one;

read another ...

Presumably, terminate when the number is <= 0.

If you want to print the positions of the max and min,

just count the numbers as they're entered, and remember

the positions of the max and min so far.

Quite a nice suggestion for a simple enhancement to the

assignment.

TerryMoorea at 2007-7-15 2:12:17 > top of Java-index,Other Topics,Algorithms...
# 6
Anybody should be able to do this assignment. The key would be to do this assignment in the most efficient manner. (i.e. don't allow yourself to do 2 comparisons for each value in the set.) good luck,jarshe
jarshea at 2007-7-15 2:12:17 > top of Java-index,Other Topics,Algorithms...
# 7
It's hard to do without using array !!
snguyent4javaa at 2007-7-15 2:12:17 > top of Java-index,Other Topics,Algorithms...
# 8

> It's hard to do without using array !!

No, Its significantly easier to do without an array then it is with an

array.

To paraphrase what someone else said a bit earlier.

I have 20 coins of various denominations (values). I give you one coin

at a time. You can only keep one coin. How do you keep the coin with the

largest value.

If you are still having problems with this then get someone to play act

with you. (Doctors and Nurses is always fun)

matfud

matfuda at 2007-7-15 2:12:17 > top of Java-index,Other Topics,Algorithms...
# 9

> > It's quite interesting. Do you have to find just

> first

> > lowest number and it's position, or write all

> lowest

> > nubers to array with theirs position?

>

> I suspect it's just an excruciatingly simple problem.

>

> The sort of exercise a beginner is given:

> read a number; print it; read another;

> print the smaller, then the greater;

> read another;

> print the smaller of the new number and previous

> minimum,

>then the greater one;

> read another ...

>

> Presumably, terminate when the number is <= 0.

>

> If you want to print the positions of the max and min,

>

> just count the numbers as they're entered, and

> remember

> the positions of the max and min so far.

>

> Quite a nice suggestion for a simple enhancement to

> the

> assignment.

How they can be so cruel. So cripling task for young brain. They should give them task to create Voronoi diagram instead. Just wait next time they would give them task: create sorting algorithm. And in most cases it would be Bubble.

^-^

Raghar

Lord_of_the_chaosa at 2007-7-15 2:12:17 > top of Java-index,Other Topics,Algorithms...
# 10

> > It's hard to do without using array !!

>

> No, Its significantly easier to do without an array

> then it is with an

> array.

>

> To paraphrase what someone else said a bit earlier.

>

> I have 20 coins of various denominations (values). I

> give you one coin

> at a time. You can only keep one coin. How do you keep

> the coin with the

> largest value.

>

> If you are still having problems with this then get

> someone to play act

> with you. (Doctors and Nurses is always fun)

>

>

> matfud

>

>

Just don't forget to check for alergy on tape. /and have some backup for that case/ It's allway interesting who goes first. Nurse or Doctor?

Lord_of_the_chaosa at 2007-7-15 2:12:17 > top of Java-index,Other Topics,Algorithms...