【php精品源码栏目提醒】:网学会员为广大网友收集整理了,【精品】课程设计报告-哈希表 - 网络与通信,希望对大家有所帮助!
数据结构课程设计 (哈希表的设计) 院 系 专 业 班 级 学 生 姓 名 学 号课程设计日期:2011 年 6 月 26 日至 2011 年 7 月 7 日 目录一、问题描述......................................................3二、需求分析 1、基本要求……………………………………………3 2、测试数据.......................................................3三、概要设计......................................................3四、详细设计......................................................4五、测试分析.....................................................11六、课程设计总结.............................................13七、附录(源代码).........................................14一、问题描述 针对自己班级体中的“人名”设计一个哈希表,使得平均查找长度不超过 R,完成相应的建表和查表程序。
二、需求分析基本要求: 假设人名为中国姓名的汉语拼音模式。
待填入哈希表的人名共有 30 个,取平均查找长度的上限为 2。
哈希函数用除留余数法构造,用链表法处理冲突。
测试数据: 输入 30 个人的姓名拼音,即 30 个字符串,然后用除留余数法构建哈希表并用链表法处理冲突,最后将结果输出,程序自动计算查找长度的总数和平均查找长度,然后用户可以根据需求进行查找操作。
三、概要设计 开始 i0key i N inextNULL keyem-key_codep N htkey.key NULLKEY N Y htkey.key htkey.key key key Y htkey.next em p htkey.next N p-next NULL p-next em Y p p-next 结束四、详细设计头文件includeincludeincludeincludedefine P 30 /除数余留法中的除数/define NULLKEY 0define MAX 30 /人名个数/define hashlen 30 /哈希表长度/int sum0k0typedef struct Node /哈希表结构体/ char key_code10 /哈希表地址/ struct Node nextNodetypedef struct hashtable /创建哈希表/ int key struct Node nextHashTableMAXint Hashint key int mode key P /除留余数法得到的余数/ return modevoid Hash_InitHashTable ht /哈希表初始化/ int i fori 0 i MAX i hti.key NULLKEY hti.next NULL int CharToIntchar str return str0str1str2int Hash_InsertHashTable ht Node node /为哈希表分配地址/ int key HashCharToIntnode-key_code Node p pNodemallocsizeofNode ifhtkey.key NULLKEY htkey.key key htkey.next node k f else i htkey.key key p htkey.next k whilep-next N ULL p p-next k p-next node k return 1Node Hash_SearchHashTable ht int key /查找函数/ int p0 Hashkey ifhtp0.key NULLKEY sumreturn N ULL f else i htp0.key p0 Node p htp0.next whilep NULL ifCharToIntp-key_code key sum return p p p-next sum return NULLint Hash_CreateHashTable ht /哈希表长度/ int i Node node Hash_Initht printf请输入个姓名/ fori0ikey_code node-next NULL Hash_Insertht node printfnCreate Successfullyn return 1int hash_outputHashTable h /哈希表的输出部分/ Node a int ijcount20 aNodemallocsizeofNode j0 fori0inext NULL p p-next k p-next em k return 1Employee Hash_SearchHashTable ht int key int p0 Hashkey ifhtp0.key NULLKEY sumreturn NULL else ifhtp0.key p0 Employee p htp0.next whilep NULL ifp-key_code key sum return p p p-next sum return NULLint Hash_CreateHashTable ht int i Employee em Hash_Initht printf请输入数据: fori0ikey_code em-next NULL Hash_Insertht em printfnCreate Successfullyn return 1void ConFun printf请按任意键继续.... getchint hash_outputHashTable h Employee a int ijcount20 aEmployeemallocsizeofEmployee j0 fori0i
上一篇:
PHP中防止SQL注入
下一篇:
什么是“双核心期刊”