#include <bits/stdc++.h>
using namespace std;
typedef struct kid
{
int data;//这个表示的是个人的编好以及在队列里的状态(即在还是不在)
struct kid *next;
}kids;
typedef kids* p;//我写这个是为了同时定义多个结构体指针
p creat(int n)
{
p head,pre;//定义头结点和前驱以及后继指针
head=(p)malloc(sizeof(kids));
head->data=1;
pre=head;//前驱指针指向头结点
for(int i=1;i<=n;i++)
{
kids* last=(p)malloc(sizeof(kids));
last->data=i+1;
pre->next=last;
pre=last;
}
pre->next=head;
return head;
}
p baoshu(p head,int n,int k)
{
p pre;
int count=1;
pre=head;
while(n>1)
{
if(pre->data!=-1)//-1表示退出队列的标志
{
if(count%k==0&&count%10==k)
{
pre->data=-1;//如果符合上述条件,
n--;
}
count++;//计数还得进行下去
}
pre=pre-&
C语言实现报数问题(约瑟夫环)
最新推荐文章于 2023-01-07 19:25:52 发布