[Data structure] using bitmap sorting

Source: Internet
Author: User
#include <stdio.h>
#include <stdlib.h>

#define INT_BY_BIT
#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 to 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.