Java record -48-JAVA data structure-linked list

Source: Internet
Author: User

A linked list is a non-sequential, non-sequential storage structure on a physical storage unit, and the logical order of the data elements is achieved through the order of the pointers in the linked list. A linked list consists of a series of nodes (each element in the list is called a node) that can be dynamically generated at run time.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/75/4A/wKioL1Y1XS-zgcqwAAJwvo9n5Q4838.jpg "title=" QQ picture 20151101081241.png "alt=" Wkiol1y1xs-zgcqwaajwvo9n5q4838.jpg "/>

One-way Node instance:

Public class nodetest {    public static void main (String[]  args) {        node node1 = new node ("Node1") ;         node node2 = new node ("Node2");         node node3 = new node ("Node3");         //build a linked list         node1.next =  node2;        node2.next = node3;         system.out.println (Node1.next.next.data);         //Inserts a node         node node4 = new node ( "Node4");        node4.next = node1.next;         Node1.next = node4;        system.out.println ( Node1.next.next.next.data);    }}class node{    string data;     node next;    public node (String data) {         this.data = data;    }}

Two-way node nodes are similar to one-way node nodes, but have a pointer to the previous node in the node declaration.

Public class nodetest {    public static void main (String[]  args) {        node node1 = new node ("Node1") ;         node node2 = new node ("Node2");         node node3 = new node ("Node3");         //build a linked list         node1.next =  node2;        node2.previous = node1;                 node2.next =  node3;        node3.previous = node2;                 node3.next = node1;       &nbSp; node1.previous = node3;        system.out.println ( Node1.next.previous.data);         //Inserting a node (inserting a node requires modifying four pointers)          node node4 = new node ("Node4");         node4.next = node1.next;         node1.next.previous = node4;        node4.previous  = node1;        node1.next = node4;                 system.out.println ( Node1.next.next.data);    }}class node{    node previous;     string data;    node next;    public  node (string data) {        this.data = data;    }} 


Java record -48-JAVA data structure-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.