#include<stdio.h>
#include<malloc.h>
#define Sum 26
typedef struct doubleList
{
char n;
struct doubleList *pioneer;
struct doubleList *next;
}doubleList;
void initList(doubleList **head);
void showList(doubleList head);
void moveList(doubleList **head,int Index);
void moveList(doubleList **head,int Index)
{
doubleList *p=NULL;
int k;
p=(*head)->next;
if(Index>=0)
{
for(k=0;k<Index;k++)
{
p=p->next;
}
(*head)->next=p;
}
else
{
for(k=Index;k<0;k++)
{
p=p->pioneer;
}
(*head)->next=p;
}
}
void showList(doubleList head)
{
doubleList *p=NULL;
int k=0;
p=head.next;
while(k<Sum)
{
printf("%3c",p->n);
p=p->next;
k++;
}
}
void initList(doubleList **head)
{
doubleList *p=NULL,*q=NULL;
int k=0;
(*head)=(doubleList *)(malloc(sizeof(doubleList)));
while(k<Sum)
{
q=(doubleList *)(malloc(sizeof(doubleList)));
k++;
if(k==1)
{
(*head)->next=q;
}
else
{
q->pioneer=p;
p->next=q;
}
q->n='A'+k-1;
p=q;
}
p->next=(*head)->next;
(*head)->next->pioneer=p;
}
int main()
{
doubleList *head=NULL;
initList(&head);
showList(*head);
printf("\n");
moveList(&head,-3);
showList(*head);
}
#include<malloc.h>
#define Sum 26
typedef struct doubleList
{
char n;
struct doubleList *pioneer;
struct doubleList *next;
}doubleList;
void initList(doubleList **head);
void showList(doubleList head);
void moveList(doubleList **head,int Index);
void moveList(doubleList **head,int Index)
{
doubleList *p=NULL;
int k;
p=(*head)->next;
if(Index>=0)
{
for(k=0;k<Index;k++)
{
p=p->next;
}
(*head)->next=p;
}
else
{
for(k=Index;k<0;k++)
{
p=p->pioneer;
}
(*head)->next=p;
}
}
void showList(doubleList head)
{
doubleList *p=NULL;
int k=0;
p=head.next;
while(k<Sum)
{
printf("%3c",p->n);
p=p->next;
k++;
}
}
void initList(doubleList **head)
{
doubleList *p=NULL,*q=NULL;
int k=0;
(*head)=(doubleList *)(malloc(sizeof(doubleList)));
while(k<Sum)
{
q=(doubleList *)(malloc(sizeof(doubleList)));
k++;
if(k==1)
{
(*head)->next=q;
}
else
{
q->pioneer=p;
p->next=q;
}
q->n='A'+k-1;
p=q;
}
p->next=(*head)->next;
(*head)->next->pioneer=p;
}
int main()
{
doubleList *head=NULL;
initList(&head);
showList(*head);
printf("\n");
moveList(&head,-3);
showList(*head);
}