#include <stdio.h>#include <stdlib.h>#define OK 1;#define ERROR 0;typedefintStatus;typedefintelemtype;typedef struct cnode{elemtype data; struct Cnode*next;} CNode; CNode*joseph; Status Create_clist (CNode*clist,intN) {CNode*p,*q;intI Clist=null;//Null=0? for(i = n; I >=1; i--) {p= (CNode*)malloc (sizeof (CNode));if(P==null) {return-1;//Storage space allocation failed} p->data=i; P->Next=clist; clist=p;if(i==n) {Q=p; } }Q-Next=clist; Joseph=clist;returnOK;} Status Joseph (CNode*clist,int m,intNintK) {intI CNode*p,*q;if(m>n) {returnERROR;}if(! Create_clist (Clist,n)) {returnERROR;} 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\ n",Q->data);if(p->Next==p) {p=null; }Else{p->Next=Q-Next; P=p->Next; FreeQ); }}clist=null;} void Main () {int m, N,k,i; CNode*clist; CList =null;printf("\ n Please enter the number of people sitting around the round Table N:"); scanf"%d", &n);printf("\ n Please enter the first time to start the person's position m:"); scanf"%d",&m);printf("\ n Please enter the number of people you wish to count down to? : "); scanf"%d", &k); Create_clist (Clist,n);printf("\ nthe order of the dequeue is as follows: \ n"); Joseph (CList,m, n,k);system("Pause");}
Solving Joseph ring problem with linear table (C language)