栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

【无标题】

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【无标题】

typedef struct LNode
{
	elemtype data;
	struct LNode* next;
}linkList;
int joseph(linkList* head, elemtype n, elemtype c, elemtype m)//妈的faker,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
{
	linkList* p = head;
	
	if (c > n || !m)//c 从第几人开始,如果比总人数大 或者m为零退出
	{
		return 0;
	}
	int count = 0;
	for (count = 1; count < c; ++count)
	{
		p = p->next;
	}
	linkList* q = p->next;
	// q p 一前一后, q 在前, p 在后
	int i = 0;
	int j = 0;
	for(i = 1;i < n ;++i)//控制删除
	{
		for(j = 1; j < m; ++j)
		{

			if ((p->next != NULL) && (q->next != NULL))//p q 都不为尾巴
			{
				p = p->next;
				q = q->next;
			}
			 else if (q->next == NULL)//q 是表尾
			{
				p = p->next;
				q = head->next;
				
			}
			 else if(p->next == NULL)//p 是表尾
			{
				p = head->next;
				q = q->next;
			}
		}
		linkList* r;
		if (q->next == NULL) //删除节点 如果q 为表尾
		{
			r = q;
			q = head->next;
			p->next = NULL;
			printf("%d  ", p->data);
			free(r);
			r = NULL;
		}
		else//q 不为表尾
		{
			r = q;//临时指针
			q = q->next;
			if (p->next != NULL)//如果p 为表尾
				p->next = q;
			else//p 不为表尾
				head->next = q;
				printf("%d  ", r->data);
			free(r);
			r = NULL;
		}
	}
	if(head->next != NULL)
	printf("           %d", (head->next)->data);
}
int main()
{
	int count = 0;//开辟空间
	int n = 0;//人数
	int m = 0;//到第几人出局
	int c = 0;//从第几人开始
	linkList* head = (linkList*)malloc(sizeof(struct LNode));
	if (head != NULL)
	{
		head->next = NULL;
	}
	linkList* s;
	int x = 39;
	printf("请输入人数,从第几人开始,循环到第几任出局:");
	scanf_s("%d%d%d", &n, &c, &m);
	linkList* p1 = head;
	for (count = 1; count <= n; ++count)
	{
		s = (linkList*)malloc(sizeof(struct LNode));
		if (s != NULL)
		{
			s->data =  count;
			p1->next = s;
			p1 = s;
		}
	}
	p1->next = NULL;
	
	joseph(head, n, c, m);

	return 0;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/657661.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号