欢迎来到一句话经典语录网
我要投稿 投诉建议
当前位置:一句话经典语录 > 心得体会 > 单链表通讯录心得体会

单链表通讯录心得体会

时间:2018-03-25 15:06

求C语言通讯录程序(如何通过链表来实现通讯录的增删减功能

一直想写来着,但是最近写算法太忙,只有一个原来的版本,不是很完善,不好意思给你,还是等等吧

用C语言编写一个通讯录系统,集合数据结构双向链表知识

\\\/\\\/类似\\\/\\\/#include stdafx.h#include #include #include class stu { char name[20]; double age,homephone,telphone; char sex; public: stu(){} stu(char n[20],char se,double ag,double ho,double te) { strcpy(name, n); age=ag; homephone=ho; telphone=te; } friend void main(); }; void main() { cout<<请选择您需要的操作

<

<>p; if((p>='0'&&p<='5')) flag2=1; else cout<<指令错误

请重新输入:<>name; cout<<请输入性别:<>sex; cout<<请输入年龄:<>age; cout<<请输入家里的电话号码:<>homephone; cout<<请输入移动电话号码:<>telphone; j++; s[i]=new stu(name, sex, age, homephone , telphone); i++; cout<<数据录入成功,想继续录入吗(y\\\/n)<>c; flag2=0; do { if(c!='y'&&c!='n') { cout<<指令错误

请重新输入

<>c; } else flag2=1; }while(flag2==0); }while(c=='y'); break; } \\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/\\\/ case '1': \\\/\\\/(1)增加人员(Add) { char name[20]; double age,homephone,telphone; char sex,c; do{ cout<<请输入姓名:<>name; cout<<请输入性别:<>sex; cout<<请输入年龄:<>age; cout<<请输入家里的电话号码:<>homephone; cout<<请输入移动电话号码:<>telphone; j++; s[i]=new stu(name, sex, age, homephone , telphone); i++; cout<<数据录入成功,想继续录入吗(y\\\/n)<>c; flag2=0; do { if(c!='y'&&c!='n') { cout<<指令错误

请重新输入

<>c; } else flag2=1; }while(flag2==0); }while(c=='y'); break; } case '2': \\\/\\\/(2)删除人员(Delete) { char name[20];bool flag3=0;char c; do{ cout<<请输入您要删除的学生姓名:<>name; for(int h=0;hname)==0) { flag3=1; i--; do{ s[h]=s[h+1]; h++; }while(h<=i); } } if(flag3==0) cout<<您要求删除的对象本来就不存在

请检查输入的正确性

; cout<<要继续删除吗

