#include <iostream>
using namespace std;
typedef struct linknode
{
int value;
struct linknode *next;
}linknode,*linklist;
linklist createcycle(int total)
{
int index = 1;
linklist prev = NULL,curr = NULL,head = NULL;
head = new linknode;
head->value = index;
prev = head;
for(;index < total;)
{
curr = new linknode;
curr->value = ++index;
prev->next = curr;
prev = curr;
}
prev->next = head;
return head;
}
void run(int total,int tag)
{
linklist node = createcycle(total);
linklist curr = node,prev = NULL;
while (curr == curr->next)
{
for(int i = 0;i < tag-1;++i)
{
prev = curr;
curr = prev->next;
}
cout<<curr->next->value<<"->";
curr->next = curr->next->next;
delete curr->next;
prev = curr;
curr = prev->next;
}
cout<<curr->value<<endl;
delete curr;
}
int main()
{
run(41,3);
return 0;
}
Lornsoul