Implementation of Data Structure (2) linked list

Source: Internet
Author: User

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

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: info-contact@alibabacloud.com 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.