Linked list definition: (Java version) a recursive data structure. It is null or a reference pointing to a node. The node contains a generic element and a reference pointing to another linked list. In this definition, a node is an abstract entity that may contain any data type. This is why it is represented by generics.
I. linked list structure, node Overview
We can use node to represent a node:
Private class node {item; // generic type node next; // execute the reference of the next node}
It is necessary to explain the meaning of the parameters item and next:
Item: generic parameter. It is like a placeholder, indicating any type of data that we want to process in the linked list.
Node: This type of instance variable shows the chain nature of this data structure.
For example, if first is a variable pointing to a Node object, we can use first. item first. Next to access its instance variables. This type of class is alsoRecord. Statement: the following uses the termLinkTo indicateNode reference.
Ii. Define the linked list Structure
According to the definition, we only need a node type variable to represent the linked list. For example, to construct a linked list containing elements to be or, first construct the node:
Node first = new node ();
Node second = new node ();
Node third = new node ();
Set the item field of each node as the required value. Assume that the generic type of the item is string.
First. Item = "";
Second. Item = "be"
Third. Item = "or"
Then, you can set the structure of the next domain to construct the linked list by referencing and pointing to it:
First. Next = secoud;
Second. Next = thrid;
Graph structure:
Note: rectangles indicate objects, instance variables are written in rectangles, and arrows pointing to referenced objects indicate reference relationships.
At this point, a simple linked list containing three nodes is implemented. First has no precursor, but there is a suffix. secoud contains the precursor and suffix. thrid has a precursor but no suffix. Next, start to operate the linked list.
Ii. Operation linked list