链队列约瑟夫环c++代码_C++编写的 约瑟夫环问题 代码

1

程序源代码:

#include 

#include 

#include

#include 

#include

#define NULL 0

typedefstruct Node

{

int m;//

密码

int n;//

序号

struct Node *next;

}Node,*Linklist;

Linklist create(int z)  //

生成循环单链表并返回

,z

为总人数

{

inti,mm;

LinklistH,r,s;

H=NULL;

printf("

请按顺序依次为每个人添加密码:

");

for(i=1;i<=z;i++)

{

printf("\ninput cipher=");

scanf("%d",&mm);

s=(Linklist)malloc(sizeof(Node));

s->n=i;

s->m=mm;

printf("%d

号的密码

%d",i,s->m);

if(H==NULL)//

从链表的第一个节点插入

{

H=s;

r=H;

}

else//

链表的其余节点插入

{

r->next=s;

r=s;//r

后移

}//for

结束

r->next=H;/*

生成循环单链表

*/

return H;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值