josephus问题中,有以下扩展问题: 每隔M个删除一个,最后剩下一个;在algorithm I-IV中提到,用环状链表进行该操作。 #include <iostream.h> #include <stdlib.h> #include <stdio.h> struct node { int item; node *next; node(int x, node *t) { item = x; next = t; } }; typedef node *link; int main(int argc, char *argv[]) { int N=10,M=3; link t = new node(1,0); t->next = t; link x = t; for (int i=2; i<=N; i++) { x=(x->next=new node(i,t)); } while (x != x->next) { for (i=1; i<M; i++) { x=x->next; } x->next = x->next->next; } cout <<x->item<<endl; } 在其中,可以随意设置N和M的值,但是我的输入参数总是出错,所以我提前设定了。