[CPP]View Plaincopy
- #include <stdio.h>
- #include <stdlib.h>
- #define INT_BY_BIT 32
- #define MASK 0x1F
- #define SHIFT 5
- #define N 1000000
- int a[n/int_by_bit+1];
- void Set_bit (int x) {A[x>>shift] |= 1 << (x & MASK);}
- void Clear_bit (int x) {A[x>>shift] &= ~ (1<< (x & MASK));}
- int test_bit (int x) {return a[x>>shift]& (1<< (x & MASK));}
- int main ()
- {
- int a[n/int_by_bit+1];
- int i;
- For (i=0;i<n;i++)
- {
- Clear_bit (i);
- }
- While (scanf ("%d", &i)! = EOF)
- {
- Set_bit (i);
- }
- For (i=0;i<n;i++)
- {
- if (test_bit (i))
- {
- printf ("%d", I);
- printf ("");
- }
- }
- return 0;
- }
1, if a number can occur up to 8 times, how should I sort the bitmap?
A: You can use a byte to represent a number
2, if there are 10 million numbers, but the memory is only 1 m, and 10000000 need 1.25M, used how to sort?
A: Can be completed by two sequencing, first Order 1 to 5000000, second order 5000000 to 10000000
[Data structure] using bitmap sorting