Fortran 90 & elements array comparaison

In summary, The most efficient way to find the redundant element in an array is to first sort the array in numerical order and then compare consecutive elements to find duplicates. However, if the initial array always has four elements, a brute force method can also be used by comparing only six pairs of elements.
  • #1
aihaike
55
0
Dear all,

I'm trying to figure about an efficient way to to get the redundant element in my array.
For instance, let's 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.
 
Technology news on Phys.org
  • #2
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
I'll try that, thanks!
 
  • #4
yes!
you're right, i'll go that way.
Thans again
 

1. What is Fortran 90?

Fortran 90 is a programming language used primarily for scientific and engineering applications. It is an updated version of the original Fortran language, with added features such as modules, arrays, and recursion.

2. What is an elements array in Fortran 90?

An elements array in Fortran 90 is a data structure that stores a collection of elements of the same data type in a linear fashion. It is similar to a list or vector in other programming languages.

3. How do you declare and initialize an elements array in Fortran 90?

To declare and initialize an elements array in Fortran 90, you would use the syntax array_name(size) = (/ list_of_values /), where size is the number of elements in the array and list_of_values is a comma-separated list of the initial values for each element.

4. How do you access and manipulate elements in a Fortran 90 array?

You can access and manipulate elements in a Fortran 90 array using indexing. Each element in the array is assigned an index, starting from 1. You can use this index to retrieve or modify the value of a specific element in the array.

5. Can you compare elements in two Fortran 90 arrays?

Yes, you can compare elements in two Fortran 90 arrays using a comparison operator such as .EQ. (equal), .NE. (not equal), .LT. (less than), .GT. (greater than), .LE. (less than or equal), or .GE. (greater than or equal). These operators will return a logical value of .TRUE. or .FALSE. based on the comparison result.

Similar threads

  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
20
Views
1K
  • Programming and Computer Science
7
Replies
235
Views
9K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
19
Views
5K
Back
Top