#include "ring.h"
#include <iostream>
using namespace std;
Ring::Ring(int n)
{
if (n < 2)
throw exception();
pBegin = new People[n];
for (int i = 1; i <= n; i++)
{
pBegin[i-1].next = &pBegin[i%n];
pBegin[i-1].code = i;
}
pivot = pCurrent = &pBegin[0];
number = n;
}
Ring::~Ring()
{
delete []pBegin;
}
void Ring::countBy(int m)
{
for (int i = 1; i <= m; i++)
{
pivot = pCurrent;
pCurrent = pCurrent->next;
pivot->previous = pCurrent->previous;
}
}
int Ring::getNum() const
{
return pCurrent->code;
}
void Ring::getKey(int i, int n)
{
pCurrent->code = i;
pCurrent->key = n;
}
void Ring::remove()
{
pivot->next = pCurrent->next;
pivot->previous = pCurrent->previous;
pCurrent = pivot;
}
int Ring::getWinner() const
{
return pCurrent->code;
}