Answer:
Check the explanation
Step-by-step explanation:
#include <iostream>
using namespace std;
class Circular{
public:
int key;
Circular *next;
Circular* prev;
};
int main()
{
int N,M;
cout<<"Enter the value of N: ";
cin>>N;
cout<<"Enter the value of M: ";
cin>>M;
Circular *c;
c=new Circular[N];
for(int i=0;i<N;i++)
{
(c+i)->key=i+1;
if(i==N-1) (c+i)->next=c;
else (c+i)->next=(c+i+1);
if(i==0) (c+i)->prev=(c+N-1);
else (c+i)->prev=(c+i-1);
}
Circular *current=c;
cout<<"Order of elimination are: ";
for(int i=1;i<N;i++)
{
for(int j=1;j<=M;j++)
{
current=current->next;
}
cout<<current->key<<" ";
current=current->next;
current->prev=((current->prev)->prev);
(current->prev)->next=current;
}
cout<<endl<<"Winner is: "<<current->key<<endl;
delete(c);
}