文章
28
粉丝
230
获赞
23
访问
242.5k
#include <stdio.h>
#include <stdlib.h>
typedef struct LNode
{
int Number;
struct LNode * next;
} LNode;
int main(int argc, char const *argv[])
{
int key,N,count,s,m;
LNode *C = (LNode *)malloc(sizeof(LNode));
while(scanf("%d %d %d",&N,&s,&m)!=EOF && m!=0){//猴子总数N
count=1 ;//设count为报数次数
key = 2 ;//用于给每一个元素编号
C->next=NULL;
C->Number = 1 ;
LNode *S=C;
while ((N-1) != 0){//尾插法建表(无头结点)
LNode *p = (LNode *) malloc (sizeof(LNode));
p->Number = key ;
S->next = p ;
S = p ;
key ++;
N--;
}
S->next = C;//使单链表=>循环单链表
LNode *r = C;//设置访问指针r
LNode *pre = r;//pre指针指向r。作r的前驱
while(r->Number != s){r=r->next;}//寻找指定开始节点
while(r ->next != r){//最后一个结点时跳出循环
if (count == m)//传递次数累计m次,进行元素删除
{
printf("%d,",r->Number);
pre->next = r ->next;
r=pre->next ;
count = 1;//重置报数次数count
}else {
pre = r ;
r = r->nex...
登录后发布评论
暂无评论,来抢沙发