440,025 Members | 2,118 Online
Need help? Post your question and get tips & solutions from a community of 440,025 IT Pros & Developers. It's quick & easy.

# Sort it with one array and some tmp files

 P: n/a Hi, I've got the following problem. I have to sort x*y elements which are in one file. I can use only an array for x elements and floor[y/4] tmp files which can be read only forward. Thanks for every clue. JS Oct 29 '06 #1
5 Replies

 P: n/a ja******@gmail.com wrote: > I've got the following problem. I have to sort x*y elements which are in one file. I can use only an array for x elements and floor[y/4] tmp files which can be read only forward. Arrange the array to be a heap. Read in and heapify the first x elements, and dump the heap (see heapsort). Repeat until 4x have been processed. Read any remainder into the heap. Now read back the 4 tmp files element by element (they will be sorted) and mergesort them (and the extra data in the x array, which is effectively a 5th temp file) and write the elements out one by one. -- Chuck F (cbfalconer at maineline dot net) Available for consulting/temporary embedded and systems. Oct 29 '06 #2

 P: n/a ja******@gmail.com wrote: Hi, I've got the following problem. I have to sort x*y elements which are in one file. I can use only an array for x elements and floor[y/4] tmp files which can be read only forward. OK, off you go and do it then. Thanks for every clue. Clue 1, this is an algorithms problem not a C problem. We discuss C here hence the name of the group. Clue 2, read the text book that goes with the course you are doing. Try looking in the index under sort. Clue 3, the normal reason for only reading files forwards is that they are on a tape. A more appropriate group would probably be comp.programming, but read there FAQ before posting there. -- Flash Gordon. Oct 29 '06 #3