------DoublyLinkedList.h------Template <class t>class dnode{private://point Pointer to left and right node dnode<t> * Left;dnode <T> * right;public://Data is a public member T data;//constructor dnode (void);D node (const t& item);//Change Table method void Insertright (Dnode <T> * p); void Insertleft (Dnode<t> * p);D node<t> * deletenode (void);//Get pointer to left and right node dnode<t> * Nextnoderight (void) const;dnode<t> * nextnodeleft (void) const;};
------DoublyLinkedList.cpp------#include "DoublyLinkedList.h"//constructor, create an empty table and initialize its data domain template <class t> Dnode<t>::D node (const t& Item) {//Establish a node to itself and initialize the data field left = right = This;data = Item;} Inserts the node p into the doubly linked list to the right of the current node template <class t>void dnode<t>::insertright (dnode<t> * p) {// Connect p to the right successor of the current node P->right = Right;right->left = p;//connects the left side of P with the current node P->left = This;right = P;} Insert node p to the left of the current node Template<class t>void dnode<t>::insertleft (dnode<t> * p) {//link p to the left successor node of the current node p-> left = Left;left->right = p;//the right side of P is connected to the current node p->right = This;left = P;} Deletes the current node from the linked list and returns its address template <class t>dnode<t> * DNODE<T>::D eletenode (void) {//The right pointer of the left node points to the right node left- >right = right;//The left pointer of the right node points to the left node Right->left = left;//Returns the current node pointer return this;
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Data structure-doubly linked list (C + +)