Data Structures for Llinklist

Source: Internet
Author: User

When using C + +, we often use a variety of containers, which are actually data structures. The same is true in Java. But since JavaScript gives us only a built-in array of data structures, it is intended to be an object. There are no data structures that are common to us, but we cannot leave these common data structures in the actual work. So we can only construct ourselves.

Although the operation of arrays in JavaScript is much more convenient than manipulating arrays such as C++/java, arrays are an object that is inefficient when processing data. So sometimes we have to construct the data structures we want ourselves.

Definition (define):

A linked list is a collection of nodes that have a set of elements. Each node has two parts: the first part is the data field where the data element is stored, and the other is the reference field that stores the next node address. Each node uses a reference to the object to point to his successor. This reference to the successor is what we often call a chain. Since they do not have to be stored sequentially, the list can achieve an O (1) complexity at the time of insertion, much faster than another linear table-order table, but the time to find a node or to access a particular numbered node requires O (n), while the corresponding time complexity of the linear and sequential tables is O (Logn) and O (1) respectively. Therefore, in addition to using arrays for random access to data elements, you can use a linked list in other cases where an array is used.

We know that arrays are primarily referencing elements by location, and linked lists are referenced by their relationships. When we want to find an element in a re-linked list, we have to go through the lookup from the list header. However, when it comes to labeling the list header, it's a bit of a hassle, and with the flexibility of JavaScript, I think we can do it easily. From here we also see that the reference to the last element should be set to null. Because inserting a delete element into a linked list, you simply need to change the reference of the element to the adjacent element, instead of moving the position of the element like an array, so that it looks more efficient.

Build a linked list (construct a linked list):

Data Structures for Llinklist

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.