数据结构:双向链表 1.代码​#include stdio.h #include malloc.h typedef struct DoubleLinkedNode { char data; struct DoubleLinkedNode *previous; struct DoubleLinkedNode *next; }DLNode,*DLNodePtr; DLNodePtr initLinkList() { DLNodePtr tempHeader (DLNodePtr)malloc(sizeof(struct DoubleLinkedNode)); tempHeader-data\0; tempHeader-previousNULL; tempHeader-nextNULL; return tempHeader; } void printList(DLNodePtr paraHeader) { DLNodePtr p paraHeader-next; while(p!NULL) { printf(%c,p-data); pp-next; } printf(\r\n); } void insertElement(DLNodePtr paraHeader,char paraChar,int paraPosition) { DLNodePtr p,q,r; pparaHeader; for(int i0;iparaPosition;i) { pp-next; if(pNULL) { printf(The position %d is beyond the scope of the list.,paraPosition); return; } } q(DLNodePtr)malloc(sizeof(struct DoubleLinkedNode)); q-dataparaChar; rp-next; q-nextp-next; q-previousp; p-nextq; if(r!NULL) { r-previousq; } } void deleteElement(DLNodePtr paraHeader,char paraChar) { DLNodePtr p,q,r; pparaHeader; while((p-next!NULL)(p-next-data!paraChar)) { pp-next; } if(p-nextNULL) { printf(The char %c does not exist.\r\n,paraChar); return; } qp-next; rq-next; p-nextr; if(r!NULL) { r-previousp; } free(q); } void insertDeleteTest() { DLNodePtr tempListinitLinkList(); printList(tempList); insertElement(tempList,H,0); insertElement(tempList,e,1); insertElement(tempList,l,2); insertElement(tempList,l,3); insertElement(tempList,o,4); insertElement(tempList,!,5); printList(tempList); deleteElement(tempList,e); deleteElement(tempList,a); deleteElement(tempList,o); printList(tempList); insertElement(tempList,o,1); printList(tempList); } void basicAddressTest() { DLNode tempNode1,tempNode2; tempNode1.data4; tempNode1.nextNULL; tempNode2.data6; tempNode2.nextNULL; printf(The first node: %d, %d, %d\r\n,tempNode1,tempNode1.data,tempNode1.next); printf(The first node: %d, %d, %d\r\n,tempNode2,tempNode2.data,tempNode2.next); tempNode1.nexttempNode2; } void main() { insertDeleteTest(); basicAddressTest(); } ​2.运行结果Hello! The char a does not exist. Hll! Holl! The first node: 6684160, 6684160, 6684176 The first node: 6684128, 6684128, 6684144