(y\\\/n)<>c; if(c!='y'&&c!='n') { cout<<指令错误

请重新输入

<>c; } }while(c=='y'); break; } case '3': \\\/\\\/(3)修改数据(Alter) { char name[20],se;double ag,ho,te;flag2=0; char c; do { cout<<请输入您要修改的学生的姓名:<>name; for(int h=0;hname)==0) { flag2=1; cout<<请输入性别:<>se; cout<<请输入年龄:<>ag; cout<<请输入家里的电话号码:<>ho; cout<<请输入移动电话号码:<>te; s[h]->sex=se; s[h]->age=ag; s[h]->homephone=ho; s[h]->telphone=te; cout<<数据修改成功

; } } if(flag2==0) { cout<<您要修改的学生本来就不存在

请检查重新输入

<>c; if(c!='y'&&c!='n') { cout<<指令错误

请重新输入

<>c; } }while(c=='y'); break; } case '4': \\\/\\\/(4)显示记录(List) { cout<<本系统所有通讯录的数据如下:<

<name<< 性别:<< <sex<<年龄:<< <age <<家里的电话号码:<< <homephone<<移动电话号码: << <telphone<>p; if(p!='y'&&p!='n') cout<<指令错误

请重新输入

<>p; for(int x=0;x

C语言:用链表写通讯录

void add(struct people* head)case 1:add();break;你的定义和使用时候完全不一样啊,这怎么可能正确。

求一纯C语言单链表通讯录:

typedef struct record{ struct record* next; char* name; char* postalCode; char* phoneNumber; char* fax; char* email;}*Record;struct record head={0};Record recordLst=&head;Record CreateRecord(char* name,char*postalCode,char*phoneNumber,char*fax,char*email){ Record r=(Record)malloc(sizeof(*r)); r->name=(char*)malloc(strlen(name)+1); r->postalCode=(char*)malloc(strlen(postalCode)+1); r->phoneNumber=(char*)malloc(strlen(phoneNumber)+1); r->fax=(char*)malloc(strlen(fax)+1); r->email=(char*)malloc(strlen(email)+1); strcpy(r->postalCode,postalCode); strcpy(r->phoneNumber,phoneNumber); strcpy(r->fax,fax); strcpy(r->name,name); strcpy(r->email,email); r->next=NULL;}Record Lookup(char* name)\\\/\\\/查找某记录{ Record r=recordLst->next; while(r){ if(!strcmp(name,r->name)) return r; r=r->next; } return r;}Record Delete(char*name)\\\/\\\/删除某记录{ Record prev,cur; if(name==NULL) return NULL; prev=cur=recordLst; for (;cur;cur=cur->next) { if(!strcmp(name,cur->name)) break; prev=cur; } if(cur==NULL) return NULL; prev->next=cur->next; return cur;}Record Insert(char* name,char*postalCode,char*phoneNumber,char*fax,char*email){\\\/\\\/添加新的记录 Record r=CreateRecord(name,postalCode,phoneNumber,fax,email); r->next=recordLst->next; recordLst->next=r; } 四、浏览通讯录 没写,不知道你所谓的浏览通讯录是怎么个浏览法

链表相关问题,就是一个通讯录的设计,使用C++。

谢谢。

能改最好,不行就重写吧~

#include #include #define Null 0#define OverFlow -1#define OK 0#define Error -2typedef int ElemType;typedef struct node{ ElemType data; struct node *next;}Node,*LinkList;void Init_LinkList(LinkList *Head_pointer){\\\/\\\/线性表初始化 *Head_pointer = Null;}int Insert_First(LinkList *Head_pointer,ElemType x){\\\/\\\/采用头插法建立线性表 Node *p; p=(Node *)malloc(sizeof Node); if(p==NULL) return OverFlow; p->data=x; p->next = *Head_pointer; *Head_pointer = p; return OK;}LinkList Location_LinkList(LinkList Head,ElemType x){\\\/\\\/查询链表中某结点数据是否存在 LinkList p; p=Head; while(p!=Null) { if(p->data==x) break; p=p->next; } return p;}int Delete_LinkList(LinkList *Head_pointer,ElemType x){\\\/\\\/删除链表中的某一结点 Node *p,*q; p=*Head_pointer; if(p->data==x)\\\/\\\/考虑头结点就是要删除的元素 { *Head_pointer =(*Head_pointer)->next; free(p); return OK; } else { q=p;p=p->next; while(p!=Null) { if(p->data==x) { q->next = p->next; free(p); return OK; } q=p;p=p->next; } } return Error;}void Show_LinkList(LinkList Head){\\\/\\\/遍历线性表中的元素 LinkList p=Head; int i=0; printf(---链表打印---\\\ ); if(p==Null) printf(空表\\\ ); while(p!=Null) { printf([%d]:%d\\\,i++,p->data); p=p->next; }}int Length_LinkList(LinkList Head){\\\/\\\/求链表长度 LinkList p=Head; int sum=0; while(p!=Null) { sum++; p=p->next; } return sum;}void SetNull_LinkList(LinkList *Head_pointer){\\\/\\\/链表清空 LinkList p,q; p=*Head_pointer; while(p!=Null) { q=p;p=p->next;free(q); }}int main(void){ LinkList Head; int i; Node *loca; ElemType x; Init_LinkList(&Head); do { printf(\\\ ); printf(1---插入一个元素(Insert)\\\ ); printf(2---查询一个元素(Locate)\\\ ); printf(3---删除一个元素(Delete)\\\ ); printf(4---显示所有元素(Show)\\\ ); printf(5---计算表的长度(Length)\\\ ); printf(6---退出\\\ ); scanf(%d,&i); switch(i) { case 1:printf(请输入要插入的分数:\\\ ); scanf(%d,&x); if(Insert_First(&Head,x)!=OK) printf(插入失败\\\ ); break; case 2: printf(请输入要查询的分数:\\\ ); scanf(%d,&x); loca = Location_LinkList(Head,x); if(loca!=Null) printf(查询成功\\\ ); else printf(查询失败\\\ ); break; case 3: printf(请输入要删除的分数:\\\ ); scanf(%d,&x); if(Delete_LinkList(&Head,x)!=OK) printf(删除失败\\\ ); else printf(删除成功\\\ ); break; case 4:Show_LinkList(Head); break; case 5:printf(表的长度是:%d,Length_LinkList(Head)); break; case 6:break; } }while(i!=6); SetNull_LinkList(&Head); printf(链表已清空,程序退出...\\\ ); return 0;}

数据结构双向链表设计学生通讯录管理系统

\\\/\\\/帮你改了,可以查找第一条记录,你那个查找最还也弄个循环,遍历所有的记录#include#include#define LEN sizeof(struct TXL)struct TXL {char name;int num;struct TXL*next;};int n;char a ;struct TXL*creat(){struct TXL*head;struct TXL*p1,*p2;n=0;p1=p2=(struct TXL*)malloc(LEN);scanf(%c,%d,&p1->name,&p1->num);head=NULL;while (p1->name!='0') {n=n+1;if(n==1){head=p1;head->next=NULL;}else{ p2->next=p1;p2=p1;}p1=(struct TXL*)malloc(LEN);scanf(%c,%d,&p1->name,&p1->num);}p1->next=NULL;return(head);}void find(struct TXL* head){struct TXL*p;printf(please input name\\\ );getchar();scanf(%c,&a);p=head;if(a==p->name)printf(Name:%c TEL:%d,p->name,p->num);elseprintf(Can't find);}void main(){struct TXL *head;head=creat();find(head);}

声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。联系xxxxxxxx.com

Copyright©2020 一句话经典语录 www.yiyyy.com 版权所有

友情链接

心理测试 图片大全 壁纸图片