1、通过单向链表实现约瑟夫问题(数三出局),然后数到三就把该节点剔除然后释放掉该节点(基于有头节点的情况下)
2、思路:先初始化一个头节点,让指针域指向自己;输入需要参加的人数,然后新建节点,把数据放入新节点中,再把新节点插入到链表中,每次就插入到链表的末尾,插入完毕后就开始数三出局,每次跳过头节点(必须跳过头节点,不然会将头节点算进来)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
typedef struct node
{
int data;
struct node *next;
}loop_list,*loop_list_p;
loop_list_p init_list();
loop_list_p creat_node(int people);
int insert_list(loop_list_p head,loop_list_p new);
bool list_null(loop_list_p head);
int three_out(loop_list_p head,int num);
void show_list(loop_list_p head);
void free_list(loop_list_p head);
int main(int argc,char **argv)
{
while(1)
{
loop_list_p head = init_list();
printf("please