猴子选大王程序

来源:互联网 发布:androidgson解析json 编辑:程序博客网 时间:2024/04/30 04:42
void monkey(int m,int n)//猴子选大王,循环链表{int cnt=0;Node * p=(Node*)malloc(sizeof(Node));Node * temp=p;Node * q;for(cnt=1;cntnum=cnt;printf("==>%d",p->num);if(cnt==n)p->next=temp;else p->next=(Node*)malloc(sizeof(Node));p=p->next;}p=temp;printf("/n");while(p->next!=p)//选猴子{for(cnt=0;cntnext;p->next=p->next->next;showlink(p);//wrong poing showlink和monkey的先后顺序p=p->next;}printf("%d/n",p->num);q=p;p=p->next;while(p!=q)//释放堆{temp=p->next;//wrong point 释放顺序free(p);p=temp;}free(q);p=NULL;q=NULL;}