Home>Article>Web Front-end> Does node have a linked list structure?

Does node have a linked list structure?

WBOY
WBOY Original
2022-07-04 16:11:25 1459browse

There is a linked list structure in node; the linked list is a structure for storing data. When the file writable stream method works, some written content needs to be queued in the cache area and is first-in-first-out. According to the rules, in order to store these queued data, the new version of node uses a linked list structure to store these data.

Does node have a linked list structure?

The operating environment of this article: Windows 10 system, nodejs version 12.19.0, Dell G3 computer.

Node has a linked list structure

A linked list is a structure for storing data.

When the file writable stream write method is working, some written content needs to be queued in the buffer and follows the first-in, first-out rule.

In order to store these queued data, the new version of Node uses a linked list structure to store these data.

Why not use arrays to store data?

Compared with the linked list structure, arrays have some obvious disadvantages:

The length of arrays to store data has an upper limit in many languages

There is a collapse problem in arrays , when inserting or deleting elements, the position of other elements may be moved

In JavaScript, arrays are actually object types, which will be less efficient in use

The above disadvantages are just Compared with linked lists, array structures are still very powerful in actual use.

Linked list

A linked list is a collection composed of a series of nodes.

Each node has an attribute (next) that points to the next node reference.

Combining these references to the next node forms a chain.

Common linked list classification

Two-way linked list: the most commonly used, its query speed will be faster

One-way linked list: This example discusses one-way Linked list, it is enough for the write method of the writable stream to use

Circular linked list

One-way linked list structure

Does node have a linked list structure?

The linked list structure is actually a container , three objects are stored in it: head, null and the middle node node.

There is a next attribute on the node node, pointing to the next node node.

At the same time, the node node also has an element attribute, which is used to store the specific data of the current node node.

head points to the first node, and then passes down in the order pointed by next, until the last node, whose next points to null.

By default, the linked list is empty (head = null) and there is no node node in it.

The so-called doubly linked list is to add an attribute similar to prev to each node, pointing to the previous node.

The circular linked list connects the head and tail nodes.

The role of linked lists

The appearance of linked lists is mainly used to store data.

This function is similar to that of an array, so the common actions of a linked list are operations such as adding, deleting, modifying, querying, and clearing data.

These need to be implemented by yourself when creating the linked list structure.

One-way linked list implementation

Master the implementation of the one-way linked list structure to store the data that needs to be queued and written when the file is writable.

The linked list structure contains node, head, and null

The default linked list is empty, that is, head points to null

The operation of the linked list is similar to an array, so there must be an attribute record node Number: size

Each node must have an attribute pointing to the next data: next

The node itself also needs to store data, using an attribute to store: element

Use a linked list The behaviors of the structure generally include: add, delete, modify, query, clear

Recommended learning: "nodejs video tutorial"

The above is the detailed content of Does node have a linked list structure?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is the url of ajax Next article:What is the url of ajax