#include <iostream>using namespace STD;Template<TypeNameType>structnode{node<type> *next; Node<type> *prve; Type data; Node (Type D = Type ()):d ATA (d), Next (null), Prve (null) {}};Template<TypeNameType>classdclist{ Public: Dclist () {tail = head =NewNode<type> (); Head->prve = tail; Tail next = head; }BOOLInsert (Type a[],intN) { for(intI=0; i<n;i++) {_insert (a[i]); }return true; }voidPrintf (Type D = Type ())//Start printing from the specified node, starting with the default from the head node. {node<type> *p = head;if(D==type ()) {p=p->next; while(P!=head) {cout<<p->data<<"\ T"; p=p->next; }cout<<endl; }Else if(d<0) { while(d++) p = p->prve; }Else{ while(d--) p=p->next; } while(P!=head) {cout<<p->data<<"\ T"; p=p->next; } }BOOLRemove (Type val) {return_remove (Val); }BOOLEmpty () {return_empty (); }voidFind (Type val) {_find (val); }Private: node<type>* _find (Type val) {node<type> *p = head->next; while(P!=head) {if(P->data = = val) Break; p = p->next; }if(P==head)returnNULL;Else returnP }BOOL_empty () {returnHead->next = = head; }BOOL_remove (Type val) {node<type> *p = head->next; p = _find (val);if(P!=null) {P->prve->next = p->next; P->next->prve = p->prve;DeleteP p = NULL;return true; }return false; }BOOL_insert (Type val) {node<type> *p = head; Node<type> *s =NewNode<type> (Val); while(P->next!=head) {p=p->next; } P->next = S; S->prve = p; tail = s; Tail next = head; Head->prve = tail;return true; }Private: Node<type> *head; Node<type> *tail;};intMain () {dclist<int>List;inta[]={2,3,4,5,1};List. Insert (A,5);//list. Remove (3); List. Printf (0);return 0;}
C + + bidirectional loop linked list