Fortran How to Merge and Sort Two Fortran Arrays?

  • Thread starter Thread starter hobmarcus
  • Start date Start date
  • Tags Tags
    Arrays Fortran
AI Thread Summary
To merge two arrays and sort them in ascending order, a new array should be created with sufficient size to hold all elements from both arrays. A loop can be used to transfer elements from the first array into the new array, followed by another loop to add elements from the second array, starting at the index where the first loop ended. For finding the intersection of the two arrays, a separate subroutine is required. This involves comparing each value in both arrays and storing the intersecting values in a new array, which may vary in size based on the data. It is important to provide code examples of what has been attempted for effective assistance. Additionally, posting in the appropriate forum section is recommended for homework-related queries.
hobmarcus
Messages
10
Reaction score
0
I have 2 set of data (from different files) and I allocate each set of data to array in my main program. But now I want to merge those 2 array and sort them in ascending orders in my sub program. What should I do? I know how to sort array in ascending orders, but i don't know how to merge those 2 array together... Any suggestion or help?
 
Technology news on Phys.org
hobmarcus said:
I have 2 set of data (from different files) and I allocate each set of data to array in my main program. But now I want to merge those 2 array and sort them in ascending orders in my sub program. What should I do? I know how to sort array in ascending orders, but i don't know how to merge those 2 array together... Any suggestion or help?
pseudo code:
create new array big enough to hold all the data
create a loop that puts all of the first array's elements into the new array
create a loop that puts all of the second array's elements into the new array (starting at the index left at the end of the first loop)
 
phinds said:
pseudo code:
create new array big enough to hold all the data
create a loop that puts all of the first array's elements into the new array
create a loop that puts all of the second array's elements into the new array (starting at the index left at the end of the first loop)
thanks you for answering my question. It helps a lot. However, Another subroutine is required to find the intersection of them and combined it into 1 array. Any suggestion or help please
 
Last edited:
hobmarcus said:
thanks you for answering my question. It helps a lot. However, Another subroutine is required to find the intersection of them and combined it into 1 array. Any suggestion or help please
You need to show us what you have tried. We are not going to write this code for you.

Your question should be posted in the Engineering & Comp. Sci. subsection under Homework & Coursework. I am closing this thread.
 
Last edited:
Mark44 said:
You need to show us what you have tried. We are not going to write this code for you.
First, I tried to use do loop to compare each value in both array and the write out each intersect value. But I do not know how to put them together into an array since the size of this intersect array varies if the data change.
 
hobmarcus said:
First, I tried to use do loop to compare each value in both array and the write out each intersect value. But I do not know how to put them together into an array since the size of this intersect array varies if the data change.

Again, you need to show us (in code) what you have tried, not explain to us what you have tried. As already noted, please start a new thread in the Homework & Coursework section.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
6
Views
1K
Replies
25
Views
3K
Replies
2
Views
1K
Replies
13
Views
3K
Replies
2
Views
1K
Replies
5
Views
3K
Back
Top