單向鍊錶例項 終端互動簡易通訊錄

2022-08-14 04:33:11 字數 3996 閱讀 7197

1 #include    2 #include    3 #include    45

6 typedef struct

contacts_infomationcon_info;

1314

15 con_info * creat_node(void)16

24new->next =null;

2526

return

new;27}

2829

int insert_node(con_info **phead)

30

3839 printf("

please input name,work unit,phone number and e-mail (separated by enter):\n");

40 printf("

name:");

41 scanf("

%s", new->name);

42 printf("

work unit:");

43 scanf("

%s", new->work_unit);

44 printf("

phone number:");

45 scanf("

%s", new->phone_number);

46 printf("

e-mail:");

47 scanf("

%s", new->e_mail);

4849

if(!(*phead))

53if(strncmp((*phead)->name,new->name,3) > 0)58

while(cur->next)64}

65 cur->next = new;66

67return0;

68}69int del_node(con_info **phead)

77 printf("

please input want delete name: ");

78 scanf("%s"

, name);

7980

if(strcasecmp((*phead)->name, name) == 0)86

while(cur->next)

93 cur = cur->next;94}

95getchar();

96 printf("

\n\ncan't find %s\n

", name);

97 printf("

\n\nplease input enter continue...");

98char ch =getchar();

99100

return

0;

101}

102103

int mod_node(con_info **phead)

112 printf("

please input want modify name: ");

113 scanf("%s"

, name);

114while

(cur)

123 printf("

modify work unit?(y/any key): ");

124 scanf("%s"

, reply);

125if(strcmp(reply, "

y") == 0

)129 printf("

modify phone number?(y/any key): ");

130 scanf("%s"

, reply);

131if(strcmp(reply, "

y") == 0

)135 printf("

modify e-mail?(y/any key): ");

136 scanf("%s"

, reply);

137if(strcmp(reply, "

y") == 0

)141

return0;

142}

143 cur = cur->next;

144}

145getchar();

146 printf("

no contact was found.\n");

147 printf("

\n\nplease input enter continue...");

148char ch =getchar();

149return0;

150}

151152

int search_node(con_info **phead)

159 printf("

please input name or phone number: ");

160 scanf("

%s", in

);161

162while

(cur)

172 cur = cur->next;

173}

174 printf("

\n\ncan't find %s\n

", in

);175

getchar();

176 printf("

please input enter continue...");

177char ch =getchar();

178179

return0;

180}

181int print_con(con_info *phead)

189while

(cur)

193getchar();

194 printf("

\n\nplease input enter continue...");

195char ch =getchar();

196197

return0;

198}

199200

201202

203int main(void

)204

else

if(!strcmp(op, "2"

))else

if(!strcmp(op, "3"

))else

if(!strcmp(op, "4"

))else

if(!strcmp(op, "5"

))else

if(!strcmp(op, "6"

))else

if(!strcmp(op, "8"

))230

else

233 }while(1

);

234235

return0;

236 }

由於通訊錄不怎麼需要倒序操作,又是乙個簡易的,所以乾脆就使用了單向鍊錶。running demo:

互動介面(^_^簡易的,所以特別簡陋):

各個功能演示一遍:

鍊錶通訊錄

include include include define password 208140119 define name max 20 define gender max 10 define str max 20 define tel max 20 鍊錶結構 struct address type...

鍊錶通訊錄

include include include include include struct addressbook typedef struct addressbook addressbook typedef struct addressbook link int main menu void a...

鍊錶寫的通訊錄

include include include include struct node typedef struct node node typedef struct node link void create link head void insert link head,link new nod...