?? 鏈表發求約瑟夫環.txt
字號:
#include<stdio.h>
#include<stdlib.h>
#define N 20
typedef struct Node{
int num;
int secrect;
struct Node *next;
}Node,*Linklist;
main(){
FILE *fp,*fpp;
int i,j,secrect;
Node *r=NULL,*t=NULL,*h=NULL,*e=NULL,*f=NULL;
if((fp=fopen("d:\\yt\\input01.txt","r"))==NULL){
printf("file open error!\n");
exit(0);
}
if((fpp=fopen("d:\\yt\\output01.txt","w"))==NULL){
printf("file open error!\n");
exit(1);
}
h=(Linklist)malloc(sizeof(Node));
r=h;
t=h;
i=1;
fscanf(fp,"%d",&(h->secrect));
h->num=i;
i++;
while(i<=20){
r=(Linklist)malloc(sizeof(Node));
fscanf(fp,"%d",&(r->secrect));
r->num=i;
t->next=r;
t=r;
i++;
}
//***************************核心代碼段************************
t->next=h;
r=t;
fscanf(fp,"%d",&secrect);
for(i=1;i<=20;i++){
j=1;
while(j<secrect){
r=r->next;
j++;
}
f=r;
e=r->next;
r->next=r->next->next;
printf("%d ",e->num);
fprintf(fpp,"%d ",e->num);
secrect=e->secrect;
free(e);
r=f;
}
//*************************************************************
fclose(fp);
fclose(fpp);
printf("\n");
system("pause");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -