我写了个约瑟夫环的算法,结果编译的时候漏洞百出,求大哥们帮忙看下
#include<iostream>using namespace std;
#include<malloc.h>
/*#define LEN sizeof(struct Node) */
Typedef struct Node
{
int data;
struct Node *next;
} *Pointer;
void CreateList(Pointer &Node,int k)
Pointer Find(Pointer &Node,int n)
void Input(m,n,k)
int main()
{
int m,n,k;
new Node Joseph;
void Input(m,n,k);
void CreateList(Joseph &head,int m);
int h=0,j=0,o=0;
new Node start=Find(Joseph &head ,int n);
p=(struct people *) malloc(LEN);
if (k==0)
{
printf("输入错误,重新输入\n");
void Input(m,n,k);
}
else if(k==1)
{
printf("出队顺序为:\n")
for(n=n+1;n<=k;n++) {printf("%d\t",n);}
for(int i=1;i<=n;i++) {printf("%d\t",j);]
}
else
while (o<m+1)
{
while (j<k)
{
if(h==n-1)
{
printf("出队顺序为n")
printf("%d\t",start->start->data);
new Node Temp=start->next;
start->next=start->next->next;
delete(Temp);
h=1;o++;
}
else {start=start->next;h++;}
j++;
}
start=head;h++;
}
return 0;
}
void Input(int m,int n,int k)
{
printf("输入玩家数\n");
scanf("%d",&m);
printf("从第几个人开始\n");
scanf("%d",&n);
printf("第几个人出队\n");
scanf("%d",&k);
}
void CreateList(Joseph &head,int m)
{
head=new Node; p=head; int j;
for(j=1;j<m;j++)
{
q=new Node;
q->data=j;
p->next=q;
p=q;
}
}
Pointer Find(Joseph &head,int n)
{
p=head; j=1;
while ((p->next)&&(j<n))
{ p=p->next; j++; }
if(n==j) reture p;
else reture(NULL);
}
看数据结构的类C写的,错了很多,请大哥们帮忙看看