数据结构一

Leek posted @ 2010年5月22日 07:42 in 【算法学习】 with tags Coding 数据结构 , 2080 阅读

 由于应聘网龙实习生耽搁了,先把整理好的基础部分贴出来

        据说ND招实习生就是招廉价劳动力?随便吧,反正不打算能做成怎么样可以向大牛们学点东西才是关键。在想要是实习住宿问题怎么解决?YOYO大人赞助吧?嗯..

        不扯淡了直接晒代码

        

//*************二叉堆相关操作*********************
void Sink(int p)
{
	int q = p << 1, tmp = heap[p];
	while (q <= hs)
	{
		if (q < hs && heap[q + 1] < heap[q])
			++q;
		if (heap[p] < heap[q])
			break;
		heap[q] = heap[p];
		p = q;
		q <<= 1;
	}
	heap[p] = tmp;
}

int Delete_MinI()
{
	int r = heap[1];
	heap[1] = heap[hs--];
	Sink(1);
	return r;
}

int Delete_MinII()
{
	heap[1] ^= heap[hs], heap[hs] ^= heap[1], heap[1] ^= heap[hs--];
	Sink(1);
	return heap[hs + 1];
}

void Swim(int p)
{
	int q = p >> 1, tmp = heap[p];
	while(q && tmp < heap[q])
	{
		heap[p] = heap[q];
		p = q;
		q >>= 1;
	}
	heap[p] = tmp;
}

void Insert(int p)
{
	heap[++hs] = p;
	Swim(hs);
}

void Build()
{
	for (int i = hs / 2; i ; --i)
		Sink(i);
}




/**********并查集************************/

void Make_Set(int x)
{
	rank[x] = 0;
	p[x] = x;
}

int Find_Set(int x)
{
	int px = x, tmp;
	while (px != p[px])
		px = p[px];
	while (x != px)
	{
		tmp = p[x];
		p[x] = px;
		x = tmp;
	}
	return px;
}

void Union_Set(int a,int b)
{
	a = Find_Set(a);
	b = Find_Set(b);
	if (rank[a] < rank[b])
	{
		p[a] = b;
	}
	else
	{
		p[b] = a;
		if (rank[a] == rank[b])
			++rank[a]; 
	}
}



/************哈希表********************/

 //质数1811 5087 10657 50503 100109 500119

int hash[Size * Size][2];
int first[Size][Size];
int next[Size * Size];
int entry = 1;

/*********************/

//      值太大二维存储   ps:从没用过  似乎没必要?

/*********************/
int Insert_Find_Hash()  
{
	long long a, b;
	a = 前半部分的值(可按位存储);b = 后半部分;
	c = a % Size; d = b % Size;
	e = first[c][d];
	while (e != 0)
	{
		if (hash[e][0] == a && hash[e][1] == b)
			return 0;
		e = next[e];
	}
	hash[entry][0] = a;
	hash[entry][1] = b;
	next[entry] = first[c][d];
	first[c][d] = entry;
	entry ++;
	return 1;
}

bool Insert_Find_Hash(Type x)
{
	unsigned int key;
	key = Hash(x);
	p = first[key];
	while (p)
	{
		if (hash[p] == x)
			return false;
		p = next[p];
	}
	hash[entry] = key;
	next[entry] = first[key];
	first[key] = entry;
	entry ++;
	return true;
}

//字符串用的Hash函数

unsigned int SDBMHash(char *str)
{
	unsigned int hash = 0;
	unsigned int len = 0;
	while (*str)
	{
		// hash = 65599*hash + (*str++);	
		hash = (*str++) + (hash << 6) + (hash << 16) - hash;
		++len;
	}
	hash = (len) + (hash << 6) + (hash << 16) - hash;
	return (hash & 0x7FFFFFFF);
}

/**********Good to the last code************/

        下期:平衡二叉树

Junior Certificate R 说:
2022年9月03日 22:32

Bangladesh Education Board DPE has conducted the class 8th grade of Junior School Certificate Exam and Junior Dakhil Certificate Exam on 1st to 15th November 2022 at all centers in division wise under Ministry of Primary and Mass Education (MOPME), and the class 8th grade terminal examination tests are successfully conducted for all eligible JSC/JDC ​​students for the academic year of 2022. Junior Certificate Result Dhaka Board The Bangladesh government Minister of Secondary Education is going to announce the JSC Result 2022 in student wise for division students in education board wise, and the result documents will be submitted to the Prime Minister of the country after then the result with mark sheet will be announced to public to check the individual result.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter