您可以在这里快速查找:


 
您的位置: 编程学习 > C++/VC > 200601
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

猫吃老鼠问题

stone1982

#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();
 }