约瑟夫环的两种实现方式--数组和循环链表
发布日期:2021-06-29 15:42:37 浏览次数:2 分类:技术文章

本文共 685 字,大约阅读时间需要 2 分钟。

1.数组实现形式

#include
#define LEN 40#define Interval 3int main(){ int R[LEN]; for(int i=0;i
2) { if(R[index]==1) { count++; if(count==Interval) { R[index]=0; count=0; leftcount--; } index++; if(index==LEN) index=0; } } for(int j=0;j

2.循环链表

typedef struct LNode{	int data;	struct LNode *next;}LNode;void create(LNode *&L){	LNode *r,*s;	L=(LNode*)malloc(sizeof(LNode));	r=L;	for(i=1;i<=n;i++)	{		s=(LNode*)malloc(sizeof(LNode));		s->data=i;		r->next=s;		r=s;	}	r->next=L->next;}void  yuesehuan(LNode *L,int m,int n){	LNode *p=L->next;	LNode *temp;	for(int i=1;i
next; temp=p->next; p->next=temp->next;p=temp->next; free(temp); }}

 

转载地址:https://codingchaozhang.blog.csdn.net/article/details/85253742 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:栈的应用之表达式转换
下一篇:回溯法之八皇后问题

发表评论

最新留言

很好
[***.229.124.182]2024年04月25日 17时52分23秒