当前位置:网站首页>通讯录管理系统链表实现
通讯录管理系统链表实现
2022-07-06 05:39:00 【用编程写诗】
本程序采用链表的方式可以实现对于通讯录信息的管理操作主要有增 删 改 查 显示全部信息 退出六个功能。代码注释都有逻辑简单易懂适合初学者进行链表的学习。
代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct stu{
char name[20];//姓名
int phone;//电话
int telephone;//移动电话
int youbian;//邮编
char tongxun[20];//通讯地址信息
}stu;
typedef struct linklist{
stu date;
struct linklist *next;
}linklist;
struct linklist* head=NULL;
struct linklist* tail=NULL;
void menu(){
system("cls");
printf("\t\t\t\t***************************************************\n");
printf("\t\t\t\t* *\n");
printf("\t\t\t\t*1.录入信息 2.查找信息 3.删除信息 *\n");
printf("\t\t\t\t* *\n");
printf("\t\t\t\t*4.修改信息 5.显示信息 6.退出程序 *\n");
printf("\t\t\t\t***************************************************\n");
}
void add(linklist *head){
linklist *q=(linklist*)malloc(sizeof(linklist));
q->next=NULL;
linklist *p;
p=head;
char nam[20];
printf(" 请输入姓名 \n");
scanf("%s",nam);
while(p->next!=NULL){
if(strcmp(p->date.name,nam)==0){
printf("该学生已存在\n");
break;
}
p=p->next;
}
if(p->next==NULL){
strcpy(q->date.name,nam);
printf(" 请输入电话 \n");
scanf("%d",&q->date.phone);
printf(" 请输入移动电话 \n");
scanf("%d",&q->date.telephone);
printf(" 请输入邮编 \n");
scanf("%d",&q->date.youbian);
printf(" 请输入通讯地址信息 \n");
scanf("%s",&q->date.tongxun);
p->next=q;
p=q;
}
}
void delet(linklist *head) {
linklist *p,*q;
p=(linklist*)malloc(sizeof(linklist));
q=(linklist*)malloc(sizeof(linklist));
p=head;
q=p->next;
char name3[20];
if(p==NULL) {
printf("此时无数据");
return;
}
else {
printf("请输入你想删除的学生的名字");
scanf("%s",name3);
while(q!=NULL) {
if(strcmp(q->date.name,name3)==0){
p->next=q->next;
free(q);
printf("删除成功!\n");
}
p=q;
q=q->next;
}
}
}
void seek( linklist *head) {
int k=0;
char name3[20];
printf("请输入学生姓名:\n");
scanf("%s",name3);
linklist *p;
p=(linklist*)malloc(sizeof(linklist));
p=head->next;
if(p==NULL){
printf("\t\t\t\t\t还未录入信息!!!\n");
}
while(p!=NULL){
if(strcmp(name3,p->date.name)==0) {
k=k+1;
printf("姓名:%s 电话:%d 移动电话:%d 邮编:%d 通讯地址信息:%s\n",p->date.name,p->date.phone,p->date.telephone,p->date.youbian,p->date.tongxun);
}
p=p->next;
}
if(k==0){
printf("查无此人");
}
}
void change(linklist *head){
char name4[20];
printf("请输入学生姓名:\n");
scanf("%s",name4);
int k=0;
linklist *p;
p=(linklist*)malloc(sizeof(linklist));
p=head->next;
while(p!=NULL){
if(strcmp(name4,p->date.name)==0) {
k=1;
printf("修改前:\n");
printf("姓名:%s 电话:%d 移动电话:%d 邮编:%d 通讯地址信息:%s\n",p->date.name,p->date.phone,p->date.telephone,p->date.youbian,p->date.tongxun);
}
p=p->next;
}
if(k==0){
printf("查无此人\n");
}
p=head->next;
while(p!=NULL){
if(strcmp(name4,p->date.name)==0){
printf("请输入移动电话要修改成多少");
scanf("%d",&p->date.telephone);
printf("修改后:\n");
printf("姓名:%s 电话:%d 移动电话:%d 邮编:%d 通讯地址信息:%s\n",p->date.name,p->date.phone,p->date.telephone,p->date.youbian,p->date.tongxun);
break;
}
}
p=p->next;
}
void print(linklist *head){
linklist *p;
p=(linklist*)malloc(sizeof(linklist));
p=head->next;
while(p!=NULL){
printf("姓名:%s 电话:%d 移动电话:%d 邮编:%d 通讯地址信息:%s\n",p->date.name,p->date.phone,p->date.telephone,p->date.youbian,p->date.tongxun);
p=p->next;
}
}
int main()
{
int choose;
head=(linklist*)malloc(sizeof(linklist));
head->next=NULL;
while(1){
menu();
scanf("%d",&choose);
switch(choose){
case 1:
do{
system("cls");
add(head);
char sel[5];
printf("\t\t\t\t\t\t是否继续添加(yes or no): ");
scanf("%s",sel);
if(strcmp(sel,"yes")==0) continue;
else break;
}while(1);
break;
case 2:
do{
printf("\t\t\t\t欢迎来到查找界面,请按要求完成操作|(@@)|\n");
seek(head);
printf("\n\n\t\t\t\t\t\t是否继续查找(yes or no):");
char sel2[5];
scanf("%s",sel2);
if(strcmp(sel2,"yes")==0) continue;
else break;
}while(1);
break;
case 3:
do{
delet(head);
char sel3[5];
printf("\t\t\t\t是否继续删除(yes or no): ");
scanf("%s",sel3);
if(strcmp(sel3,"yes")==0) continue;
else break;
}while(1);
break;
case 4:
change(head);
break;
case 5:
system("cls");
print(head);
printf("退出请输入0:");
int sel6;
scanf("%d",&sel6);
if(sel6==0) break;
default:
printf("\n感谢使用!\n");
return 0;
}
}
return 0;
}
边栏推荐
- The digital economy has broken through the waves. Is Ltd a Web3.0 website with independent rights and interests?
- Unity Vector3. Use and calculation principle of reflect
- 【经验】win11上安装visio
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Note the various data set acquisition methods of jvxetable
- Knowledge points of circular structure
- 【云原生】3.1 Kubernetes平台安装KubeSpher
- Analysis of grammar elements in turtle Library
- Figure database ongdb release v-1.0.3
- 自建DNS服务器,客户端打开网页慢,解决办法
猜你喜欢
剑指 Offer II 039. 直方图最大矩形面积
03. 开发博客项目之登录
【SQL server速成之路】——身份驗證及建立和管理用戶賬戶
类和对象(一)this指针详解
B站刘二大人-线性回归及梯度下降
js Array 列表 实战使用总结
【经验】win11上安装visio
01. 开发博客项目之项目介绍
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
嵌入式面试题(四、常见算法)
随机推荐
剑指 Offer II 039. 直方图最大矩形面积
What impact will frequent job hopping have on your career?
【华为机试真题详解】统计射击比赛成绩
JS array list actual use summary
[leetcode] 18. Sum of four numbers
Jvxetable用slot植入j-popup
UCF(暑期团队赛二)
Easy to understand IIC protocol explanation
B站刘二大人-多元逻辑回归 Lecture 7
Selective parameters in MATLAB functions
After the project is released, index Html is cached
嵌入式面试题(四、常见算法)
[QNX hypervisor 2.2 user manual]6.3.3 using shared memory (shmem) virtual devices
Text classification still stays at Bert? The dual contrast learning framework is too strong
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Analysis of grammar elements in turtle Library
What preparations should be made for website server migration?
Qt TCP 分包粘包的解决方法
B站刘二大人-反向传播
Application Security Series 37: log injection