#includeiostreamusingnamespacestd;classJosephCircle{public:JosephCircle(intTotal,intMultiple);~JosephCircle();//释放内存voidProdecuCircle();voidPrintCircle();private:typedefstructCircle{intNo;structCircle*Next;}JosCir,*PJosCir;PJosCirL;//指向第一个结点intTotal;//环的总人数intMultiple;//按什么倍数来};JosephCircle::JosephCircle(intTotal=41,intMultiple=3){this-Total=Total;this-Multiple=Multiple;L=newJosCir;//创造头结点,不是第一个结点,头结点不存数}JosephCircle::~JosephCircle(){PJosCirtemp;for(;L!=L-Next;){temp=L;L=L-Next;deletetemp;}deleteL;//最后一个结点}voidJosephCircle::ProdecuCircle(){PJosCirtemp=L,head;for(inti=1;i=Total;i++)//尾插{head=newJosCir;if(head==NULL){exit(-1);}head-No=i;temp-Next=head;temp=head;}head-Next=L-Next;//尾结点连接到第一个结点deleteL;//头结点可以释放了L=head-Next;//L指向第一个结点}voidJosephCircle::PrintCircle(){PJosCirtemp;while(L-Next!=L){for(inti=1;iMultiple-1;i++){L=L-Next;}coutL-Next-No--;temp=L-Next;L-Next=L-Next-Next;//连接起来L=L-Next;//从下一位开始deletetemp;}coutsetw(4)leftL-No\n\n\n;}intmain(){intTotal,Multiple;cout请输入约瑟夫环人数:;cinTotal;cout请输入约瑟夫环规则倍数:;cinMultiple;JosephCircleCircle(Total,Multiple);Circle.ProdecuCircle();Circle.PrintCircle();return0;}