#include
#include
#define SIZE 10
typedef struct lldata
{
int ID;
int nu;
char name[SIZE];
}Data;
typedef struct llnode
{
Data data;
struct llnode *next;
}lln,*llp;
llp CreateList()
{
llp head,p,new;
int id=0;
head=malloc(sizeof(lln));
if(head==NULL)
{
printf("malloc is fail\n");
return NULL;
}
else
{
Data info;
info.ID=id;
printf("亲输入你的幸运数字:\n");
scanf("%d",&info.nu);
printf("亲输入姓名:\n");
scanf("%s",info.name);
head->data=info;
head->next=head;
p=head;
while(1)
{
id++;
Data info;
info.ID=id;
new = malloc(sizeof(lln));
printf("亲输入你的幸运数字(0->结束):\n");
scanf("%d",&info.nu);
if(info.nu==0)
break;
printf("亲输入姓名:\n");
scanf("%s",info.name);
new->data=info;
p->next=new;
new->next=head;
p=new;
}
}
return head;
}
void SeaDelList(llp head)
{
llp ptr;
ptr=head;
int i=1,m;
while(head->next!=ptr)
head=head->next;
srand(time());
m=rand()%(head->data.ID+1);
while(head->next!=head)
{
if(i==m)
{
ptr=head->next;
printf("ID=%d----密码:%d----姓名:%s\n",ptr->data.ID,ptr->data.nu,ptr->data.name);
m=ptr->data.nu;
head->next=ptr->next;
free(ptr);
i=1;
}
else
{
head=head->next;
i++;
}
}
printf("最后一个活人:\n\tID=%d----nu:%d----name:%s\n",head->data.ID,head->data.nu,head->data.name);
return;
}
int main()
{
llp H;
H=CreateList();
SeaDelList(H);
free(H);
return 0;
}
阅读(950) | 评论(0) | 转发(0) |