哈希表中的一些问题
来源:互联网 发布:excel数据保护 编辑:程序博客网 时间:2024/05/17 06:01
‘`#include
include
include
include
include
include
include
using namespace std;//关于hw4中命令怎么写得问题
struct ListNode;
typedef unsigned int uint;
int size1 = 0;
uint string_to_int(string s)
{
uint k;
k= atoi(s.c_str());
return k;
}
struct elemtype
{
string str;
int type;
int fre;
};
struct ListNode
{
elemtype element;
struct ListNode *Next;
};
class HashTable
{
public:
int Tablesize;
ListNode **Thelists;
public:
HashTable Init(int Tablesize);
HashTable insert(elemtype Key, HashTable H1);
int Hash(elemtype Key, int Tablesize);
ListNode *Find(elemtype Key, HashTable H1);
HashTable Delete(elemtype Key, HashTable H1);
HashTable Rebuild(HashTable H1, int size, elemtype Harry[], int le, int fac);
HashTable Build(HashTable H1, int size, elemtype Harry[], int le, int fac);
};
HashTable HashTable::Init(int Tablesize)
{
HashTable H1;
int i;
H1.Tablesize = Tablesize;
// H1.Thelists = (ListNode**)malloc(sizeof(ListNode) * H1.Tablesize);
H1.Thelists = new ListNode*[H1.Tablesize];
if (H1.Thelists == NULL)
{
exit(0);
}
for (i = 0; i < H1.Tablesize; i++)
{
//H1.Thelists[i] = (ListNode )malloc(sizeof(struct ListNode));//从这一行开始读取字符串字符时出错,为啥好好的ListNode结构到这里成了ListNode
//但是同在结构体里的int类型能够读取//是不是malloc本身的问题
H1.Thelists[i] = new ListNode;
if (H1.Thelists[i] == NULL)
{
exit(0);
}
else
{
H1.Thelists[i]->Next = NULL;//位置冲突怎么避免
}
}return H1;
}
int HashTable::Hash(elemtype Key, int Tablesize)
{
uint hashval = 0;
uint hash_value = 0;
if (Key.type == 1)
{
hashval = string_to_int(Key.str);
hash_value = hashval % Tablesize;
}
if (Key.type == 0)
{
int lens = Key.str.length();
for (int i = 0; i
- 哈希表中的一些问题
- Torque中的一些问题
- Torque中的一些问题
- 事务中的一些问题
- 项目中的一些问题
- JBoss中的一些问题
- arm中的一些问题
- struts2中的一些问题
- web中的一些问题
- VS2008中的一些问题
- 项目中的一些问题
- JDBC中的一些问题!
- android中的一些问题
- C++中的一些问题
- CI中的一些问题
- PHP中的一些问题
- 局域网中的一些问题
- ubuntu中的一些问题
- hdu 5600 BestCoder Round #67 (div.2)
- 抛弃编程语言的偏见——对话百度架构师
- NSPredicate(正则表达式核心类)
- [译]How to Design Games Levels with "Super Mario World Method"
- android 制作9.png图片
- 哈希表中的一些问题
- Linux内核源代码解析之——小弟我与神童聊Linux内核
- oracle数据库操作方式
- git学习
- 由于SSH配置文件的不匹配,导致的Permission denied (publickey)及其解决方法
- 价值交换的5个层次
- 文章标题
- 初学python1
- NumberUtils、ArrayUtils和RandomUtils工具类用法