编译成功,运行不成功,大家帮忙看看错在哪(约瑟夫环)
#include<iostream.h>#include<math.h>
#include<malloc.h>
#include<stdio.h>
typedef struct link{
int num;
int cod;
struct link *next;
}node,*linklist;
int main()
{
linklist link_make(int );
void construct_input_cod(linklist ,int );
void deal_with_link(linklist ,int );
linklist beg;
int all;
cout<<"请输入一共有多少人:";
cin>>all;
beg=link_make(all);//创建
construct_input_cod(beg,all);//编辑密码
int m;
cout<<"请输入初始密码:";
cin>>m;
deal_with_link(beg, m);//处理
getchar();
}
linklist link_make(int t)/*创建链表*/
{
linklist L;
node *s,*r;
int m=1;
if((L=(linklist)malloc(sizeof(node)))==0)
{
cout<<"无法分配内存!";
return 0;
}
L->num=m;
m++;
r=L;
while(m<=t)
{
if((s=(linklist)malloc(sizeof(node)))=0)
{
cout<<"无法分配内存!";
return 0;
}
s->num=m;
r->next=s;
r=s;
m++;
}
r->next=L;
return L;
}
void construct_input_cod(linklist L,int t)/*输入密码*/
{
node *r;
int s;
r=L;
for(int i=1;i<=t;i++)
{
cout<<"请输入第"<<i<<"个节点的密码:";
cin>>s;
r->cod=s;
r=r->next;
}
}
void deal_with_link(linklist L,int m)/*处理链表*/
{
node *s,*r;
r=L;
int q=m;
while(r->next!=r)
{
for(int i=1;i<q;i++)
r=r->next;
s=r;
q=r->cod;
cout<<r->num<<"号出列;"<<endl;
r=r->next;
free(s);
}
}