解题思路:
分享一个链表
注意事项:
参考代码:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int no;
struct node*next;
};
int main()
{
int i,k;struct node*head,*p,*q;
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
head=(struct node*)malloc(sizeof(struct node));
head->no=-1;
head->next=head;
for(i=n;i>0;i--) //生成循环链表
{
p=(struct node*)malloc(sizeof(struct node));
p->next=head->next;p->no=i;head->next=p;
}
printf("\nThe original circle is :");
while(p->next!=head) //找到表头节点 并跳过表头节点
p=p->next;
p->next=head->next; //节点删除操做 *p->30
for(i=0;i<n-1;i++)
{
for(k=1;k<m;k++)
p=p->next;
q=p->next; //p的下一个节点是要出列的节点
p->next=q->next; //循环链表跳过要出列的节点
// printf("%3d",q->no); //输出q节点的编号
free(q); //释放q节点
}
printf("\n%d",p->no);
}
printf("\n");
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题9.1 (C语言代码)浏览:681 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)from DQM浏览:670 |
字符逆序 (C语言代码)浏览:615 |
核桃的数量 (C语言代码)浏览:872 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:470 |
简单的a+b (C语言代码)浏览:587 |
10月月赛题解浏览:536 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:713 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:445 |
字符串的修改 (C语言代码)浏览:1143 |