完成test.h和ReadMe文件
|
@ -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
|
||||||
|

|
||||||
|
哈希表插入数字99
|
||||||
|

|
||||||
|
哈希表插入6
|
||||||
|

|
||||||
|
输出哈希表
|
||||||
|

|
||||||
|
删除元素9
|
||||||
|

|
||||||
|
查找元素99在哈希表中的位置
|
||||||
|

|
||||||
|
输出删除元素9后的哈希表
|
||||||
|

|
||||||
|
销毁哈希表并输出
|
||||||
|

|
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 7.7 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 11 KiB |
|
@ -21,15 +21,10 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "test_hash.h"
|
||||||
#include <transform.h>
|
#include <transform.h>
|
||||||
#ifdef ADD_XIZI_FETURES
|
#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;
|
prenode->next = temp->next;
|
||||||
}
|
}
|
||||||
free(temp);
|
free(temp);
|
||||||
|
temp = NULL;
|
||||||
printf("Delete the corresponding value in the hash table.\n");
|
printf("Delete the corresponding value in the hash table.\n");
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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[]);
|
||||||
|
|
||||||
|
|