#include<stdio.h>
#include<stdlib.h>
typedef struct josephnum
{
int num;//1-N连续数字
struct josephnum *front;//前指针
struct josephnum *next;//后针域
}JCN;
void print_help()
{
puts("****************************");
puts("1.创建约瑟夫数字");
puts("2.查看约瑟夫数字");
puts("3.输出约瑟夫环");
puts("4.查看帮助信息");
puts("5.退出系统");
puts("6.清空");
puts("****************************");
}
void link_insert(JCN **head, JCN *p_new)
{
JCN *pb, *pf = *head;
if (*head == NULL)//空链表时
{
*head = p_new;
p_new->next = *head;
p_new->front = *head;
}
else//有一个或以上链表时
{
pb = pf->front;
pb->next = p_new;
p_new->front = pb;
p_new->next = pf;
pf->front = p_new;
}
}
void link_print(JCN *head)
{
JCN *p_mov = head;
if (head == NULL)
{
return;
}
while (p_mov->next != head
约瑟夫环问题:用户输入M,N值,从1至N开始顺序循环数数,每数到M输出该数值,直至全部输出。
最新推荐文章于 2023-05-21 18:39:08 发布