查错

daheixiong 2003-07-02 11:17:24
是约瑟夫(Josephus)环的问题

#define LEN sizeof(struct Josephus)
struct Josephus{
int num;
struct Josephus * next;
};

struct Josephus * creat(int n)
{
struct Josephus * head, * p1, * p2;
int i;

head=p1=p2=(struct Josephus * )malloc(LEN);
p1->num=1;
for (i=0;i<n-1;i++)
{
p1=(struct Josephus * )malloc(LEN);
p1->num=i+2;
p2->next=p1;
p2=p1;
}
p2->next=head;
return (head);
}
int process(struct Josephus * h,int n,int m)/*处理,并调用del()*/
{
int i;
struct Josephus * h1;

i=n;
h1=h;
while (i>1)
{
h1=del(h1,m); /*33行*/
i=i-1;
}
return (h1->num);
}
struct Josephus * del(struct Josephus * h,int m)/*摘除数到的一环*/
{ /*39行*/
int i;
struct Josephus * h1,* p1, * p2;
p1=p2=h1=h;
for (i=0;i<m-1;i++)
{
p1=p2->next;
p2=p1;
}
p1=p2->next;
p1=p1->next;
p2->next=p1;
h1=p1;
return (h1); /*59行*/
}
main()
{
int n,m;
struct Josephus * head;

scanf("%d,%d",&n,&m);
head=creat(n);
printf("\nThe last number is:%d\n",process(head,n,m));
}

错误提示:
Warning A:\10_E_5.C 33: Non-portable pointer assignment in function process
Error A:\10_E_5.C 39: Type mismatch in redeclaration of 'del'
Warning A:\10_E_5.C 52: Non-portable pointer conversion in function del
...全文
41 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zteliubin 2003-07-02
  • 打赏
  • 举报
回复
up!
point_to 2003-07-02
  • 打赏
  • 举报
回复
没什么大错!
只要加个声明就行了,否则不认识del
struct Josephus * del(struct Josephus * h,int m);
int process(struct Josephus * h,int n,int m)/*处理,并调用del()*/
{
int i;
struct Josephus * h1;

i=n;
.......
simouse 2003-07-02
  • 打赏
  • 举报
回复
up

70,031

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