和单链表没差多少其实
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
typedef struct LNode {
char data;
struct LNode* prior;
struct LNode* next;
}DLinkNode;//双向链表结构体的定义
//这里使用尾插法
void Create(DLinkNode* head)
{
char data;
head->next = NULL;
head->prior = NULL;
DLinkNode *s,*tail=head;
scanf("%c", &data);
while (data != '#')
{
s = (DLinkNode*)malloc(sizeof(DLinkNode));
s->data = data;
s->next = NULL;
s->prior = tail;
tail->next = s;
tail = tail->next;
scanf("%c", &data);
}
}
int main()
{
DLinkNode head;
DLinkNode* temp;
Create(&head);
temp = &head;
temp = temp->next;
while (temp->next != NULL)
{
printf("%c", temp->data);
temp = temp->next;
}
printf("%c\n", temp->data);
while (temp != &head)
{
printf("%c", temp->data);
temp = temp->prior;
}
return 0;
}
下面是运行的例子