資源簡介
《數據結構與算法分析》課程設計教學任務書
通訊錄系統設計:
設計要求
設計以姓名為關鍵字的散列表(哈希表),實現通訊錄查找系統,完成相應的建表和查表程序。
(1)設每個記錄有下列數據項:用戶名、電話號碼、地址;
(2)從鍵盤輸入各記錄,分別以姓名為關鍵字建立散列表;
(3)人名可以采用漢語拼音形式。人名字符串轉化為數字的方式自行決定。
(4)哈希函數用除留余數法構造,采用二次探測再散列法解決沖突;
(5)根據姓名查找,找到顯示給定記錄的電話號碼和地址;找不到提示通訊錄無此人。
(6)通訊錄信息保存到文件。
=============================================================
以上為任務書,我的程序在其基礎上又增加了以下功能:
1、通訊錄信息以鏈表的形式進行存儲。
2、可從文件讀取之前保存的通訊錄信息。
3、人名支持漢字。
===================================
文件說明:
contacts.c ——主程序文件
hash.c -- 支持哈希表操作的函數
hash.h -- 哈希類型接口文件
list.c -- 支持列表操作的函數
list.h——列表類型接口文件
menu.c —— 實現菜單的函數
menu.h —— 菜單函數的聲明
contacts.dat —— 數據存儲文件(二進制形式)
Contacts.cbp ——CodeBlocks工程文件,如有CodeBlocks,可直接打開工程。

代碼片段和文件信息
#include?
#include?????/*?為了使用exit()函數?*/
#include?“menu.h“
#include?“list.h“
#include?“hash.h“
static?void?showPeoples(Item?item);
int?main(void)
{
int?i;
List?peoples;
Item?temp;
/*?初始化???????*/
InitializeList(&peoples);
if?(ListIsFull(&peoples))
{
fprintf(stderr“沒有可用的內存!\n“);
exit(1);
}
HashTable?*?H;
H?=?(HashTable*)malloc(sizeof(HashTable));
for(i=0;i {
H->elem[i]=NULL;
}
H->size=HASHSIZE;
H->count=0;
/*?由文件讀取?*/
LoadList(&peoples);
// LoadTXTList(&peoples);
int?choice;
while((choice?=?getChoice())?!=?‘q‘)
{
switch(choice)
{
case?‘a‘?:
{
if?(ListIsEmpty(&peoples))
printf(“沒有數據“);
else
{
printf?(“通訊錄如下:\n“
“%-25s%-25s%-60s\n“
“姓名“?“電話“?“地址“);
Traverse(&peoples?showPeoples);
}
printf(“共計?%d?人\n“?ListItemCount(&peoples));
break;
}
case?‘b‘?:
{
puts(“請輸入聯系人的姓名:“);
while?(gets(temp.name)?!=?NULL?&&?temp.name[0]?!=?‘\0‘)
{
puts(“請輸入聯系人的電話號碼:“);
scanf(“%s“?temp.phonenum);
//????話說scanf()的參數不是要加“&”嗎?這里怎么沒有?
//????嘛,這個是數組名哦,已經是地址了,再加&不就成了地址的地址了嗎
clearBuffer();
puts(“請輸入聯系人的地址:“);
scanf(“%s“?temp.address);
clearBuffer();
if?(AddItem(temp?&peoples)==false)
{
fprintf(stderr“添加失敗\n“);
break;
}
if?(ListIsFull(&peoples))
{
puts(“列表已滿“);
break;
}
puts(“輸入下一個聯系人的姓名(輸入空行結束輸入):“);
}
break;
}
case?‘c‘?:
CreateHash(H?&peoples);
break;
case?‘d‘?:
SearchHash(H);
break;
case?‘e‘?:
SaveList(&peoples);
break;
default?:
puts(“\a輸入有誤!\n“);
break;
}
puts(“按回車繼續.......“);
clearBuffer();
putchar(‘\n‘);
}
puts(“\n謝謝使用!再見!\n“);
/*?清空????????*/
EmptyTheList(&peoples);
printf(“再見!\n“);
getchar();
return?0;
}
static?void?showPeoples(Item?item)
{
printf(“%-25s%-25s%-60s\n“
item.name
item.phonenum
item.address);
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-01-07?17:38??Contacts\
?????文件????????2296??2014-01-07?17:35??Contacts\contacts.c
?????文件????????1617??2013-07-11?13:02??Contacts\Contacts.cbp
?????文件???????16485??2013-07-11?13:00??Contacts\contacts.dat
?????文件???????46023??2014-01-07?17:36??Contacts\Contacts.exe
?????文件????????2984??2013-07-11?10:24??Contacts\hash.c
?????文件?????????914??2013-07-11?07:33??Contacts\hash.h
?????文件????????3037??2013-07-11?12:58??Contacts\list.c
?????文件????????2188??2013-07-11?12:52??Contacts\list.h
?????文件?????????830??2013-07-11?12:47??Contacts\menu.c
?????文件?????????152??2013-07-11?11:28??Contacts\menu.h
- 上一篇:大白鯊遠控1.5共享版
- 下一篇:微機原理與接口技術期末試題及答案
評論
共有 條評論