level 13
狗gou富贵
楼主
基于链表结构实现一个简单的通讯录管理系统,实现通讯录的简单电子化。该系统具有增加新纪录,修改原记录,删除原纪录,根据姓名查找和查看所有记录等功能。
#include<bits/stdc++.h>
using namespace std;
struct stud_node{
char name[20];
struct stud_node *next; };
struct stud_node * InsertDoc(struct stud_node * head, struct stud_node *stud);
struct stud_node * DeleteDoc(struct stud_node * head, char *name);
struct stud_node * FindDoc(struct stud_node * head,char *name);
int Print_Stu_Doc(struct stud_node * head);
int main()
{
struct stud_node *head,*p;
int choice;
char name[20];
int size = sizeof(struct stud_node);
head=nullptr;
cout<<"1.增加新记录\n"<<"2.修改原记录\n"<<"3.删除原纪录\n"<<"4.根据姓名查找\n"<<"5.查看所有记录\n"<<"6.out\n"<<endl;
cin>>choice;
switch(choice) {
case 1:
printf("增加人员的信息");
printf("姓名:");
scanf("%s",name);
p = (struct stud_node *) malloc(size);
strcpy(p->name, name);
p->next=nullptr;
head=InsertDoc(head, p);
break;
case 2:
printf("修改信息");
scanf("%s", name);
if ((p=FindDoc(head,name)) !=NULL)
{ printf("录入信息:\n");
printf("姓名:");
scanf("%s",p->name);
}
else
printf("no\n");
break;
case 3:
printf("删除信息;\n");
scanf("%s",name);
if ((p=FindDoc(head,name)) !=NULL)
head = DeleteDoc(head, name);
else
printf("no\n");
break;
case 4 :
printf ("查找姓名\n");
scanf("%s",name);
if ((p=FindDoc(head,name)) !=NULL)
{ printf("姓名:%s\n",p->name);
}
else
printf("no\n");
break;
case 5:
Print_Stu_Doc(head);
break;
case 6:
break;
}
while(choice != 6);
return 0;
}
struct stud_node * InsertDoc(struct stud_node * head, struct stud_node *stud)
{
struct stud_node *ptr;
ptr = stud;
if(head == NULL)
{ head = ptr;
head->next = NULL; }
else
{ ptr->next=head;
head=ptr;
}
return head;
}
struct stud_node * DeleteDoc(struct stud_node * head, char *name)
{
struct stud_node *ptrl, *ptr2;
while(head!=NULL && strcmp(head->name,name) == 0)
{ptr2 = head;
head = head->next; free(ptr2);
}
if(head == NULL)
return NULL;
ptrl = head;
ptr2 = head->next;
while(ptr2!=NULL){
if(strcmp(ptr2->name,name) == 0)
{ ptrl->next = ptr2->next;
free(ptr2);}
else
ptrl = ptr2;
ptr2 = ptrl->next;
}
return head;
}
int Print_Stu_Doc(struct stud_node * head)
{ struct stud_node * p;
if(head == NULL){
printf("\nno\n");
}
printf("记录:\n");
p = head;
while ( p!=NULL)
{ printf("姓名:%s\n",p->name);
}
}
struct stud_node * FindDoc(struct stud_node * head,char *name)
{
struct stud_node * p=head;
while(p!=NULL)
{ if(strcmp(p->name,name)==0)
return p;
else
p=p->next;
}
return p;
}

这样之后按什么都无效
2018年03月24日 11点03分
1
#include<bits/stdc++.h>
using namespace std;
struct stud_node{
char name[20];
struct stud_node *next; };
struct stud_node * InsertDoc(struct stud_node * head, struct stud_node *stud);
struct stud_node * DeleteDoc(struct stud_node * head, char *name);
struct stud_node * FindDoc(struct stud_node * head,char *name);
int Print_Stu_Doc(struct stud_node * head);
int main()
{
struct stud_node *head,*p;
int choice;
char name[20];
int size = sizeof(struct stud_node);
head=nullptr;
cout<<"1.增加新记录\n"<<"2.修改原记录\n"<<"3.删除原纪录\n"<<"4.根据姓名查找\n"<<"5.查看所有记录\n"<<"6.out\n"<<endl;
cin>>choice;
switch(choice) {
case 1:
printf("增加人员的信息");
printf("姓名:");
scanf("%s",name);
p = (struct stud_node *) malloc(size);
strcpy(p->name, name);
p->next=nullptr;
head=InsertDoc(head, p);
break;
case 2:
printf("修改信息");
scanf("%s", name);
if ((p=FindDoc(head,name)) !=NULL)
{ printf("录入信息:\n");
printf("姓名:");
scanf("%s",p->name);
}
else
printf("no\n");
break;
case 3:
printf("删除信息;\n");
scanf("%s",name);
if ((p=FindDoc(head,name)) !=NULL)
head = DeleteDoc(head, name);
else
printf("no\n");
break;
case 4 :
printf ("查找姓名\n");
scanf("%s",name);
if ((p=FindDoc(head,name)) !=NULL)
{ printf("姓名:%s\n",p->name);
}
else
printf("no\n");
break;
case 5:
Print_Stu_Doc(head);
break;
case 6:
break;
}
while(choice != 6);
return 0;
}
struct stud_node * InsertDoc(struct stud_node * head, struct stud_node *stud)
{
struct stud_node *ptr;
ptr = stud;
if(head == NULL)
{ head = ptr;
head->next = NULL; }
else
{ ptr->next=head;
head=ptr;
}
return head;
}
struct stud_node * DeleteDoc(struct stud_node * head, char *name)
{
struct stud_node *ptrl, *ptr2;
while(head!=NULL && strcmp(head->name,name) == 0)
{ptr2 = head;
head = head->next; free(ptr2);
}
if(head == NULL)
return NULL;
ptrl = head;
ptr2 = head->next;
while(ptr2!=NULL){
if(strcmp(ptr2->name,name) == 0)
{ ptrl->next = ptr2->next;
free(ptr2);}
else
ptrl = ptr2;
ptr2 = ptrl->next;
}
return head;
}
int Print_Stu_Doc(struct stud_node * head)
{ struct stud_node * p;
if(head == NULL){
printf("\nno\n");
}
printf("记录:\n");
p = head;
while ( p!=NULL)
{ printf("姓名:%s\n",p->name);
}
}
struct stud_node * FindDoc(struct stud_node * head,char *name)
{
struct stud_node * p=head;
while(p!=NULL)
{ if(strcmp(p->name,name)==0)
return p;
else
p=p->next;
}
return p;
}

这样之后按什么都无效