用C++编写通讯录
来源:优易学  2011-12-18 11:50:48   【优易学:中国教育考试门户网】   资料下载   IT书店

  while(head)
  {
  if(strcmp(head->name,in_name)==0) //比较名字是否相等。
  {
  cout<<head->name<<’\t’<<head->tel<<’\t’<<head->email<<’\t’<<head->relation<<’\n’;
  break;
  }
  head=head->next;
  }
  if(head==NULL)
  cout<<"没有你要找的名字!";
  cout<<endl;
  }
  //通讯录排序
  void Bubble(Address*head)
  {
  Address*m=head;
  Address*start=head,*present;
  present=start->next;
  Address*r=new Address;
  while(head->next!=NULL)
  {
  while(present!=NULL)
  {
  if(strcmp(start->name,present->name)>0)
  {
  strcpy(r->name,start->name);
  strcpy(r->tel,start->tel);
  strcpy(r->email,start->email);
  strcpy(r->relation,start->relation);
  strcpy(start->name,present->name);
  strcpy(start->tel,present->tel);
  strcpy(start->email,present->email);
  strcpy(start->relation,present->relation);
  strcpy(present->name,r->name);
  strcpy(present->tel,r->tel);
  strcpy(present->email,r->email);
  strcpy(present->relation,r->relation);
  }
  start=present;
  present=present->next;
  }
  start=m;
  present=m->next;
  head=head->next;
  }
  cout<<"显示当前所有记录:\n";
  while(m)
  {
  cout<<m->name<<’\t’<<m->tel<<’\t’<<m->email<<’\t’<<m->relation<<’\n’;
  m=m->next;
  }
  cout<<endl;
  }
  //删除记录
  void MoveAway(Address*head)
  {
  Address*start,*present=head;
  char in_name[20];
  cout<<"输入要删除人的名字:";
  cin>>in_name;
  while(head)
  {
  if(strcmp(head->name,in_name)==0) //比较名字是否相等。
  {
  cout<<"要删除的内容是: "<<endl;
  cout<<head->name<<’\t’<<head->tel<<’\t’<<head->email<<’\t’<<head->relation<<’\n’;
  break;
  }
  if(head->next!=NULL)
  head=head->next;
  else
  cout<<"没有你要找的名字!"; break;
  }
  cout<<endl;
  start=present;
  present=head;
  head=start;
  if(!head)
  { cout<<"列表是空的。\n"; return;}
  if(present==head) //被删除的节点是头节点。
  {
  start=head;
  head=head->next;
  delete start;
  start=NULL;
  cout<<"已删除。";
  return;
  }
  for(start=head;start!=present;start=start->next) //被删除节点不是头节点。找到被删除节点的前一节点。
  {
  if(start->next==present)
  {
  start->next=present->next;
  delete present;
  present=NULL;
  cout<<"已删除。";
  return;
  }
  }
  return;
  }
  //更新记录
  void ReSet(Address*head)
  {
  Address*s=head;
  char in_name[20];
  cout<<"输入要更新的名字:";
  cin>>in_name;
  int i;
  while(head) //首先判断该记录是否存在。
  {
  if(strcmp(head->name,in_name)==0) //比较名字是否相等。
  {
  cout<<"要更新的内容存在。"<<endl;
  cout<<head->name<<’\t’<<head->tel<<’\t’<<head->email<<’\t’<<head->relation<<endl;
  break;
  }
  head=head->next;
  }
  if(head==NULL)
  cout<<"没有你要找的名字!";
  cout<<endl;
  head=s;
  while(s)
  {
  if(strcmp(s->name,in_name)==0) //比较名字是否相等。
  {
  cout<<"要更新什么内容?输入1选择更新人名;输入2选择更新电话;输入3选择更新Email;输入4选择更新与本人的关系。"<<endl;
  cin>>i;
  cout<<"输入要更改的内容。"<<endl;

上一页  [1] [2] [3] 下一页

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训