Saturday, 15 March 2014

c++ - Sorting a sequence of numbers from within a file without saving them into an array -


Is it possible to sort a sequence of numbers without saving in an array, and, if so, how do

I assume that this is a text file instead of a binary file. One of the problems with text files (for storage numbers) is that the numbers are potentially different sizes.

Yes, assuming that all numbers take up one place (which means, if it is a text file, then you have pad all the numbers at the same length). [Okay, technically, this is probably going to be done, but for this it will need to read all the intermediate numbers between the two points, and then they will have to be rewritten, and then you can fully read and store the entire file It would be better to get it back out again]

In the form of "how" - the method is similar to any other sorting algorithm, read two values, if they are out of order, then swap them. There are probably algorithms that "read / decrease the number of swaps", I have not noticed in it.

I hope, if you worry that "I do not have enough memory for the entire file", then you can read some large amounts and sort between them / between them. Repeat it again, perhaps, algorithms are being sorted in particular, but I have uncertainty that - when I need to sort the text files, then use Unix sort

The first answer on this page is a link to "compare"

No comments:

Post a Comment