-
大小: 25KB文件類型: .zip金幣: 2下載: 0 次發(fā)布日期: 2024-01-24
- 語言: 其他
- 標(biāo)簽: 數(shù)據(jù)結(jié)構(gòu)??鏈表??哈希表??
資源簡介
《數(shù)據(jù)結(jié)構(gòu)與算法分析》課程設(shè)計(jì)教學(xué)任務(wù)書
通訊錄系統(tǒng)設(shè)計(jì):
設(shè)計(jì)要求
設(shè)計(jì)以姓名為關(guān)鍵字的散列表(哈希表),實(shí)現(xiàn)通訊錄查找系統(tǒng),完成相應(yīng)的建表和查表程序。
(1)設(shè)每個記錄有下列數(shù)據(jù)項(xiàng):用戶名、電話號碼、地址;
(2)從鍵盤輸入各記錄,分別以姓名為關(guān)鍵字建立散列表;
(3)人名可以采用漢語拼音形式。人名字符串轉(zhuǎn)化為數(shù)字的方式自行決定。
(4)哈希函數(shù)用除留余數(shù)法構(gòu)造,采用二次探測再散列法解決沖突;
(5)根據(jù)姓名查找,找到顯示給定記錄的電話號碼和地址;找不到提示通訊錄無此人。
(6)通訊錄信息保存到文件。
=============================================================
以上為任務(wù)書,我的程序在其基礎(chǔ)上又增加了以下功能:
1、通訊錄信息以鏈表的形式進(jìn)行存儲。
2、可從文件讀取之前保存的通訊錄信息。
3、人名支持漢字。
===================================
文件說明:
contacts.c ——主程序文件
hash.c -- 支持哈希表操作的函數(shù)
hash.h -- 哈希類型接口文件
list.c -- 支持列表操作的函數(shù)
list.h——列表類型接口文件
menu.c —— 實(shí)現(xiàn)菜單的函數(shù)
menu.h —— 菜單函數(shù)的聲明
contacts.dat —— 數(shù)據(jù)存儲文件(二進(jìn)制形式)
Contacts.cbp ——CodeBlocks工程文件,如有CodeBlocks,可直接打開工程。

代碼片段和文件信息
#include?
#include?????/*?為了使用exit()函數(shù)?*/
#include?“menu.h“
#include?“l(fā)ist.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èi)存!\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(chǎn)‘?:
{
if?(ListIsEmpty(&peoples))
printf(“沒有數(shù)據(jù)“);
else
{
printf?(“通訊錄如下:\n“
“%-25s%-25s%-60s\n“
“姓名“?“電話“?“地址“);
Traverse(&peoples?showPeoples);
}
printf(“共計(jì)?%d?人\n“?ListItemCount(&peoples));
break;
}
case?‘b‘?:
{
puts(“請輸入聯(lián)系人的姓名:“);
while?(gets(temp.name)?!=?NULL?&&?temp.name[0]?!=?‘\0‘)
{
puts(“請輸入聯(lián)系人的電話號碼:“);
scanf(“%s“?temp.phonenum);
//????話說scanf()的參數(shù)不是要加“&”嗎?這里怎么沒有?
//????嘛,這個是數(shù)組名哦,已經(jīng)是地址了,再加&不就成了地址的地址了嗎
clearBuffer();
puts(“請輸入聯(lián)系人的地址:“);
scanf(“%s“?temp.address);
clearBuffer();
if?(AddItem(temp?&peoples)==false)
{
fprintf(stderr“添加失敗\n“);
break;
}
if?(ListIsFull(&peoples))
{
puts(“列表已滿“);
break;
}
puts(“輸入下一個聯(lián)系人的姓名(輸入空行結(jié)束輸入):“);
}
break;
}
case?‘c‘?:
CreateHash(H?&peoples);
break;
case?‘d‘?:
SearchHash(H);
break;
case?‘e‘?:
SaveList(&peoples);
break;
default?:
puts(“\a輸入有誤!\n“);
break;
}
puts(“按回車?yán)^續(xù).......“);
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
評論
共有 條評論