Академический Документы
Профессиональный Документы
Культура Документы
[C Frequently
{
int** ip;
long** lp;
float** fp;
char** cp;
...
sort(int)(ip);
sort(long)(lp);
sort(float)(fp);
sort(char)(cp);
...
}
This program contains four functions to sort four different data types: int, long,
float, and string (notice that only the function prototypes are included for brevity). A
macro named SORT was created to take the data type passed to the macro and
combine it with the sort_ string to form a valid function call that is appropriate for
the data type being sorted. Thus, the string
sort(int)(ip);
translates into
sort_int(ip);
after being run through the preprocessor.
1)
2)
3)
4)
5)
auto
static
extern
register
typedef
How can I sort things that are too large to bring into memory?
A sorting program that sorts items that are on secondary storage (disk or tape)
rather than primary storage (memory) is called an external sort. Exactly how to sort
large data depends on what is meant by too large to fit in memory. If the items to be
sorted are themselves too large to fit in memory (such as images), but there arent
many items, you can keep in memory only the sort key and a value indicating the
datas location on disk. After the key/value pairs are sorted, the data is rearranged
on disk into the correct order. If too large to fit in memory means that there are too
many items to fit into memory at one time, the data can be sorted in groups that
will fit into memory, and then the resulting files can be merged. A sort such as a
radix sort can also be used as an external sort, by making each bucket in the sort a
file. Even the quick sort can be an external sort. The data can be partitioned by
writing it to two smaller files. When the partitions are small enough to fit, they are
sorted in memory and concatenated to form the sorted file.