归纳编程学习的感悟,
记录奋斗路上的点滴,
希望能帮到一样刻苦的你!
如有不足欢迎指正!
共同学习交流!
🌎欢迎各位→点赞 👍+ 收藏⭐ + 留言📝
每一个裂缝都是为透出光而努力!
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<malloc.h>
typedef struct CLNode
{
int data;
struct CLNode* next;
}CLNode,*CLinkList;
int main()
{
int n, k, m;
scanf("%d%d%d", &n, &k, &m);
CLinkList head = NULL;
CLNode* pre = NULL, * p = NULL;
for (int i = 1; i <= n; i++)
{
p = (CLNode*)malloc(sizeof(CLNode));
p->data = i;
if (head == NULL)
{
head = p;
}
else
{
pre->next = p;
}
pre = p;
}
p->next = head;
p = head;
for (int i = 1; i < k; i++)
{
pre = p;
p = p->next;
}
while (p->next != p)
{
for (int i = 1; i < m; i++)
{
pre = p;
p = p->next;
}
pre->next = p->next;
printf("被删除的元素:%d\n", p->data);
free(p);
p = pre->next;
}
printf("最后剩下元素:%d\n", p->data);
return 0;
}