#include < iostream >
#include < cstdlib >
#define NUM 100
using namespace std;
// 双链表的结点
typedef struct DLnode{
char data;
struct DLnode *prior;
struct DLnode *next;
}DLnode;
// 创建双链表
void createLinklist(DLnode *&S,char a[],int n)
{
S = (DLnode *)malloc(sizeof(DLnode));
S->prior = S;
S->next = S; // 表头初始化
DLnode *s,*r,*p; // s用于创建新节点,r用于指向终端结点,p用于删除头结点
r = S;
for(int i=0;i<n;i++){
s = (DLnode *)malloc(sizeof(DLnode));
s->data = a[i];
s->next = r->next;
r->next = s;
s->prior = r;
S->prior = s;
r = s;
}
p = S; // 删除表头
S = S->next;
r->next = S;
S->prior = r;
free ( p );
}
// 移动链表
void moveLinklist(DLnode *&S,int num)
{
DLnode *p = S;
if(num>0){
for(int i=0;i<num;i++){
p = p->next;
}
S = p;
}
else if(num<0){
for(int i=0;i<-num;i++){
p = p->prior;
}
S = p;
}
else return;
}
// 显示链表
void display(DLnode *S)
{
DLnode *p = S;
while(p->next!=S){
cout<<p->data<<" ";
p = p->next;
}
cout<<p->data<<endl;
}
// 销毁链表
void destroy(DLnode *&S)
{
DLnode *p = S;
while(p->next!=S){
DLnode *temp = p;
p = p->next;
free(temp);
}
free ( p );
}
int main()
{
char a[26];
int num;
for(int i=0;i<26;i++){
a[i] = 'A' + i;
}
DLnode *S;
createLinklist(S,a,26);
display(S);
cout<<"Please input a integer: ";
cin >> num;
moveLinklist(S,num);
display(S);
return 0;
}