Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran 90 & elements array comparaison

  1. Nov 3, 2009 #1
    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.
     
  2. jcsd
  3. Nov 3, 2009 #2

    jtbell

    User Avatar

    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
     
  4. Nov 3, 2009 #3
    I'll try that, thanks!!
     
  5. Nov 4, 2009 #4
    yes!!
    you're right, i'll go that way.
    Thans again
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran 90 & elements array comparaison
  1. FORTRAN 90 2d arrays (Replies: 6)

Loading...