约瑟夫环2.txt

来自「数据结构学习用到的一些程序!!里面有二叉树相关的几个」· 文本 代码 · 共 35 行

TXT
35
字号
#include<malloc.h>
#include<stdio.h> 
#define LEN sizeof(struct shu) 
#define NULL 0 
struct shu 
{int num; 
 struct shu *next; 
 }; 
 main() 
 {struct shu *p,*q,*head; 
 int i,a,b; 
 head=NULL; 
 p=q=(struct shu *)malloc(LEN); 
 scanf("%d",&p->num); 
 while(p->num!=NULL) 
 {if(head==NULL)head=p; 
 else {q->next=p;q=p;} 
 p=(struct shu *)malloc(LEN); 
 scanf("%d",&p->num); 
 } 
 q->next=head; 
 scanf("\n%d%d\n",&a,&b); 
 while(q->num!=a) 
 q=q->next; 
 p=q->next; 
 while(p!=q) 
 {for(i=1;i<=b-2;i++) 
 {q=p;p=p->next;} 
 q->next=p->next; 
 printf("%d",p->num); 
 q=q->next; 
 p=q->next; 
 } 
 printf("%d",q->num); 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?