Re: ordinate a sequences of number



In article <1130594803.624636.259900@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
gambato@xxxxxxxxxxxx wrote:

> hi!!
> I need to ordinate a lot of number in a growing way. I tryed to write
> this program but it doesn't work ....what is wrong?
> Can you help me?Thank you very much!
>
> C.
>
> c**************************************************
> PROGRAM ORD
> c**************************************************
> c
> integer n
> parameter (n=108000 )
> real*8 fvx(n), fvy(n), fvz(n)
> real*8 pos(n)
> c
> open (unit=11, file='fv900')
> do 10 i=1, (n-1)

It looks like you may not be reading all of the numbers. If
"n" is the right number, then you are only reading (n-1) of them.

> read (11,*) fvx(i)
> minx= fvx(i)
> do 20 j=(i+1),n
> if (fvx(j) .lt. minx) then

It looks like you are referencing elements in the array that you
have not yet read.

> min= fvx(j)
> end if
> c write(*,*) min
> 20 continue
> pos(i)=min

It look like "min" is the last element in the j loop that you found
that was less than minx (which is never changed within the loop).
Is that what you wanted, or did you want to find the smallest
element in the list?

> 10 continue
> close(unit=11)
> RETURN
> END

On a larger scale, you have two nested do loops with no chance of an
early exit, so this is an O(n^2) procedure. There are other ways to
sort elements in an array that require less effort. Look up bubble
sort, insertion sort, and heapsort and find something that fits your
problem that you can adapt to your situation.

$.02 -Ron Shepard
.



Relevant Pages

  • Re: Problem with a script
    ... a loop there becomes impractical. ... You still have them as uniquely named array indexes... ... writing the code twice will only ... reading your entire code and parsing it in their head, ...
    (comp.lang.php)
  • Re: Problem with a script
    ... Okay, so variables have unique labels, that doesn't mean they still couldn't be handled in a loop. ... You still have them as uniquely named array indexes... ... I believe that for the new guy this code would be readable, and identifying problems should really not be any more difficult with this, plus I think that it actually might save some time to write the actual code from the beginnig, even though it's not at it's final stage, instead of first writing everything spread out, and then rewriting the same code again cleaned. ... If you expect a person to spend an hour reading your entire code and parsing it in their head, you wont get any help and have to solve the problem by yourself. ...
    (comp.lang.php)
  • Re: fastest way to sort 2-D variant arrays?
    ... and then change the FSO loop section to loop through the ... array, and add the elements to the recordset using the AddNew statement. ... How would I write my variant array to the recordset? ... Here is something that I use on an ASP page to sort files by date there ...
    (microsoft.public.vb.general.discussion)
  • Re: fastest way to sort 2-D variant arrays?
    ... and then change the FSO loop section to loop through the ... array, and add the elements to the recordset using the AddNew statement. ... How would I write my variant array to the recordset? ... Here is something that I use on an ASP page to sort files by date there ...
    (microsoft.public.vb.general.discussion)
  • Newbie read image help
    ... reading one byte or one line per loop. ... array, that would be great if I could choose. ... is there any libraries out there that someone can ...
    (comp.lang.cpp)