Data structure-doubly linked list (C + +)

Source: Internet
Author: User

------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 + +)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.