双向循环链表之实践

本文介绍了一个使用C语言实现的双向链表的基本操作。包括初始化双向链表、展示链表内容以及通过指定索引来调整链表元素的位置等功能。通过具体的代码示例,读者可以了解到双向链表的结构及其实现细节。
#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);
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值