/*
* @鎻忚堪:
* @鐗堟湰:
* @浣滆€?
* @Date: 2022-03-12 09:28:13
* @LastEditors: Please set LastEditors
* @LastEditTime: 2022-03-12 09:59:18
*/
#include<stdio.h>
#include<stdlib.h>
typedef struct Queue
{
int data;
struct Queue *next;
}Queue,* LinkQueue;
Queue *InitQueue()
{
int i ,n ;
Queue *rear,*que,*tmp;
printf("please input value n :");
que = NULL;
scanf("%d",&n);
for(i = 0 ; i < n ; i++)
{
printf("please input value %d :",i);
tmp = (LinkQueue)malloc(sizeof(Queue));
tmp->next = NULL;
scanf("%d",&tmp->data);
if(que == NULL)
{
que = tmp;
}
else
{
rear->next = tmp;//闃熷熬鎻掑叆
}
rear = tmp;
}
rear->next = que ;
return que;
}
void joseph(Queue *queue)
{
int m ,i=1;
printf("please input m and m < n");
scanf("%d",&m);
while(queue->next != queue)
{
i++;
if( i == m)
{
printf("out line is %d",queue->next->data);
queue->next = queue->next->next;
i=1;
}
queue = queue->next;
}
}
int main()
{
Queue *que = InitQueue();
joseph(que);
return 0;
}
运行结果: