⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 text1.cpp

📁 帮助学生练习和解决JesephRing问题
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
	int number;
	int cipher;
} DataType;
#include "SCLinList.h"

void SCLLDeleteAfter(SCLNode *p)
{
	SCLNode *q=p->next;
	p->next=p->next->next;
	free(q);
}

void JesephRing(SCLNode *head,int m)
{
	SCLNode *pre,*curr;
	int i;

	pre=head;
	curr=head->next;
	while (SCLLNotEmpty (head)==1)
	{
		for (i=1;i<m;i++)
		{
			pre=curr;
			curr=curr->next;
			if (curr==head)
			{
				pre=curr;
				curr=curr->next;
			}
		}

		printf("%d  ",curr->data.number);
		m=curr->data.cipher;
		curr=curr->next;
		if(curr==head)
			curr=curr->next;

		SCLLDeleteAfter(pre);
	}
}
void main()
{
	DataType test[7]={{1,3},{2,1},{3,7},{4,2},{5,4},{6,8},{7,4}};
	int n=7,m=20,i;
	SCLNode *head;

	SCLLInitiate(&head);
	for(i=1;i<=n;i++)
		SCLLInsert(head,i,test[i-1]);

	JesephRing(head,m);
	printf("\n");
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -