//n people
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node *next;
}node;
node *create(int n)
{
node *p=NULL,*head;
node *s;
int i=1;
head=(node*)malloc(sizeof(node)*8);
p=head;
if(0 != n)
{
while(i<=n)
{
s=(node *)malloc(sizeof(node*)*8);
s->data = i++;
p->next = s;
p = s;
}
s->next =head->next;//構成鏈表環;
}
free(head);
return s->next;//回傳頭結點
}
int main()
{
int n;
int m;
int i;
scanf("%d",&n);
scanf("%d",&m);
node *p =create(n);
node *temp;
m %=n;
while(p!=p->next)
{
for(i=1;i<m-1;i++)
{
p=p->next;
}
printf("%d->",p->next->data);
temp=p->next;
p->next=temp->next;
free(temp);
p=p->next;
}
printf("%d\n",p->data);
return 0;
}
uj5u.com熱心網友回復:
什么問題沒說啊轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/87255.html
標籤:基礎類
