c语言线性表处理约瑟夫环1
发布网友
发布时间:2023-10-16 23:15
我来回答
共2个回答
热心网友
时间:2023-11-09 20:07
#include<stdio.h>
#include<malloc.h>
#define Namelength 10
typedef struct CLNode{
char*name;
int ID;
int pastword;
struct CLNode *next;
}child,*ptrchild;
ptrchild CreateCList(int n)
{int i;
ptrchild p,head,rear;
printf("please input the children information:");
rear=head=(ptrchild)malloc(sizeof(child));
rear->next=head;
for(i=0;i<n;i++)
{getchar();
p=(ptrchild)malloc(sizeof(child));
p->ID=i+1;
p->name=(char*)malloc(Namelength*sizeof(char));
gets(p->name);
scanf("%d",&(p->pastword));
rear->next=p;
rear=p;
}
rear->next=head;
return head;
}
Joshpus(ptrchild head,int m)
{ptrchild p,q;int i=0;
p=head;
while(head->next!=head)
{while(i<m)
{q=p;
p=p->next;
if(p==head){q=head;p=p->next;}
i++;
}
printf("\nID:%d Name:%s",p->ID,p->name);
q->next=p->next;
m=p->pastword;
i=0;
free(p);
p=q;
}
printf("\n");
}
main()
{ptrchild CL;
int n,m;
printf("please input the number of children:");
scanf("%d",&n);
CL=CreateCList(n);
printf("please input the initial value of m:");
scanf("%d",&m);
Joshpus(CL,m);
}
热心网友
时间:2023-11-09 20:07
数组是从0开始计数的,首位是data[0],不是data[1]追问为什么有人这样传参*&L,而且我的数组空间很大,从1到7是不会影响的,我输入的数据从一到7也蹦溃