#include
typedef struct JNode
{
int Number;
int Cipher;
struct JNode *next;
}JNode;
int createJosephCycle(JNode **la,int n){
JNode *p,*s;int i;
if((*la=(JNode *)malloc(sizeof(JNode)))==NULL){
printf("allocation failed(1)!");return 0;
}
(*la)->next = NULL;
p = (*la);
for(i=0;iCipher);
s->Number = i+1;
p->next = s;
p=s;
}
p->next = (*la)->next;
}
int killOrder(JNode *la, int m){
JNode *p,*s; int j;
p = la; j=0;
while (p->next!=NULL)
{
while(jnext;
j++;
}
if(p->next==p){
printf("%d GAME OVER!",p->Number);
return 0;
}
if(j==m-1){
s = p->next;
p->next = p->next->next;
printf("%d ",s->Number);
j=0;
m = s->Cipher;
}
}
}
main(){
JNode *la;
clrscr();
createJosephCycle(&la,1);
killOrder(la,10);
getch();
}。
全部