ADD file via upload
This commit is contained in:
parent
1a6ee0234b
commit
b96d1825ef
|
@ -0,0 +1,45 @@
|
|||
# 基于cortex-m3-emulator实现哈希表并测试验证
|
||||
|
||||
## 1. 简介
|
||||
利用c语言实现了哈希表(HashMap),包括添加键值对(insert_hash_table),查找键对应的值(search_hash_table),清空哈希表(free_hash_table), 迭代遍历哈希表(show_hash_table)等功能、操作。
|
||||
|
||||
利用数组(hashType)作为存储空间,利用链表(*next)解决冲突。
|
||||
|
||||
## 2. 数据结构设计说明
|
||||
键值对结构;
|
||||
|
||||
```
|
||||
typedef struct node {
|
||||
int data;//存数据,为方便运行,key、value同值
|
||||
struct node *next;//存指针,解决哈希冲突
|
||||
}hashType;
|
||||
```
|
||||
|
||||
包括以下函数功能,分别为:
|
||||
`hashType **create_hash();`:创建一个哈希表
|
||||
`int insert_hash_table(hashType **h, int data);`:添加键值对
|
||||
`int show_hash_table(struct node *head);`:遍历哈希表
|
||||
`void free_hash_table(struct node *head);`:清空哈希表
|
||||
`int search_hash_table(hashType **h, int data);`:查找哈希表
|
||||
|
||||
|
||||
## 3. 测试程序说明
|
||||
测试了哈希表(HashMap),包括添加键值对(insert_hash_table),查找键对应的值(search_hash_table),清空哈希表(free_hash_table), 迭代遍历哈希表(show_hash_table)等操作。
|
||||
并展示了利用链地址法解决哈希冲突的示例,遍历时,输出相同地址的链表中有多个节点。
|
||||
|
||||
## 4. 运行结果(需结合运行测试截图按步骤说明)
|
||||

|
||||
打开menuconfig之后,将test_hash_map开启(y),保存后退出
|
||||
|
||||

|
||||
编译XiZi-cortex-m3-emulator.elf成功
|
||||
|
||||

|
||||
启动qemu模拟Xiuos操作系统,验证TestHash注册Shell命令
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
执行TestHash命令,打印测试结果。
|
||||
|
Loading…
Reference in New Issue