#include<stdio.h>
#include<malloc.h>
struct node
{
int data;
struct node* next;
};
struct node *p,*q,*head,*tail;
void create(int m,int n,struct node* head)
{
if(m<=0||n>m)
{
free(head);
printf("ERROR!");
}
else
{
int i=1;
tail=head;
for(i=1;i<=m;i++)
{
p=(struct node* )malloc(sizeof(struct node));
p->data=i;
tail->next=p;
p->next=head->next;
tail=p;
}
p=p->next;
}
}
int main()
{
int m;
int s,n;
int count=1;
int flag=0;
int i;
printf("请按照形式“m s n”输入链表结点个数、开始节点及循环数:");
scanf("%d %d %d",&m,&s,&n);
head=(struct node* )malloc(sizeof(struct node));
head->data=-1,head->next=NULL;
create(m,s,head);
p=head->next;
q=tail;
for(i=1;i<s;i++)
{
p=p->next;
q=q->next;
}
while(count<=m)
{
for(flag=1;flag<n;flag++)
{
p=p->next;
q=q->next;
}
printf("%d ",p->data);
q->next=q->next->next;
free(p);
p=q->next;
count++;
}
return 0;
}