完成test.h和ReadMe文件

This commit is contained in:
mashenglong 2023-06-30 03:17:55 -07:00
parent c46a1bd412
commit aa9d27ae68
11 changed files with 91 additions and 6 deletions

View File

@ -0,0 +1,52 @@
# ##**基于cortex-m3-emulator实现哈希表并测试验证**##
## 1. 简介
基于矽璓模拟器cortex-m3-emulator实现哈希表,并支持链地址法解决哈希冲突,编写测试程序进行验证
## 2. 数据结构设计说明
```
//定义哈希表的节点
typedef struct HashNode{
int val;
struct HashNode *next;
}hash_list;
```
```
//定义哈希表的大小
#define HashTableSize 10
// 创建哈希表
hash_list* hash_table[HashTableSize];
```
```
//函数定义说明
void InitHash();//创建哈希表
int ComputeHash(int value);//哈希函数,返回在哈希表中的下标
void InsertHash(int key, int value);//根据key寻找元素在哈希表中的位置并且使用链地址法解决哈希冲突
void DeleteHash(int key);//删除哈希表中某个元素
int SearchHash(int key);//根据value寻找在哈希表中的位置返回值为在取模后的第几个
void PrintHash();//打印哈希表
void TestHash(int argc, char *argv[]);//测试程序,函数参数为对哈希表的操作以及数字
```
## 3. 测试程序说明
测试程序为TestHash设置有有参函数参数设置为字符串数组可输入包括 insert、delete、search、print和clean命令并可输入哈希表操作数字根据输入参数完成哈希表的插入、删除、查找、输出和销毁操作通过atoi()函数将字符数字转为int类型
## 4. 运行结果(##需结合运行测试截图按步骤说明##
哈希表插入数字9
![哈希表插入数字9](image.png)
哈希表插入数字99
![哈希表插入数字99](image-1.png)
哈希表插入6
![哈希表插入6](image-2.png)
输出哈希表
![输出哈希表](image-3.png)
删除元素9
![删除元素9](image-4.png)
查找元素99在哈希表中的位置
![查找元素99在哈希表中的位置](image-6.png)
输出删除元素9后的哈希表
![输出删除元素9后的哈希表](image-5.png)
销毁哈希表并输出
![销毁哈希表](image-7.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -21,15 +21,10 @@
#include <stdio.h>
#include <string.h>
#include <string.h>
#include "test_hash.h"
#include <transform.h>
#ifdef ADD_XIZI_FETURES
#define HashTableSize 10
// 初始化哈希表一共有10个元素其值为0表示为空
typedef struct HashNode{
int val;
struct HashNode *next;
}hash_list;
// 创建哈希表
@ -129,6 +124,7 @@ void DeleteHash(int value)
prenode->next = temp->next;
}
free(temp);
temp = NULL;
printf("Delete the corresponding value in the hash table.\n");
return ;
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: test_hash.c
* @brief: a application of HashTable function
* @version: 1.1
* @author: NWPUWSN
* @date: 2023/6/22
*/
// 初始化哈希表一共有10个元素其值为0表示为空
#define HashTableSize 10
typedef struct HashNode{
int val;
struct HashNode *next;
}hash_list;
void InitHash();
int ComputeHash(int value);
void InsertHash(int key, int value);
void DeleteHash(int key);
int SearchHash(int key);
void PrintHash();
void TestHash(int argc, char *argv[]);