?? 1.txt
字號(hào):
/* HELLO.C -- Hello, world */
#include "stdio.h"
#include "stdlib.h"
#define NULL 0
#define OK 1;
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int Elemtype;
typedef struct Cnode
{
Elemtype data;
struct Cnode *next;
}CNode;
CNode *joseph;
Status Create_clist(CNode *clist,int n)
{
CNode *p,*q ;
int i;
clist=NULL;
for(i=n;i>=1;i--)
{
p=(CNode*)malloc(sizeof(CNode));
if(p==NULL)
return OVERFLOW;
p->data=i;
p->next=clist;
clist=p;
if(i==n)
q=p;
}
q->next=clist;
joseph=clist;
return OK;
}
Status Joseph(CNode *clist,int m,int n,int k)
{
int i;
CNode *p,*q;
if(m>n)return ERROR;
if(!Create_clist(clist,n))
return ERROR;
p=joseph;
for(i=1;i<m;i++)
p=p->next;
while(p)
{
for(i=1;i<k-1;i++)
p=p->next;
q=p->next;
printf("%d ",q->data);
if(p->next==p)
p=NULL;
else
{
p->next=q->next;
p=p->next;
free(q);
}
clist=NULL;
}
}
jixu()
{
int m,n,k,i;
CNode *clist;
printf("\n請(qǐng)輸入圍坐在圓桌周圍的人數(shù)1n:");
scanf("%d",&n);
printf("請(qǐng)輸入第一次開始報(bào)數(shù)人的位置2m:");
scanf("%d",&m);
printf("\n你希望報(bào)數(shù)到第幾個(gè)數(shù)的人出列?:");
scanf("%d",&k);
Create_clist(clist,n);
printf("\n出列的順序如下4:\n");
Joseph(clist,m,n,k);
}
void main()
{
int m,n,k,i;
char f;
CNode *clist;
f='y';
while((f=='y')||(f=='Y'))
{
jixu();
printf("\n要繼續(xù)測(cè)試嗎(y/Y繼續(xù),其他鍵退出):\n");
scanf("%s",&f);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -