欢迎访问:常州市武进区嘉泽中心小学网站 !今天是:
栏目列表
您现在的位置是:首页>>教师>>计算机技术>>程序设计>>杂项>>文章内容
猫吃老鼠问题
发布时间:2008-11-20   点击:   来源:本站原创   录入者:佚名
 
#define len sizeof(struct catmouse)
struct catmouse
{int num;
struct catmouse *next;
};
void main()
{struct catmouse *head,*p,*q;
 int n,m,i,j;
 int a[7];
 printf("\nenter the an integer:");
 scanf("%d",&n);
 p=q=(struct catmouse*)malloc(len);
 p->num=1;
 head=p;
 for(i=2;i<=n;i++)      //建立循环链表
  { p=(struct catmouse*)malloc(len);
    p->num=i;
    q->next=p;
    q=p;
  }
  q->next=head;
  p=q=head;           //指向头节点,每个一个节点依次删去吃掉的老鼠
  for(i=0;i<n;i++)
   {
      p=q->next;
      q=p;
      p=q->next;
      q->next=p->next;
      free(p);
    }
   printf("\n最后一个号码是:%d",p->num);   //结果
   getch();
 }
附件:
    关闭窗口
    打印文档
    账号登录
    保持登录 忘记密码?
    账号与武进教师培训平台同步