双链表创建(尾插法)

来源:互联网 发布:centos终端能输入中文 编辑:程序博客网 时间:2024/04/30 09:53



#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;}





0 0
原创粉丝点击