1
程序源代码:
#include
#include
#include
#include
#include
#define NULL 0
typedefstruct Node
{
int m;//
密码
int n;//
序号
struct Node *next;
}Node,*Linklist;
Linklist create(int z) //
生成循环单链表并返回
,z
为总人数
{
inti,mm;
LinklistH,r,s;
H=NULL;
printf("
请按顺序依次为每个人添加密码:
");
for(i=1;i<=z;i++)
{
printf("\ninput cipher=");
scanf("%d",&mm);
s=(Linklist)malloc(sizeof(Node));
s->n=i;
s->m=mm;
printf("%d
号的密码
%d",i,s->m);
if(H==NULL)//
从链表的第一个节点插入
{
H=s;
r=H;
}
else//
链表的其余节点插入
{
r->next=s;
r=s;//r
后移
}//for
结束
r->next=H;/*
生成循环单链表
*/
return H;
}