循环报数问题
来源:互联网 发布:淘宝客户信誉度怎么看 编辑:程序博客网 时间:2024/05/20 11:24
#include "stdafx.h"#include "stdlib.h"typedef struct _node{int data;struct _node *next;}node;void create(node *&head, node *&tail, int n){if (n < 1){head = NULL;return;}head = (node *)malloc(sizeof(node));head->data = 1;head->next = NULL;node *p = head;for (int i = 2; i < n+1; i++){p->next = (node *)malloc(sizeof(node));p = p->next;p->data = i;p->next = NULL;}tail = p;tail->next = head;}void print(node *head){node *p = head;while (p && (p->next != head)){printf("%d ", p->data);p = p->next;}if (p)printf("%d\n", p->data);}void count_print(node *&head,node *&tail,int m){int cnt = m - 1;node * cur = head;node * pre = tail;while (cur && cur != cur->next){if (cnt){cnt--;pre = cur;cur = cur->next;}else{pre->next = cur->next;printf("%d ", cur->data);free(cur);cur = pre->next;cnt = m - 1;}}if (cur){printf("the last num is %d\n", cur->data);free(cur);head = tail = NULL;}}int _tmain(int argc, _TCHAR* argv[]){node *head = NULL;node *tail = NULL;int n,m;scanf_s("%d", &n);scanf_s("%d", &m);create(head,tail,n);print(head);count_print(head, tail,m);return 0;}
0 0
- 循环报数问题
- 循环删除报数问题
- 循环报数问题
- 约瑟夫循环报数问题
- [蓝桥杯][java]循环报数问题
- n个人循环报数1-3问题
- n个人循环报数1-3问题
- 循环报数
- 循环报数
- 循环报数
- 软件开发笔试心得一:循环报数,圆圈报数,约瑟夫问题
- poj 3750 小孩报数问题(循环链表)
- 循环链表解决Josephus环轮流报数问题
- 循环列表解决n个人首位相连报数问题
- 北京大学ACM---poj3750---小孩报数问题(循环链表求解法)
- 用循环链表解决报数淘汰问题
- 用C++Vector和Queue解决循环报数淘汰问题
- 报数问题
- 画DBGRID,DBGRIDEH中文帐簿金额栏
- POJ 2752 Seek the Name, Seek the Fame
- 拓扑排序(栈)——POJ 1094
- hdu 4893 Wow! Such Sequence!
- [Linux]scp 命令远程复制
- 循环报数问题
- 一步一步教你怎样给Apache Spark贡献代码
- Button cannot be resolved to a type报错
- Mmap的实现原理和应用
- 单调递增子序列
- JAVA获取MAC地址的方法
- hadoop常用命令
- C#快速排序算法
- Python框架、库和软件资源大全(整理篇)