*/
#include
#include
using namespace std;
//////////////////////////////
//
template class List;
/*结点*/
template
class Node
{
friend class List;
T value;
Node *next;
Node(int v,Node *n)
{
value=v,next=n;
}
};
///////////////////////////////
//
/*链表*/
template
class List
{
public:
List();
~List();
void showList();
void xunhuan();
void shanchu(Node *p);
void js(int n,int s,int m);
bool isEmpty()
{
return head==NULL;
};
void append(const T value);
private:
Node *head;
};
template
void List::showList()
{
Node *p=head;
while(p!=NULL)
{
cout<value<<' ';
p=p->next;
}
}
template
List::List()
{
head=NULL;
}
template
List::~List()
{}
template
void List::append(T v)
{
Node *e=new Node(v,NULL);
Node *p=head;
if(head==NULL)
{
head=e;
}
else
{
while(p->next!=NULL)
p=p->next;
p->next=e;
}
}
template
void List::xunhuan()
{
Node *p=head;
while(p->next!=NULL)
{
p=p->next;
}
p->next=head;
}
template
void List::shanchu(Node *p)
{
Node *h=p;
while(h->next!=p)
h=h->next;
h->next=p->next;
delete p;
}
template
void List::js(int n,int s,int m)
{
Node *p=head;
Node *temp;
int i;
for(i=0;i<s-1;i++)
p=p->next;
cout<<"出列顺序为:";
while(n!=1)
{
for(i=0;i<m-1;i++)
p=p->next;
cout<<p->value<<' ';
temp=p;
p=p->next;
shanchu(temp);
n--;
}
cout<<p->value;
}
////////////////////////////////////////
//
class Text
{
public:
void text()
{
/*
n为单链表的长度;
s为从开头第S个结点处开始报数
m为报数长度,报m的结点将被删除
*/
List list;
int i;
int n,s,m;
cout<<"请输入n,s,m三个相关数据"<<endl;
cin>>n>>s>>m;
for(i=0;i<n;i++)
list.append(i+1);
list.showList();
cout<<endl;
list.xunhuan();
list.js(n,s,m);
}
};
/////////////////////////////////////////////////////////////
//主函数
int main()
{
Text t;
t.text();
while(1){}
return 0;
}