#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
typedef struct LNode
{
int password;
int number;
struct LNode *next;
}LNode,*LinkList;
LinkList create(int num[],int pas[],int length)
{
LinkList p1,p2,head;
p1=(struct LNode*)malloc(sizeof(LNode));
p1->number=num[0];
p1->password=pas[0];
for(int i=1;i<=length;i++)
{
if(i==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct LNode*)malloc(sizeof(LNode));
p1->number=num[i];
p1->password=pas[i];
}
p2->next=head;
return head;
}
void print(LinkList head)
{
LinkList p=head;
for(int i = 0;i<7;i++)
{
printf("%d,%d\n",p->number,p->password);
p = p->next;
}
}
void yuesefu(LinkList head,int m)
{
LinkList p=head,q;
q=(struct LNode*)malloc(sizeof(LNode));
int time=m;
while(p->next!=p)
{
for(int i=0;i<time-2;i++)
{
p=p->next;
}
cout<<p->next->number<<" ";
time=p->next->password+1;
q=p->next;
p->next=q->next;
}
cout<<p->number;
}
int main()
{
int num[]={1,2,3,4,5,6,7},pas[]={3,1,7,2,4,8,4};
LinkList head;
head=create(num,pas,7);
print(head);
cout<<endl;
yuesefu(head,20);
return 0;
}