PDA

View Full Version : Fortran 90 & elements array comparaison


aihaike
Nov3-09, 01:25 PM
Dear all,

I'm trying to figure about an efficient way to to get the redundant element in my array.
For instance, lets take the array [0,2,3,0].
I'd like to get out [2,0,3] (or 3,0,2 it doesn't matter).
So it find out which element is duplicated, an puts its value in between the 2 other elements.
The size of my initial array is always 4 and the final one always 3.
The duplicated element can have any index.
It's look very simple, and it certainly is, but I can not figure.
Some help would be very helpful.
Thanks in advance,

Eric.

jtbell
Nov3-09, 04:57 PM
First sort the array in numerical order, using any of a number of sorting methods. Then it's easy to find duplicates because they're in consecutive positions.

(added) Ah, now I see that you always start with four elements. In that case you could even do it by brute force because you need to compare only six pairs of elements:

#1 with #2
#1 with #3
#1 with #4
#2 with #3
#2 with #4
#3 with #4

aihaike
Nov3-09, 04:59 PM
I'll try that, thanks!!

aihaike
Nov4-09, 06:02 AM
yes!!
you're right, i'll go that way.
Thans again