⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 数据结构课程设计
💻 CPP
字号:
#include"stdafx.h"
#include <stdio.h>
#include <stdlib.h>

typedef struct Poeple
{int num;       //每个人的编号
 int pwd;        //每人所持密码
 struct Poeple *next; //指向下一个人的指针
}Poeple,*Linklist;

Linklist p,p1;

//声明函数
struct Poeple *creat(int n);//建立单循环链表
void output(struct Poeple *L,int m,int n);//求出列顺序


//定义函数
struct Poeple *creat(int n)//定义函数建立单循环链表
{struct Poeple *L;
int i;
L=(Linklist)malloc(sizeof(Poeple));// 开辟空间
p=L;
p->num=1;
printf("请输入各人的密码:\n");
printf("请输入编号为1的人的密码:");
scanf("%d",&p->pwd);
for(i=2;i<=n;i++)
{p1=(Linklist)malloc(sizeof(Poeple));
 p->next=p1;
 p1->num=i;
 printf("请输入第 %d 个人的密码:",i);
 scanf("%d",&p1->pwd);
 p=p1;
}
p->next=L;
return L;
}



void output(struct Poeple *L,int m,int n)//定义函数,求出列顺序
{int c;
int  t;
Linklist q=L;
Linklist pt;
c=n;
printf("输出编号:");
while(c>1)
{
	t=1;
	while(t<m)
	{
		
		q=q->next;
        p=p->next;
		t++;
	}
	printf("%d\t",q->num);
	m=q->pwd;
	c--;
	p->next=q->next;
	pt=q;
	q=q->next;
	free(pt);
}
printf("%d\n",p->num);

}



int  inputcommand()
{
	int c;
	printf("\n输入命令:(1--执行, 其它--退出)\n");
	scanf("%d",&c);
	return  c;
}

void  interpret()
{
	int  m, n;
    Linklist L;
	
		printf("请输入报数上限值m:\n");
        scanf("%d",&m);
        printf("请输入总人数n:");
        scanf("%d",&n);
        L=creat(n);
        output(L,m,n);
		
	
}

main()
{

	int  c;
	printf("学院:计算机学院\t  专业班级:网络工程2班\n");
	printf("姓名:黎灶群\t\t    学号:200208024214\n");
	c=inputcommand();
	while(c==1)
	{
		interpret();
		c=inputcommand();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -