#include<iostream>
using namespace std;
typedef struct LNode
{
int number;
int password;
struct LNode *next;
}LNode,*LinkList;
void CreateList(LinkList &L)
{
int n,i;
LinkList p,q,first;
first=new LNode;
p=new LNode;
first=p;
cout<<"输入总人数为:"<<endl;
cin>>n;
cout<<"依次输入"<<n<<"个人的密码:"<<endl;
for(i=0;i<n;i++)
{
q=new LNode;
p->next =q;
q->number=i+1;
cin>>q->password;
p=q;
}
p->next =first;
}
int LengthList(LinkList L)
{
LinkList p;
p=L->next;
int i=0;
while(p->next!=L)
{
i++;
p=p->next;
}
return i;
}
void DeleteList(LinkList &L)
{
int m,i,n=0,k;
LinkList p;
cout<<"请输入初始报数上限值:"<<endl;
cin>>m;
k=LengthList(L);
cout<<k;
while(k!=0)
{
for(i=n+1;i<=m;i++)
{
p=new LNode;
p->number=m%k;
if(p->number==0)
p->number=k;
n=p->number;
k--;
cout<<"出列的顺序序号为:"<<n<<" ";
m=p->password;
delete p;
}
}
}
int main()
{
LinkList L;
CreateList(L);
DeleteList(L);
return 0;
}
顾安益之我的滨海路
相关分类