主题:求助那里有错误
//约瑟夫环程序
#include"stdio.h"
#include"stdlib.h"
typedef struct Node
{
int data;
int password;
struct Node *next;
}Node, *LinkList;
void CreateList(LinkList &L,int n)
{Node *p,*q;
p=(LinkList)malloc(sizeof(Node));
p=(*L);
p->data=1;
p->password=GetPassword();
for(i=2;i<=n;i++)
{q=(LinkList)malloc(sizeof(Node));
if(!q)
printf("error");
p->password=GetPassword();
q->data=i;
p->next=q;
p=q;
}
p->next=(*L);
}
void GetPassword()
{
int password;
int count=1;
printf("\n请输入第%d的密码:",count);
scanf("%d",&password);
count++;
return password();
}
void josephus(LinkList &L,int n,int m,int array[])
{
Node *p,*Q;
int count,i,j;
count=1;i=0;
p=(*L);
while(n)
{ while(count!=m)
{ q=p;
p=p->next;
count++;
}
array[i++]=p->data;
m=p->password;
q->next=p->next;
free(p);
q=p->next;
count=1;
n--;
}
for(j=0,j<=n;j++)
printf("%-3d\n",array[i]);
}
void main()
{
LinkList L=NULL;
int n,password,m;
printf("请输入围圈人数:\n");
scanf("%d\n",&n);
printf("请输入第一个报数上限值:\n");
scanf("%d"&m);
CreateList(L,n);
GetPassword()
printf("\n出队的顺序为:");
josephus(LinkList &L,int n,int m,int array[])
}
#include"stdio.h"
#include"stdlib.h"
typedef struct Node
{
int data;
int password;
struct Node *next;
}Node, *LinkList;
void CreateList(LinkList &L,int n)
{Node *p,*q;
p=(LinkList)malloc(sizeof(Node));
p=(*L);
p->data=1;
p->password=GetPassword();
for(i=2;i<=n;i++)
{q=(LinkList)malloc(sizeof(Node));
if(!q)
printf("error");
p->password=GetPassword();
q->data=i;
p->next=q;
p=q;
}
p->next=(*L);
}
void GetPassword()
{
int password;
int count=1;
printf("\n请输入第%d的密码:",count);
scanf("%d",&password);
count++;
return password();
}
void josephus(LinkList &L,int n,int m,int array[])
{
Node *p,*Q;
int count,i,j;
count=1;i=0;
p=(*L);
while(n)
{ while(count!=m)
{ q=p;
p=p->next;
count++;
}
array[i++]=p->data;
m=p->password;
q->next=p->next;
free(p);
q=p->next;
count=1;
n--;
}
for(j=0,j<=n;j++)
printf("%-3d\n",array[i]);
}
void main()
{
LinkList L=NULL;
int n,password,m;
printf("请输入围圈人数:\n");
scanf("%d\n",&n);
printf("请输入第一个报数上限值:\n");
scanf("%d"&m);
CreateList(L,n);
GetPassword()
printf("\n出队的顺序为:");
josephus(LinkList &L,int n,int m,int array[])
}