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.

Singly linked list

A one-way linked list is a kind of linked list, also known as a single linked list. A one-way list means that its link direction is one-way, and it is composed of several nodes, each node contains the pointer of the next node.

Single linked list features

  • Creating a single list without specifying the length of the list is an advantage over an array structure, which requires specifying a larger array length even if the array is implemented as a dynamic array and copying the elements of the original array into the new array.
  • Node deletion in a singly linked list is convenient because it can be done by changing the pointer directly, while in some cases array deletion will cause the remaining elements to be moved.
  • The disadvantage of a singly linked list is that elements are accessed sequentially, that is, iteratively, to find the elements, whereas arrays can be accessed randomly.

Single linked list creation

Create an empty linked list,

Insert the chain end

Insert the word nobody grows old merely by a number of years into the end of the node to create “nobody”.

To connect,

To continue creating the “Grows” node,

And then connect them,

And so on, create the remaining nodes separately and connect them.

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 4,

Insert the node

Insert “but” and “someone” after index 1. Create a new “but” node by pointing the current pointer to the node whose index is 1.

Insert to current point,

Perform the next operation,

Create a new node for “someone”,

Insert to current point,

Remove nodes

Delete the “but” and “someone” nodes, first delete the “but” node,

Delete the “someone” node,

————- 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: