各位高手帮帮忙
晚辈在调试一个小程序joseph环时,怎么程序已经编译通过但总已运行就被关了请教各位高手帮个忙
程序如下
#include <stdio.h>
#include<stdlib.h>
#include<iostream.h>
struct Node {int no;
int password;
struct Node *next;
}Node;
typedef struct Node* Lnode;
int Fill_thelist(int n,int password[],Lnode &head)
{int i;
Lnode p,q;
head=p=(Lnode)malloc(sizeof(struct Node));
if(!p) return 0;
for(i=1;i<=n;i++)
{p->no=i;
p->password=password[i-1];
q=(Lnode)malloc(sizeof(struct Node));
if(!q)return 0;
p->next=q;
p=q;
}
p->next=head;
return 1;
}
int main(int argc,char *argv[])
{
Lnode head,p,q;
int i,m,n,s;
int password[30];
m=atoi( argv[2] );
n=atoi( argv[1] );
for(i=1;1<=n;i++)
password[i-1]=atoi( argv[i+1] );
Fill_thelist(n,password,head);
p=head;
for(i=1;i<m%n;i++)
{p=p->next;}
s=p->password;
while (p!=p->next)
{
for(i=1;i<s;i++)
{q=p;p=p->next;}
q->next=p->next;
p->next=NULL;
s=p->password;
cout<<p->no<<endl;
free(p);
p=q->next;
}
cout<<p->no<<endl;
head=NULL;
free(p);
return 0;
}