我写的一些数据结构的算法
密码认证
#include <stdio.h>
password()
{
int i,l;
FILE *fp;
printf("默认密码100\n");
printf("请输入密码\n");
scanf("%d",&i);
if((fp=fopen("密码.txt","r"))==0)
{
if(i==100)
printf("输入正确\n");
else
printf("请再次输入\n");
}
else
{ fp=fopen("密码.txt","r");
fscanf(fp,"%d",&l);
if(i==l)
printf("输入正确");
else
printf("对不起请重新输入\n");
fclose(fp);
} 124706716
} 13077094055
word()
{
int i;
FILE *fp;
fp=fopen("密码.txt","w");
printf("请输入你要更新的密码\n");
scanf("%d",&i);
fprintf(fp,"%d",i);
fclose(fp);
}
void main()
{
int i;
printf("<1>输入密码\t<2>修改密码\n");
scanf("%d",&i);
while(1)
{
if(i==1)
password();
else if(i==2)
word();
else
exit(1);
scanf("%d",&i);
}
getch();
}
色必夫循环 数组实现
void main()
{
int i,n,m,k=0,h=1,pass,j,a[20],b[20];
printf("请输入你要输入的人数\n");
scanf("%d",&n);
for(j=1;j<=n;j++)
{
a[j]=j;
printf("请输入密码\n");
scanf("%d",&b[j]);
}
printf("\n");
printf("请输入m");
scanf("%d",&m);
j=1;
while(h)
{
if(a[j]!=0)
k++;
if(k==m)
{ printf("%d",a[j]);
a[j]=0;
pass=b[j];
k=0;
h=0;
}
j++;
if(j>n)
j=1;
}
while(h<n-1)
{
if(a[j]!=0)
k++;
if(k==pass)
{
k=0;
printf("%d",a[j]);
a[j]=0;
pass=b[j];
h++;
}
j++;
if(j>n)
j=1;
}
j=1;
for(j=1;j<=n;j++)
if(a[j]!=0)
printf("%d",a[j]);
}
建立双向循环链表
struct student
{
int num;
struct student *next,*prior;
};
#define len sizeof(struct student)
#include <stdio.h>
void main()
{ int n,b;
struct student *p,*p1,*head,*p2;
n=0;
p=(struct student *)malloc(len);
head=NULL;
scanf("%d",&p->num);
while(p->num!=0)
{
n++;
if(n==1)
{
head=p;
p->next=p;
p->prior=p;
}
else
{
p1->next=p;
p->prior=p1;
}
p1=p;
p=(struct student *)malloc(len);
scanf("%d",&p->num);
}
free(p);
p1->next=head;
head->prior=p1;
while(n>0)
{
printf("%d",head->prior->next->num);
printf("%d",head->next->prior->num);
n--;
printf("\n");
head=head->next;
}
}