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

📄 第二题.c

📁 Josephu问题为:设编号为1
💻 C
字号:
/* Note:Your choice is C IDE */
#include <stdio.h>
#include <stdlib.h>

typedef struct lnode{
int data;
struct lnode *next;
}LNode;


LNode *Create(int n ){
LNode *s,*p,*t;
int i=1;
t=(LNode *)malloc(sizeof(LNode));
t->data=i; i++;
p=t;
 while(n!=1){
   s=(LNode *)malloc(sizeof(LNode));
   s->data=i;
   if(t==NULL) 
   t=s;
   else
   p->next=s;
   p=s;
   i++;
   n--;

 }
   p->next=t;
   return (t);
}

LNode* OutNode(LNode *p) {
    LNode *q;
    for (q=p;q->next!=p;q=q->next);
    q->next=p->next;
    free (p);
 return q;
}

void PrintList(LNode *t,int m,int k){
 int i;
 LNode *p;
 printf ("The out number is:\n");
 p=t;
 for(i=1;i<k;i++)
 p=p->next; /*找到k编号的节点指针*/

 while (p->next!=p){
  for (i=1;i<m;i++)
  p=p->next;
  printf ("%d ",p->data);
  p=OutNode(p);
  p=p->next;
 }
    
}
void main(){
   int n,k,m,h;
   LNode *p,*q;
   printf("Please enter 1 to start or -1 to end:");
   scanf("%d",&h);
   while(h==1){
      printf("The total number is:");
      scanf("%d",&n);
      while(n==0) {
      printf("Wrong.");
      scanf("%d",&n);
      }

   printf("The number of the start people is:");
   scanf("%d",&k);
   while (k>n&&k<1){
    printf("Wrong.");
    scanf("%d",&k);

}
    printf("The interval number is:");
    scanf("%d",&m);
    while (m>n||m<1){
    printf("Wrong.");
    scanf("%d",&m);

}
     p=Create(n);
     PrintList(p,m,k);
     puts("Press any key to Quit....");
     getch();
}
}

⌨️ 快捷键说明

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