约瑟夫环c语言代码原创
#include
#include
struct peolist int n;
int secret;
struct peolist *next;
;
struct outlist int num;
struct outlist *next;
;
struct peolist *creat1 int i 1;
struct peolist *head;
struct peolist *p1,*p2;
printf "依次输入个人的密码,输入非正数时结束\n" ;
p1 p2 struct peolist * malloc sizeof struct peolist ;
scanf "%d",&p1- secret ;
head p1;
p1- n i;
while p1- secret 0 i++;
p2 p1;
p1 struct peolist * malloc sizeof struct peolist ;
scanf "%d",&p1- secret ;
p1- n i;
p2- next p1; p2- next head;
return head; struct outlist *creat2 struct peolist *head int i,m;
struct peolist *p0,*temp;
struct outlist *head1;
struct outlist *p1,*p2;
printf "输入初始m值\n" ;
scanf "%d",&m ;
p1 p2 struct outlist * malloc sizeof struct outlist ;
head1 p1;
p0 head;temp NULL;
while p0- next! p0 i 1;
while i m if i+1 m temp p0; p0 p0- next; i++; p1- num p0- n;
m p0- secret;
p0 p0- next;
temp- next p0;
p2 p1;
p1 struct outlist * malloc sizeof struct outlist ;
p2- next p1; p2 p1;
p2- num p0- n;
p2- next NULL;
return head1; void main struct peolist *head1;
struct outlist *head2,*p;
head1 NULL;head2 NULL;p NULL;
head1 creat1 ;
head2 creat2 head1 ;
p head2;
while p! NULL printf "%d ",p- num ;
p p- next;