preface

A new series, “Easy to Understand Data Structures and Algorithms by Looking at Pictures”, is launched, mainly using pictures to describe common data structures and algorithms, easy to read and understand. This series includes dozens of examples of heaps, queues, lists, trees, graphs, sorts, and more.

Two-way linked list

Bidirectional linked list is a kind of linked list, also called double linked list bidirectional means that its link direction is bidirectional, it is composed of several nodes, each node contains the next node and the pointer of the previous node, so from any node of the bidirectional linked list, it is very convenient to access its precursor node and successor node.

Double linked list features

  • You do not need to specify the length of a list when creating a double-linked list.
  • Double-linked lists require one more pointer to the precursor node than single-linked lists, so they require a little more storage space.
  • Insertion and deletion of double-linked lists require maintaining both next and prev Pointers.
  • Elements in a doubly linked list need to be accessed sequentially, that is, by traversing to find the elements.

Double linked list creation

Create an empty linked list,

Insert the chain end

Insert the monster is coming at the end of each word in order to create the “The” node,

To connect,

Create the “Monster” node,

And then connect them,

All the remaining nodes are created and joined.

Creating iterators

The current pointer to the iterator initially points to head,

Execute next twice, the current pointer points to the node whose index is 2,

The node value is,

Set the current pointer to the node with index 3,

Insert the node

Insert the “big” node after index 1. Create a “big” new node by pointing current to the node whose index is 1.

Insert to current point,

Remove nodes

Delete the “big” node, move the current pointer to the “but” node,

Perform the delete operation, break the next and prev Pointers to the “Big” node and the two nodes, and associate the “The” node with the “Monster” node.

Bidirectional circular linked lists

The head node of the previous bidirectional list is not connected to the tail, so if you want to access the last node, you need to traverse all the way to the last node. The prev pointer of the header node points to the last node, and the next pointer of the last node points to the header node, thus forming a bidirectional circular list.

————- Recommended reading ————

Summary of my open Source projects (Machine & Deep Learning, NLP, Network IO, AIML, mysql protocol, Chatbot)

Why to write “Analysis of Tomcat Kernel Design”

My 2017 article summary – Machine learning

My 2017 article summary – Java and Middleware

My 2017 article summary – Deep learning

My 2017 article summary — JDK source code article

My 2017 article summary – Natural Language Processing

My 2017 Article Round-up — Java Concurrent Article


Talk to me, ask me questions:

Welcome to: