# Fortran 90 & elements array comparaison

1. Nov 3, 2009

### aihaike

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.

Eric.

2. Nov 3, 2009

### Staff: Mentor

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

3. Nov 3, 2009

### aihaike

I'll try that, thanks!!

4. Nov 4, 2009

### aihaike

yes!!
you're right, i'll go that way.
Thans again