| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 414 人关注过本帖
标题:这个程序怎么修改哈~请高手指教!
只看楼主 加入收藏
猴子唱歌
Rank: 2
来 自:徐州
等 级:论坛游民
帖 子:5
专家分:10
注 册:2010-7-15
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
这个程序怎么修改哈~请高手指教!
M1_13.rar (959 Bytes)
搜索更多相关主题的帖子: 指教 
2010-07-27 21:00
猴子唱歌
Rank: 2
来 自:徐州
等 级:论坛游民
帖 子:5
专家分:10
注 册:2010-7-15
收藏
得分:0 
程序我做了注释,运行有两处错误,但不知怎么改...劳驾大伙看看哈~~
2010-07-27 21:02
Justfeeling
Rank: 2
等 级:论坛游民
帖 子:26
专家分:47
注 册:2010-2-15
收藏
得分:0 
程序代码:
#include <stdio.h>
#include <stdlib.h>
struct node
{int d;

 struct node *next;};
struct node *create(void)    /*开辟一个8结点的单向链表*/
{ struct node *head=NULL,*p,*q=NULL;
  int i;
  for(i=3;i<=10;i++)
   {p=(struct node *)malloc(sizeof(struct node));
    p->d=i;p->next=NULL;
    if(head==NULL) head=p;
    else q->next=p;
    q=p;
   }

 return head;
}
void print(struct node *head)         /*打印链表*/
{if(head==NULL) return;

 while(head->next!=NULL)
  {printf("%d",head->d);head=head->next;}
   printf("%d\n",head->d);
  }
struct node *delst(struct node *head,int *n)

 {int count=0;struct node *p,*q,*r;
  p=r=head;
  while(p!=NULL)   /*p指向的结点后移*/
   {q=p->next;
    while(q!=NULL)         /*若q指向的结点值是p指向的结点值的整    */
     {if((q->d)%(p->d)==0)     /*  数倍,去掉q指向的结点,否则q后移一个结点*/
      {r->next=q->next; free(q);count++;q=r->next;}
      else{r=q;q=q->next;
     }
    p=p->next;
   }
  *n=count;return head;
}
void main()
{int y;struct node *head;

 head=create();

 print(head);

 head=delst(head,&y);

 print(head);

 printf("%d",y);
}
把源程序红色部分改成  if((q->d)%(p->d)==0)   
我在TC调试success
2010-07-27 22:39
Justfeeling
Rank: 2
等 级:论坛游民
帖 子:26
专家分:47
注 册:2010-2-15
收藏
得分:20 
程序代码:
#include <stdio.h>
#include <stdlib.h>
struct node
{int d;
struct node *next;};
struct node *create(void)    /*开辟一个8结点的单向链表*/
{ struct node *head=NULL,*p,*q=NULL;
  int i;
  for(i=3;i<=10;i++)
   {p=(struct node *)malloc(sizeof(struct node));
    p->d=i;p->next=NULL;
    if(head==NULL) head=p;
    else q->next=p;
    q=p;
   }
return head;
}
void print(struct node *head)         /*打印链表*/
{if(head==NULL) return;
while(head->next!=NULL)
  {printf("%d",head->d);head=head->next;}
   printf("%d\n",head->d);
  }
struct node *delst(struct node *head,int *n)
{int count=0;struct node *p,*q,*r;
  p=r=head;
  while(p!=NULL)   /*p指向的结点后移*/
   {q=p->next;
    while(q!=NULL)         /*若q指向的结点值是p指向的结点值的整    */
    if((q->d)%(p->d)==0)     /*  数倍,去掉q指向的结点,否则q后移一个结点*//*这里去掉了一个{*/
      {r->next=q->next; free(q);count++;q=r->next;}
      else{r=q;q=q->next;
     }
    p=p->next;
   }
  *n=count;return head;
}
void main()
{int y;struct node *head;
head=create();
print(head);
head=delst(head,&y);
print(head);
printf("%d",y);
}
2010-07-27 22:43
无悔爱白修
Rank: 2
等 级:论坛游民
帖 子:28
专家分:27
注 册:2010-3-24
收藏
得分:0 
我用VS2005运行的。
我运行了没有问题啊。
2010-07-27 23:16
快速回复:这个程序怎么修改哈~请高手指教!
数据加载中...
 
   



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

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