#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#define ERROR 0
typedef struct CNode
{
int data;
struct CNode *next;
}CNode,*CycList;
void YSF(int n,int k,int m)
{
CycList head,p,s,p1;
head=(CycList)malloc(sizeof(CNode));
head->data=1;
head->next=head;
p=head;
for (int i=2;i<n+1;i++)
{
s=(CycList)malloc(sizeof(CNode));
s->data=i;
s->next=p->next;
p->next=s;
p=s;
}//此时P指向head的逆时针的下一个元素
while (--k)
{
p1=head;
head=head->next;
}//重新定位头指针
head=p1;
while(n--)
{
for (int s=m;s>0;--s,p1=head,head=head->next);
p1->next=head->next;
printf("%d->",head->data);
free(head);
head=p1;
}
}
void main()
{
YSF(8,3,2);
}
约瑟夫
约瑟夫
最新推荐文章于 2021-07-26 14:41:33 发布