约瑟夫环的问题 好的,谢谢[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //数据结构实习1.2,Joseph#include <stdlib.h>#include <stdio.h>#include <iostream.h>typedef struct LNode{ //定义数据结构 int Sequential; int SecretCode; struct LNode *next;}LNode,*LinkList; void CreateList(LinkList &L,int n){ //创造链表 L=(LinkList)malloc(sizeof(LNode)); L->next=L; L->Sequential=1; for(int i=n;i>1;i--){ LNode *p=(LinkList)malloc(sizeof(LNode)); p->Sequential=i; p->next=L->next;L->next=p; }}//CreateListvoid InputSecretCode(LinkList &L,int n){ //依次输入每个人的密码 LNode *p=L; printf("please input secret code"); for(int i=0;i<n;i++) {scanf("%d",&p->SecretCode); p=p->next;}}//InputSecretCodevoid Prior(LinkList L,LNode *p,LNode *&q){ //已知链表L,指向结点的指针p,使q指向p的前趋 while (q->next!=p) q=q->next;}//Priorvoid OutOfRank(LinkList &L,int &m,int n){ //报数,最后报的人出列,显示出列人的序号 LNode *p=L;LNode *q=L; for(int i=0;i<n;i++){ for(int j=1;j<m;j++)p=p->next; Prior(L,p,q); cout << p->Sequential; m=p->SecretCode; q->next=p->next; free(p); p=q->next; } }//OutOfRankvoid main(){ int n; printf("please input people number");cin >> n; int m; printf("please input m"); scanf("%d",&m); LinkList L; CreateList(L,n); InputSecretCode(L,n); OutOfRank(L,m,n);}//main 源码分享-自制植物大战僵尸 文件操作 异常?? 小弟最近遇到的面试题,希望大侠给解答一下 问问 !及此事可不可以用java二次开发AutoCAD 如何用javac编译一个文件夹下的所有*.java文件呢? 如何得到TimeStamp型的现在时刻。。 JTree中怎样才可以选中指定的结点 定义字符数组的简单问题,请进来看看 选择什么样的java编译器? (在线等回答)对象定义的问题 在JTextPane中Paragraph的概念是什么? 谁有封装好的导航条赠送或者源代码下载地址?
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>typedef struct LNode{
//定义数据结构
int Sequential;
int SecretCode;
struct LNode *next;
}LNode,*LinkList;
void CreateList(LinkList &L,int n){
//创造链表
L=(LinkList)malloc(sizeof(LNode));
L->next=L;
L->Sequential=1;
for(int i=n;i>1;i--){
LNode *p=(LinkList)malloc(sizeof(LNode));
p->Sequential=i;
p->next=L->next;L->next=p;
}
}//CreateList
void InputSecretCode(LinkList &L,int n){
//依次输入每个人的密码
LNode *p=L;
printf("please input secret code");
for(int i=0;i<n;i++)
{scanf("%d",&p->SecretCode); p=p->next;}
}//InputSecretCode
void Prior(LinkList L,LNode *p,LNode *&q){
//已知链表L,指向结点的指针p,使q指向p的前趋
while (q->next!=p) q=q->next;
}//Prior
void OutOfRank(LinkList &L,int &m,int n){
//报数,最后报的人出列,显示出列人的序号
LNode *p=L;LNode *q=L;
for(int i=0;i<n;i++){
for(int j=1;j<m;j++)p=p->next;
Prior(L,p,q);
cout << p->Sequential; m=p->SecretCode;
q->next=p->next;
free(p);
p=q->next;
}
}//OutOfRank
void main(){
int n;
printf("please input people number");cin >> n;
int m;
printf("please input m");
scanf("%d",&m);
LinkList L;
CreateList(L,n);
InputSecretCode(L,n);
OutOfRank(L,m,n);
}//main