#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct list
{
int data;
struct list *next;
struct list *pre;
};
/*双向链表的定义*/
typedef struct list node;
typedef node *link;
link front=NULL,rear,ptr,head=NULL;
link push(int item)
{
link newnode=(link)malloc(sizeof(node));
newnode->data=item;
if(head==NULL)
{
head=newnode;
head->next=NULL;
head->pre=NULL;
rear=head;
}
else
{
rear->next=newnode;
newnode->pre=rear;
newnode->next=head;
head->pre=newnode;
rear=newnode;
}
return head;
}
/*链表节点的插入*/
void main()
{
int n,i,m,x=1,y=1,k=1,t,j,out;
FILE *fp;
if((fp=fopen("result.txt","w"))==NULL)
{
printf("Cannot open the file.\n");
exit(0);
}
printf("输入参加小孩的总人数:\n");
scanf("%d",&t);
printf("按顺序输入%2d名小孩的序号.\n输入第个%2d小孩的号码:\n",t,k++);
scanf("%d",&n);
front=push(n);
for(i=0;i<t-1;i++)
{
printf("输入第个%2d小孩的号码:\n",k++);
scanf("%d",&n);
push(n);
}
printf("输入报数值m:\n");
scanf("%d",&m);
ptr=head;
for(i=0;i<t-1;i++)
{
{
for(j=1;j<m;j++)
ptr=ptr->next;
out=ptr->data;
printf("第%2d个被淘汰的是:%2d号选手.\n",x++,out);
ptr->pre->next=ptr->next;
ptr->next->pre=ptr->pre;
/*链表中节点的删除*/
fprintf(fp,"第%2d个被淘汰的是:%2d号选手.\n",y++,out);
}
ptr=ptr->next;
}
printf("最后的胜利者是:%2d号选手.\n",ptr->next->data);
fprintf(fp,"最后的胜利者是:%2d号选手.",ptr->next->data);
}
你自己看看吧 改改就行了