⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hash.h

📁 著名的LZW压缩和解压的C++实现
💻 H
字号:
#ifndef HASH_H
#define HASH_H

const int D=4099;

struct part
{
	int code;
	unsigned long key;
};

struct element
{
	int prefix;
	unsigned char suffix;
};
    
struct hashnode
{
	int code;
	unsigned long key;
	hashnode* link;
};

void insert(hashnode h[D],part e)
{
	int i=e.key%D;
	if(h[i].link==NULL)
	{
		h[i].link=new hashnode;
		h[i].link->code=e.code;
		h[i].link->key=e.key;
		h[i].link->link=NULL;
	}
	else{
		for(hashnode* p=h[i].link;p->link!=NULL;p=p->link);
		p->link=new hashnode;
		p->link->code=e.code;
		p->link->key=e.key;
		p->link->link=NULL;
	}
}
	

bool search(hashnode h[D],unsigned long k, int &code)
{
	int i=k%D;
	hashnode* p=h[i].link;
	while(p!=NULL)
	{
		if(k==p->key)
		{
			code=p->code; 
			return true;
		}
		p=p->link;
	}
	return false;
}


#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -