Re: ordinate a sequences of number
- From: Ron Shepard <ron-shepard@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 29 Oct 2005 10:13:12 -0500
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
.
- Follow-Ups:
- Re: ordinate a sequences of number
- From: gambato
- Re: ordinate a sequences of number
- References:
- ordinate a sequences of number
- From: gambato
- ordinate a sequences of number
- Prev by Date: ordinate a sequences of number
- Next by Date: Re: ordinate a sequences of number
- Previous by thread: ordinate a sequences of number
- Next by thread: Re: ordinate a sequences of number
- Index(es):
Relevant Pages
|