链表—约瑟夫环
来源:互联网 发布:photoshop cc mac破解 编辑:程序博客网 时间:2024/05/22 03:38
#include <stdio.h>#include <stdlib.h>typedef struct node{ int num; struct node* next;}NODE,*PNODE;PNODE creat_(int n){ PNODE head,p,q; int num_=1; head=(PNODE)malloc(sizeof(NODE)); head->next=NULL; q=head; head->num=num_; n--; while(n--) { p=(PNODE)malloc(sizeof(NODE)); num_=num_+1; p->num=num_; q->next=p; q=p; } q->next=head; return head;}void adjust(PNODE head,int n,int m){ int i=1; int t=0; PNODE q,p; q=head; if(m==1) { while(n--) { printf("%d ",q->num); q=q->next; } printf("\n"); } else { while(t<n*m) { t++; if(i==(m-1)) { p=q->next; q->next=p->next; printf("%d",p->num); printf(" "); i=0; } else { q=q->next; i++; } } printf("\n"); }}int main(){ int i,p; PNODE head; while(scanf("%d",&i)!=EOF) { head=creat_(i); scanf("%d",&p); adjust(head,i,p); } return 0;}
0 0
- 链表—约瑟夫环
- 约瑟夫环问题——链表
- 约瑟夫环(链表)
- 链表--约瑟夫环
- 约瑟夫问题、约瑟夫环
- [链表]约瑟夫环问题 Josephus
- 随手小代码——约瑟夫出圈问题/约瑟夫环
- 约瑟夫环——POJ3379
- 【约瑟夫环—数学策略】
- 约瑟夫环—华为试题
- 计蒜客 数据结构 链表——约瑟夫环 C++
- 题解报告——约瑟夫环(链表)
- 约瑟夫-链表
- 约瑟夫环
- 约瑟夫环
- 约瑟夫环
- 约瑟夫环
- 约瑟夫环
- poj1039 Pipe
- linux重启tomcat 小脚本
- 剑指Offer_46_孩子们的游戏(圆圈中最后剩下的数)
- 简单的轮播图代码
- 【Linux开发】【Qt开发】arm-linux-gnueabihf-gdb versus gdb-multiarch
- 链表—约瑟夫环
- Activiti工作流引擎使用
- Jakob Jenkov多线程系列一一Java Volatile Keyword
- tarjan+缩点
- C++STL之string
- HDU1599:find the mincost route
- Redis实战经验及使用场景
- 蓝桥杯试题“饮料换购”和“猜字母”用数学方法
- JS 中 this 的概念