Title: Sort a binary file
Tags: c;sorting
Question: I need to sort a binary file using external sort. I use 2 aux files f1 and f2 where i put monotonous sequence data. After that i merge this files. I do this until there is one monotonous sequence.
EX 1 2 3 4 5 0 1
f1: 1 2 3 4 5
f2: 0 1
final file 0 1 1 2 3 4 5
I need some hints
Comment: Start by reading each file as an array of `unsigned long`. Then try to figure out how to merge and sort.

Comment: What is your question exactly ? Just saying "I need some hints" is way too vague.

Comment: OK - and what do you need to know ? What sorting algorithm to use ? How to code it in whatever programming language you are using ? Try and improve your question and you may get some helpful answers.

Comment: OK - I've added a `c` tag for you now - try and remember to tag with programming language in future questions. You might also want to read up on similar questions on SO that have already been answered, e.g. http://stackoverflow.com/questions/5958169/how-to-merge-two-sorted-arrays-into-a-sorted-array

Comment: I don't know how to distribute those monotonous sequences in f1 and f2. My file contains numbers of type unsigned long

Comment: Ok. I need to do this in C. I need an algorithm. For example if i have file1: 1 2 3 0 1 and file2:0 2 I need to know how to merge this files to obtain a sorted file

Here is the accepted answer: Read files f1 and f2 into arrays a1 and a2.
Sort arrays a1 and a2.
Walk through both arrays element by element, adding the lowest element from each array to output array. As you add an element, increment your "walk-index" for that array.
Print output array to file.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 6, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:01/15/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c><sorting>', 'Title': 'Sort a binary file', 'ViewCount': 1182, 'id': 14348050, 'user_AboutMe': None, 'user_AccountId': 2158715.0, 'user_DisplayName': 'Alex', 'user_Reputation': 31.0, 'user_Views': 23.0, 'user_id': 1981842.0}}