查错
是约瑟夫(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