Implement linked list using Java

Source: Internet
Author: User

Question: using Java to implement linked list
Ideas:
Linked list features: linked list elements are connected by pointers. Usually there is a head pointer pointing to the first element, and other elements can be accessed through the first element.
How to store data in a linked list: Each element in a linked list should be composed of a data domain and a pointer to other elements.
Common Operations of a linked list: Create a linked list, add elements to the Linked List (Add at the end or at a specific position), modify elements in the Linked List, delete elements in the linked list, and view the chain

Elements in the table.
Public class mylist {
Private element header;
Public mylist (){}
Public mylist (Object O ){
Header = new element ();
Header. setvalue (O );
Header. setnext (null );
}
// Other operations are similar. Only the method for adding elements is written.
Public void add (Object O ){
Element temp = header;
If (temp = NULL ){
Header = new element ();
Header. setvalue (O );
Header. setnext (null );
} Else {
While (temp. getnext ()! = NULL ){
Temp = temp. getnext ();
}
Element new = new element ();
New. setvalue (O );
New. setnext (null );
Temp. setnext (new );
}
}
// Add an element at a specified position
Public void add (INT index, object O ){

}
Public void setelement (INT index, object O ){

}
}
Public class element {
Private object value;
Private element next;
// Setter and getter Methods
}

 

 

Related Article

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.