解题思路:
注意事项:
参考代码:
#include <stdio.h> #include <stdlib.h> typedef struct no { int id; struct no *next; } N1; N1 *Init(int n); void output(N1 *a, int m); int main() { int n, m; N1 *one; while(scanf("%d%d", &n, &m)!=EOF){ one = Init(n); output(one, m); free(one); } return 0; } N1 *Init(int n) { N1 *a = (N1 *)malloc(sizeof(N1)); N1 *h = a, *p; for (int i = 1; i <= n; i++) { p = (N1 *)malloc(sizeof(N1)); p->id = i; p->next = NULL; h->next = p; h = h->next; p = NULL; } h->next = a->next; return a; } void output(N1 *a, int m) { N1 *h, *p; p = a->next; free(a); do { for (int i = 1; i <= m; i++) { if (i == m) { h->next = p->next; free(p); p = h->next; } else { h = p; p = p->next; } } } while (h->next != h); printf("%d", h->id); free(h); }
0.0分
0 人评分
简单的a+b (C语言代码)浏览:594 |
简单的a+b (C语言代码)浏览:564 |
字符串比较 (C语言代码)答案错误????浏览:641 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:674 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:1292 |
C语言程序设计教程(第三版)课后习题6.6 (C语言代码)浏览:366 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:761 |
关于float,double变量的几点说明浏览:1926 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:627 |
IP判断 (C语言代码)浏览:592 |