Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1498106
  • 博文数量: 329
  • 博客积分: 2773
  • 博客等级: 少校
  • 技术积分: 4219
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 14:17
个人简介

淡定从容,宁静致远

文章分类

全部博文(329)

文章存档

2016年(4)

2015年(50)

2014年(68)

2013年(45)

2012年(162)

分类: C/C++

2012-12-18 21:53:46

#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;
}
阅读(881) | 评论(0) | 转发(0) |
0

上一篇:链表

下一篇:有头单链表学生管理系统

给主人留下些什么吧!~~