/*
Name: 约瑟夫环
Author:wujilin
Description:
Date: 11-09-06 20:22
Copyright:
*/
#include"stdio.h"
#include"stdlib.h"
#define MAXPASSWORDVALUE 20
#define MAXPERSONNUMBER 30
#define MAXFIRSTCOUNTVALUE 10
#define MAXPASSWORD 10
typedef struct Node
{
int data;
int password;
struct Node *next;
}Node, *LinkList;
////////////////////////////////////////////////
/////函数的声明
////////////////////////////////////////////////
void CreatLinkList(LinkList *);
void InitLinkList(LinkList *,int );
int GetPassword();
int GetPersonNumber();
int GetPersonNumber();
int GetFirstCountValue();
void GetOutputOrder(LinkList* , int, int, int* );
void printResult(int * ,int );
void CreatLinkList(LinkList *L)//构建单链表
{
(*L) = (LinkList)malloc(sizeof(Node));
if ((*L) == NULL)
{
printf("memory allocation failed, goodbye");
exit(1);
}
}
void InitLinkList(LinkList *L, int personNumber)//初始化单链表
{
Node *p, *q;
int i ;
p = (*L);
p->data = 1;
p->password = GetPassword();
for (i = 2; i <= personNumber; i++)
{
q = (LinkList)malloc(sizeof(Node));
if (q == NULL)
{
printf("memory allocation failed, goodbye");
exit(1);
}
q->password = GetPassword();
q->data = i;
p->next = q;
p = q;
}
p->next = (*L);
}
int GetPassword()//给每个人赋密码
{
int password;
static int count = 1;
printf("\n请输入第%d的密码:",count);
scanf("%d",&password);
while (password > MAXPASSWORDVALUE || password < 0)
{
printf("您输入的数字无效,请输入在0到%d的整数:",MAXPASSWORD);
scanf("%d",&password);
}
printf("第%d个人的密码为%d",count,password);
count++;
return password;
}