單鏈表寫通訊錄

2021-10-04 08:32:02 字數 3361 閱讀 1156

單鏈表實現通訊錄,增加,刪除,更改乙個聯絡人等功能。其中增加了乙個記憶體池功能,用於對廢棄記憶體的**和利用。

#include

#include

#include

#define max 1024

void

addperson

(struct presonlist *

*node)

;//新增乙個聯絡人

void

displaycontact

(struct presonlist *node)

;//顯示通訊錄

void

changperson

(struct presonlist *node,

char

**str1,

char

**str2)

;//更改聯絡人

void

delperson

(struct presonlist *

*node,

char

*str)

;//刪除乙個聯絡人

void

welcome

(void);

//歡迎介面

struct presonlist *pool =

null

;//定義乙個記憶體池

void

pooldelete

(void);

int count;

struct presonlist

;void

addperson

(struct presonlist *

*node)

//如果記憶體池為空,則用malloc申請空間

else

}printf()

;scanf_s

("%s"

, newlist->name,

sizeof

(newlist->name));

printf()

;scanf_s

("%s"

, newlist->number,

sizeof

(newlist->number));

if(*node ==

null

)//如果指標為空,直接將新節點插入即可

else

//採用尾插法

tail = newlist;

//保證尾指標指向鍊錶的最末尾

}void

displaycontact

(struct presonlist *node)

}void

delperson

(struct presonlist *

*node,

char

*str)

//輸入鍊錶和要刪除的字串

if(current ==

null

)else

else

if(count < max)

//如果記憶體池大小小於max,則把刪除的current存放在pool中

else

//否則直接插入即可

count++;}

else

//如果記憶體池大小大於max,直接釋放current結點}}

void

contactexit

(struct presonlist *

*node)

//直接釋放所有的鍊錶結點

}void

pooldelete

(void

)//刪除記憶體池

}struct presonlist *

findperson

(struct presonlist *node,

char

*str)

if(sear !=

null

)//如果不為空

else

}else

}void

changperson

(struct presonlist *node,

char

*str1,

char

*str2)

if(sear !=

null

)elseif(

!strcmp

(sear->number, str1)

)//不然就是**號碼

else

}else

}void

welcome

(void

)int

main

(void);

char change[

100]=;

welcome()

;while(1

)break

;case

'3':

printf()

;scanf_s

("%s"

, change,

sizeof

(change));

delperson

(&node, change)

;printf

("count:%d\n"

,count)

;break

;case

'4':

displaycontact

(node)

;break

;case

'5':

printf

("請輸入需要更改的名字/**號碼\n");

memset

(input,0,

sizeof

(input));

scanf_s

("%s"

, input,

sizeof

(input));

printf

("請輸入更改後的名字/**號碼\n");

scanf_s

("%s"

, change,

sizeof

(change));

changperson

(node, input, change)

;printf

("更改後的聯絡人列表:\n");

displaycontact

(node)

;break

;case

'6':

contactexit

(&node)

;pooldelete()

;printf

("已刪除所有列表\n");

welcome()

;break

;case

'7':

return0;

}}

單鏈表通訊錄 通訊錄2 0

單鏈表通訊錄 通訊錄2.0 標頭檔案 ifndef address h define address h include include include define success 10000 define failure 10001 define true 10002 define false ...

單鏈表實現通訊錄

main.c include include addresslist.h int main addresslist.c include include addresslist.h include int g id 10000 list createlist ls head next null 空鍊錶...

python 寫的通訊錄

儲存為 book.py 執行命令 python book.py f add n name1 a address1 新增 使用者,位址 python book.py f insert n name1 a address1 新增 根據 使用者,位址 python book.py f select n n...