-
-
Save reterVision/a81fc239e65445de59fe to your computer and use it in GitHub Desktop.
Bitsort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| #define BITSTEPWORD 32 | |
| #define SHIFT 5 | |
| #define MASK 0x1F | |
| #define NUM 10000000 | |
| int array[1 + NUM / BITSTEPWORD]; | |
| void clear() | |
| { | |
| memset(array, 0, sizeof(array)); | |
| } | |
| void set(int i) | |
| { | |
| array[i >> SHIFT] |= (1 << (i & MASK)); | |
| } | |
| void clr(int i) | |
| { | |
| array[i >> SHIFT] &= ~(1 << (i & MASK)); | |
| } | |
| int test(int i) | |
| { | |
| return array[i >> SHIFT] & (1 << (i & MASK)); | |
| } | |
| int main(int argc, char* argv[]) | |
| { | |
| int i; | |
| clear(); | |
| printf("Before set anything:\n"); | |
| for (i=0; i<200; i++) | |
| { | |
| printf("%d ", array[i]); | |
| } | |
| printf("\n\n"); | |
| for (i=0; i<100; i++) | |
| { | |
| printf("%d ", i*2); | |
| set(i*2); | |
| } | |
| printf("\n\n"); | |
| for (i=0; i<200; i++) | |
| { | |
| if (test(i)) | |
| printf("%d ", i); | |
| } | |
| getchar(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment