- #include
- #include
- #include
- struct Node
- {
- int num;
- char name[10];
- char sex;
- int phone_number;
- char addr[31];
- struct Node *pnext;
- struct Node *pfront;
- };
- struct Node * creat()
- {
- struct Node *head,*temp,*tail=0;
- int numtemp;
- printf("请输入编号姓名性别电话号码和住址,编号为0退出:\n");
- scanf("%d",&numtemp);
- while(numtemp>0)
- {
- temp=(struct Node *)malloc(sizeof(struct Node));
- temp->num=numtemp;
- scanf("%s%c%d%s",temp->name,&temp->sex,&temp->phone_number,temp->addr);
- if(!head)
- {
- head=tail=temp;
- }
- else
- {
- tail->pnext=temp;
- temp->pfront=tail;
- tail=temp;
- }
- printf("请输入编号姓名性别电话号码和住址,编号为0退出\n");
- scanf("%d",&numtemp);
- }
- return head;
- }
- void getin(struct Node *head)
- {
- struct Node *p;
- struct Node *temp=head;
- p=(struct Node *)malloc(sizeof(struct Node));
- printf("输入新添加联系人的编号姓名性别电话号码和住址");
- scanf("%d%s%c%d%s",&p->num,&p->name,&p->sex,&p->phone_number,&p->addr);
- while(temp->pnext!=NULL)
- {
- if((temp->num)>(p->num))
- {
- p->pfront=temp->pfront;
- temp->pfront->pnext=p;
- p->pnext=temp;
- temp->pfront=p;
- }
- else
- temp=temp->pnext;
- }
- if(p->pnext==NULL)
- {
- temp->pnext=p;
- p->pfront=temp;
- }
- }
- void put(struct Node * head)
- {
- struct Node *temp=head;
- while(temp->pnext!=NULL)
- {
- printf("%d\t%s\t%c\t%d\t%s\t",temp->num,temp->name,temp->sex,temp->phone_number,temp->addr);
- temp=temp->pnext;
- printf("\n");
- }
- printf("%d\t%s\t%c\t%d\t%s\t",temp->num,temp->name,temp->sex,temp->phone_number,temp->addr);
- }
- struct Node * serch(struct Node *head,char *names)
- {
- while(head!=NULL)
- {
- if(strcmp(head->name,names)==0)
- return head;
- else
- head=head->pnext;
- }
- printf("没有找到相关联系人");
- return 0;
- }
- void dele(struct Node *head,char *names)
- {
- while(head!=NULL)
- {
- if(strcmp(head->name,names)==0)
- {
- head->pfront->pnext=head->pnext;
- head->pnext->pfront=head->pfront;
- free(head);
- break;
- }
- else
- head=head->pnext;
- }
- }
- int main()
- {
- struct Node *head;
- int n;
- char names[20];
- char names2[20];
- struct Node *p;
- printf("创建通讯录请输入1,插入输入2,删除输入3,输出输入4,查找输入5,退出输入0\n");
- scanf("%d",&n);
- while(n!=0)
- {
- switch(n)
- {
- case 1:
- head=creat();
- break;
- case 2:
- getin(head);
- break;
- case 3:
- printf("请输入要删除的联系人姓名\n");
- gets(names);
- dele(head,names);
- break;
- case 4:
- put(head);
- break;
- case 5:
- printf("请输入要查找联系人的姓名\n");
- gets(names2);
- p=serch(head,names2);
- printf("%d\t%s\t%c\t%d\t%s",p->num,p->name,p->sex,p->phone_number,p->addr);
- break;
- case 0:
- while(head!=NULL)
- {
- struct Node *p=head;
- head=head->pnext;
- free(p);
- }
- return 0;
- }
- }
- return 0;
- }
大一狗遇到了一个问题,请大手帮忙看看!!!!
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
6条回答 默认 最新
悬赏问题
- ¥40 复杂的限制性的商函数处理
- ¥15 程序不包含适用于入口点的静态Main方法
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码