#include <stdio.h>
#include <stdlib.h>
typedef int ItemValue;
typedef struct DoubleLinkedList
{
ItemValue value;
struct DoubleLinkedList *pre;
struct DoubleLinkedList *next;
} DoubleList, *pDoubleList;
DoubleList *CreateDoubleLinkedList()
{
DoubleList *head = (DoubleList *)malloc(sizeof(DoubleList));
head->pre = NULL;
head->next = NULL;
DoubleList *pTemp;
pTemp = head;
ItemValue iValue;
while (scanf("%d", &iValue) != EOF)
{
DoubleList *p = (DoubleList *)malloc(sizeof(DoubleList));
p->value = iValue;
p->next = pTemp->next;
p->pre = pTemp;
pTemp->next = p;
pTemp = p;
}
return head;
}
void VisitDoubleLinkedList(DoubleList *L)
{
DoubleList *p = L;
while (p->next != NULL)
{
printf("%d ", p->next->value);
p = p->next;
}
}
int main()
{
DoubleList *DL;
DL = CreateDoubleLinkedList();
VisitDoubleLinkedList(DL);
free(DL);
system("pause");
return 0;
}

本文详细介绍了如何使用尾插法创建双链表,包括步骤和示例代码,帮助理解双链表数据结构的操作。
3959

被折叠的 条评论
为什么被折叠?



