1

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

SheetJS
  • 22,470
  • 12
  • 65
  • 75
Alex
  • 31
  • 1
  • 7
  • 1
    What is your question exactly ? Just saying "I need some hints" is way too vague. – Paul R Jan 15 '13 at 22:27
  • I don't know how to distribute those monotonous sequences in f1 and f2. My file contains numbers of type unsigned long – Alex Jan 15 '13 at 22:33
  • 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. – Paul R Jan 15 '13 at 22:34
  • 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 – Alex Jan 15 '13 at 22:43
  • 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 – Paul R Jan 15 '13 at 22:58
  • Start by reading each file as an array of `unsigned long`. Then try to figure out how to merge and sort. – m0skit0 Jan 15 '13 at 22:58

1 Answers1

1
  1. Read files f1 and f2 into arrays a1 and a2.
  2. Sort arrays a1 and a2.
  3. 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.
  4. Print output array to file.
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345