⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 链表发求约瑟夫环.txt

📁 中过科学技术大学历年复试机试题
💻 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 + -