| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 425 人关注过本帖
标题:请帮我把下面这个程序改正确,如果改不了能帮我重新编一个吗?真的很急迫! ...
只看楼主 加入收藏
Junzeo
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-10-27
收藏
 问题点数:0 回复次数:0 
请帮我把下面这个程序改正确,如果改不了能帮我重新编一个吗?真的很急迫!!!


原题是利用有序单链表实现集合的差运算
集合的元素限定为小写字母字符【'a'..'z'】


#include
#include
 typedef struct pointer{
  char dat;
  struct pointer *link;
 } pointer;
void readdata(pointer *head){ //读集合
 pointer *p;
 char tmp;
 printf("input data ('0' for end):");
 scanf("%c",&tmp);
 while(tmp!='0')
 {
  if((tmp<'a')||(tmp>'z'))
  {
   printf("输入错误!必须为小写字母!\n");
   return;
                }
  p=(pointer *)malloc(sizeof(struct pointer));
  p->dat=tmp;
  p->link=head->link;
  head->link=p;
  scanf("%c",&tmp);
 }
}
void disp(pointer *head){ //显示集合数据
 pointer *p;
 p=head->link;
 while(p!=NULL)
 {
  printf("%c ",p->dat);
  p=p->link;
 }
 printf("\n");
}
 
void cha(pointer *head1,pointer *head2, pointer *head3){ //计算集合1与集合2的差
 pointer *p1,*p2,*p3;
 p1=head1->link;
 while(p1!=NULL)
 {
  p2=head2->link;
  while((p2!=NULL)&&(p2->dat!=p1->dat))
   p2=p2->link;
  if(p2==NULL)
  {
   p3=(pointer *)malloc(sizeof(struct pointer));
   p3->dat=p1->dat;
   p3->link=head3->link;
   head3->link=p3;
  }
  p1=p1->link;
 }
}
main(){
 pointer *head1,*head2,*head3;
 head1=(pointer *)malloc(sizeof(struct pointer));
 head1->link=NULL;
 head2=(pointer *)malloc(sizeof(struct pointer));
 head2->link=NULL;
 head3=(pointer *)malloc(sizeof(struct pointer));
 head3->link=NULL;
 printf("输入集合1:\n");
 readdata(head1);
 printf("输入集合2:\n");
 readdata(head2);
 printf("集合1为:\n");
 disp(head1);
 printf("集合2为:\n");
 disp(head2);
 printf("集合1与集合2的差为:\n");
 cha(head1,head2,head3);
 disp(head3);
}
 



搜索更多相关主题的帖子: return include pointer 元素 
2012-10-27 15:45
快速回复:请帮我把下面这个程序改正确,如果改不了能帮我重新编一个吗?真的很急 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014121 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved