首页 > 代码库 > 约瑟夫环

约瑟夫环

#include <iostream>using namespace std;struct Node{    Node *next;    int data;};void createCircle(Node* &L,int n,int k){    int i = 0;        Node*p = L;    p ->data = http://www.mamicode.com/k;"The sequence of dequeue queue is:"<<endl;    createCircle(L, n, k);    Node *p = L;    while (n--)    {        int count = 1;                while (count<m-1)        {            p = p->next;            count++;        }                Node* q= p->next;        cout<<q->data<<" ";        p->next = q->next;        p = p->next;        free(q);    }    cout<<endl;    cout<<"Winner: "<<p->data<<endl;}int main(){    Node* L = new Node;        JosephusProblem(L,6,1,3);    return 0;}