| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 371 人关注过本帖
标题:集合的并运算。帮下忙
只看楼主 加入收藏
dengjun000
Rank: 2
等 级:论坛游民
帖 子:66
专家分:77
注 册:2009-10-14
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
集合的并运算。帮下忙
我用的单链表做的集合并运算,,集合A和B 最后求的结果放在B;我用的是WIN-TC;代码如下
#include <stdio.h>
#include <stdlib.h>

struct set
{
  int info;
  struct set *next;
};

void createlist(struct set*p,int n)
{
  int i;
  struct set *L;
  p=(struct set*)malloc(sizeof(struct set));
  p->next=NULL;
  for(i=0;i<n;i++)
  {
    L=(struct set*)malloc(sizeof(struct set));
    printf("please input:\n");
    getch();
    scanf("%d",&L->info);
    L->next=p->next;
    p->next=L;
  }
}
void printlist(struct set *p)
{
  struct set *L;
  for(L=p->next;L!=NULL;L=L->next)
  {
    printf("%d",&L->info);
    getch();
  }
}

void addset(struct set *p,struct set *q)
{
  int count=0;
  struct set *k,*m,*n;
  k=p->next;
  m=q->next;
  for(k=p->next;k!=NULL;k=k->next)
  {
    for(m=q->next;m!=NULL;m=m->next)
    if(k->info==m->info)
    { count=1;
      break;
    }
    if(count==0)
    {
    n=(struct set*)malloc(sizeof(struct set));
    n->info=k->info;
    n->next=q->next;
    q->next=n;
    }
  }
}

void main()
{
  int n;
  struct set p,q;
  printf("yuansu geshu;\n");
  getch();
  scanf("%d",&n);
  createlist(&p,n);
  printlist(&p);
  printf("yuansu geshu;\n");
  getch();
  scanf("%d",&n);
  createlist(&q,n);
  printlist(&q);
  addset(&p,&q);
  printlist(&q);
  getch();
}
总是感觉printlist这个函数有错误,,求达人解析。。不胜感激
搜索更多相关主题的帖子: 运算 
2009-10-24 10:29
dengjun000
Rank: 2
等 级:论坛游民
帖 子:66
专家分:77
注 册:2009-10-14
收藏
得分:0 
我错了。。 printf("%d",&L->info);这里竟然加了&。汗
2009-10-24 10:32
m456m654
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:3
帖 子:783
专家分:2806
注 册:2009-9-17
收藏
得分:20 
自己动手,丰衣足食
2009-10-24 11:06
快速回复:集合的并运算。帮下忙
数据加载中...
 
   



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

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