In fact, we use each element to represent a 32-bit binary string so that the element retains information about the presence of 32 adjacent numbers, and the array range drops to 10000000/32. For example, for number 89256, due to 89256 mod 32=2789 ... 8, so we should place the 8th bit of the 32-bit string in a[2789] (from the low number) to 1.
#define WORD
#define SHIFT 5////Move 5 digits, the left is the equivalent of multiplying by 32, and the right is equivalent to dividing
by 32 #define MASK 0x1F//16 into the
#define N 10000000
int bitmap[1 + N/word];
* * Position Function--with "|" operator, I&mask is equivalent to mod operation
* M mod n operation, when n = 2 of the x power, m mod n = m& (n-1)
/
void set (int i) {
bitmap[i ;> SHIFT] |= (1 << (I & MASK));
}
/* Purge bit operation, with &~ operator/
void Clear (int i) {
bitmap[i >> SHIFT] &= ~ (1 << (I & MASK));
} /
* Test bit operation with & operator/
int test (int i) {return
bitmap[i >> SHIFT] & (1 << (I & MASK)) c19/>}
Implementation sort (cannot be repeated):
int main (void) {FILE *in = fopen ("In.txt", "R");
FILE *out = fopen ("OUT.txt", "w");
if (in = = NULL | | out = = NULL) {exit (-1);
int i = 0;
int m;
for (i = 0; i < N; i++) {Clear (i);
while (!feof (in)) {fscanf (in, "%d", &m);
printf ("%d/n", m);
Set (m);
printf ("Abnother");
for (i = 0; i < N; i++) {if (Test (i)) {printf ("%d/n", I);
fprintf (out, "%d/n", I);
} fclose (in);
Fclose (out);
return exit_success; }