In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is to share with you about the linked list in JavaScript, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Write at the front
What is a linked list and the linked list in JavaScript? then we will use the language JavaScript to implement the design of all kinds of linked lists. Finally, we will throw out some general questions and answer them one by one from all aspects. In short, the purpose is to complete the linked list.
After getting the concept done, we can go to the button to select the list classification, and brush them according to the degree of difficulty. The title of the linked list is relatively simple. As long as you have read the linked list design of this article completely, you can at least easily get rid of 20 questions. At the same time, the number of linked list topics is relatively small, there are a total of about 50 questions, and there are more than a dozen questions for members, that is to say, 40 questions. Linked list of this data structure can be preliminarily mastered, if you do not want to sort questions, you can according to my GitHub algorithm warehouse in the order of doing exercises, there are not quite understand questions or concepts can see I wrote the solution, at the same time, I also recorded a video, there are links at the end of the article, so let's start to learn linked lists, GO!
What is a linked list
Usually we want to store multiple elements in a program, and array is probably the most commonly used data structure. Array is a very convenient data structure, and it can even access its elements in a very simple way, that is, the syntax [].
The linked list also stores an ordered collection of elements, but unlike arrays, the elements in the linked list are not continuous in memory. Each element consists of a node that stores the element itself and a reference (also known as a pointer) to the next element.
Let's move on to the data structure of arrays, which has one drawback: in most languages, the size of an array is fixed, and it is expensive to insert or remove items from the beginning or middle of the array because you need to move elements, as shown in the following figure
If the above array deletes an element with an index of 2 and a value of 3, then we first delete the element 3, because the element with an index of 2 and 3 is deleted, and index 2 is empty, so then, we need to move index 3, that is, element 4, forward one bit, while the latter element 5 needs to move forward one bit, and inserting an element into the array is the same reason. As long as one bit is missing or more than one bit in the array, the following elements will move forward or backward one bit in turn, so it is conceivable that when the length of the array is very large, the efficiency of insertion and deletion will gradually decrease.
Let's look at the linked list again.
Also to delete element 3, the linked list only needs to iterate to the node with a value of 3, and point node 2 to node 4. If node 3 has no reference relationship, it will be regarded as garbage collection by the garbage collection mechanism. even when there are a lot of nodes, you only need to change the reference relationship to delete the element, while the insertion element is the other way around, that is, to disconnect the elements on both sides of the insertion position first. Then let the previous element point to the insert element, and the insert element points to the next element. The more elements, the more efficient the comparison array will be.
Compared with traditional arrays, one of the advantages of linked lists is that there is no need to move other elements when adding or removing elements, but in arrays, we can directly access any element anywhere, not in linked lists. Because each node in the linked list only has a reference to the next node, so you want to access an element in the middle of the linked list. It is important to note that you have to iterate through the linked list from the starting point (the list header node) until you find the desired element
Linked list in JavaScript
Above we briefly introduced the concept of regular linked lists, but how do we represent linked lists in the language JavaScript?
Since there is no built-in linked list in JS, we need to use objects to simulate the linked list, just as we introduced the linked list above, it is actually an one-way linked list, in addition to the two-way linked list, circular linked list and so on, we will introduce them one by one and use JavaScript to implement them.
Unidirectional linked list
Let's first look at the basic single-item linked list. Each element in the one-way linked list consists of a node that stores the element itself and a pointer to the next element, as shown in the following figure.
To realize the data structure of linked list, the key is to save the head element (that is, the head element of the linked list) and the next pointer of each element. With these two parts, we can easily traverse the linked list and manipulate all the elements. You can think of the linked list as a chain, and every node in the chain is connected to each other. As long as we find the head of the chain, the whole chain can be found. So how to simulate the one-way linked list in JS? let's do it step by step.
First of all, we want to create a class, which is used to describe the node of the linked list, it is very simple, only need to have two attributes, one to hold the value of this node, one to hold the pointer to the next node, as follows
/ * * @ description: create chain form node class * @ param {*} val node value * @ return {*} * / function ListNode (val) {this.val = val this.next = null}
Next, we need to write a linked list class, where the length attribute represents the length of the linked list and the head attribute represents the header node of the linked list.
/ * * @ description: create a linked list class * @ param {*} * @ return {*} * / function LinkedList () {this.length = 0 this.head = null}
Let's think about it, since we're here to simulate a linked list class, we should stuff all the features it might use into this class, such as an array with push/splice/indexOf/.... Wait, these useful methods we linked list must also have, ah, let's carefully think about which practical features or methods to add to the linked list, first build a basic skeleton, here I list a lot, let's implement them one by one, also welcome to add
/ / append node LinkedList.prototype.append = function (val) {} / / insert node LinkedList.prototype.insert = function (index, val) {} / / delete the element at the specified location in the linked list And return the value of this element LinkedList.prototype.removeAt = function (index) {} / delete the corresponding element in the linked list LinkedList.prototype.remove = function (val) {} / / get the index LinkedList.prototype.indexOf = function (val) {} / / get a node in the linked list LinkedList.prototype.find = function (val) {} / / get the index in the linked list The corresponding element LinkedList.prototype.getElementAt = function (index) {} / / determines whether the linked list is empty LinkedList.prototype.isEmpty = function () {} / / gets the length of the linked list LinkedList.prototype.size = function () {} / / gets the header element LinkedList.prototype.getHead = function () {} / / clears the linked list LinkedList.prototype.clear = function () {} / / sequence Chemical linked list LinkedList.prototype.join = function (string) {}
GetElementAt (index)
Let's first implement the getElementAt method to get the elements corresponding to the index in the linked list and the find method to get the linked list elements through node values, because we will use them many times later, let's talk about the getElementAt method first. We said above that if we want to find an element, we have to iterate from the beginning, so we can iterate directly based on the incoming index.
First, determine the boundary value of the parameter index. If the value is out of the range of the index (less than 0 or greater than length-1), return null. Isn't it easy for us to start with the head node of the linked list, traverse the entire linked list until we find the node at the corresponding index location, and then return this node? Like all ordered data sets, the index of the linked list starts from 0. As long as there is a header node of the linked list, you can traverse to find the element where the index is located, so we save the head value in the constructor, that is, the LinkedList class.
/ / get the element LinkedList.prototype.getElementAt = function (index) {if (index) corresponding to the index in the linked list
< 0 || index >= this.length) return null let cur = this.head while (index--) {cur = cur.next} return cur}
Find (val)
The find method is similar to the getElementAt method, one looks for the element through the index, the other finds the element through the node value, so we can iterate to find and compare it directly.
/ / get a node in the linked list LinkedList.prototype.find = function (val) {let cur = this.head while (cur) {if (cur.val = = val) return cur cur = cur.next} return null}
Append (val)
Now that we have the getElementAt method, we can easily implement the append method, which appends elements to the end of the list
This method passes in a value, and we can create a new node through the constructor ListNode above
Then, we need to consider that if the head of the linked list is null, this means that the linked list is empty, so we need to point the head node to the newly added element to ensure that the storage header node is stored. If it is not empty, we find the last node of the linked list through the getElementAt method, and the index of the last node is the list length length attribute of our store in the constructor minus 1. Then point the next pointer of the last node to the newly added element.
The newly added element next pointer defaults to null, and the next value of the last element of the linked list is null. In addition, after the node is attached to the linked list, add 1 to the length of the linked list to ensure that the length attribute is equal to the length of the linked list, as shown below.
/ / append node LinkedList.prototype.append = function (val) {let node = new ListNode (val) if (! this.head) {this.head = node} else {let cur = this.getElementAt (this.length-1) cur.next = node} this.length++} to the linked list
Insert (index, val)
Next we will implement the insert method, which adds nodes anywhere in the linked list
To insert an element at a specified location, we first need to determine whether the incoming index index exceeds the boundary.
Then we consider it in two situations.
When the value of index is 0, you want to insert a new node in the head of the linked list, point the next pointer of the newly inserted node to the current head, and then update the value of head to the newly inserted node, as shown below.
When the value of index is not 0, that is, the inserted node is in the middle or tail of the linked list, we first find the previous node prevNode in the location to be inserted, then point the next pointer of the new node newNode to the node corresponding to the next of prevNode, and then point the next pointer of prevNode to newNode, so that the new node is inserted into the linked list. When the inserted node is at the end of the linked list, this method is also applicable, as shown in the following figure.
Finally, we insert the node and add 1 to the length of the linked list, that is, the length of the length. The code is as follows
/ / insert node LinkedList.prototype.insert = function (index, val) {if (index) at the specified location in the linked list
< 0 || index >This.length) return false let node = new ListNode (val) if (index = 0) {node.next = this.head this.head = node} else {let prev = this.getElementAt (index-1) node.next = prev.next prev.next = node} this.length++ return true}
RemoveAt (index)
In the same way, we can easily write the removeAt method to delete the node at the specified location in the linked list
Still, let's first determine whether the incoming index index exceeds the boundary.
There are still two situations.
If the node to be deleted is the head of the linked list, move head to the next node. If there is only one node in the current linked list, then the next node is null. Pointing head to the next node is equivalent to setting head to null. After deletion, the linked list is empty.
If the node to be deleted is in the middle of the linked list, we need to find the previous node where the index is located and point its next pointer to the next node where the index is located. In short, to delete the node, you only need to modify the pointer of the corresponding node, disconnect the adjacent nodes to the left and right of the deletion position, and then reconnect.
Image-20201227180444604
The deleted node has no reference relationship, and the JavaScript garbage collection mechanism will deal with it. The garbage collection mechanism is also beyond the scope of this article. Just know that the node element is deleted, and we also need to reduce the length of the linked list by 1. The final code is as follows
/ / deletes the element at the specified location in the linked list and returns the value of this element LinkedList.prototype.removeAt = function (index) {if (index)
< 0 || index >= this.length) return null let cur = this.head if (index = 0) {this.head = cur.next} else {let prev = this.getElementAt (index-1) cur = prev.next prev.next = cur.next} this.length-- return cur.val}
IndexOf (val)
Get the index of a given element in the linked list. This is relatively simple and can be iterated directly. Matching returns the corresponding index, but matching does not return-1.
/ / get the index LinkedList.prototype.indexOf = function (val) {let cur = this.head for (let I = 0; I) of the given element in the linked list
< this.length; i++) { if (cur.val === val) return i cur = cur.next } return -1 } remove(val) 删除链表中对应的元素,有了之前的铺垫,这里就比较简单了,我们可以直接用 indexOf 方法拿到对应索引,再使用 removeAt 方法删除节点即可 // 删除链表中对应的元素 LinkedList.prototype.remove = function (val) { let index = this.indexOf(val) return this.removeAt(index) } isEmpty() 判断链表是否为空,只需要我们判断一下链表长度 length 等不等于 0 即可 // 判断链表是否为空 LinkedList.prototype.isEmpty = function () { return !this.length } size() 获取链表长度就是取其 length // 获取链表的长度 LinkedList.prototype.size = function () { return this.length } getHead() 获取链表的头元素即返回 head 属性即可 // 获取链表的头元素 LinkedList.prototype.getHead = function () { return this.head } clear() 清空链表,我们只需要将 head 置空,然后让 length 等于 0,等待垃圾回收机制回收无引用的废弃链表即可 // 清空链表 LinkedList.prototype.clear = function () { this.head = null this.length = 0 } join(string) 序列化链表即使用指定格式输出链表,类似于数组中 join 方法,此举旨在便于我们测试 // 序列化链表 LinkedList.prototype.join = function (string) { let cur = this.head let str = '' while (cur) { str += cur.val if (cur.next) str += string cur = cur.next } return str } 那么到此,我们的单向链表类就设计完成了,快来测试一下吧,我们输入下面代码进行测试 let linkedList = new LinkedList() linkedList.append(10) linkedList.append(20) linkedList.append(30) console.log(linkedList.join("--")) linkedList.insert(0, 5) linkedList.insert(2, 15) linkedList.insert(4, 25) console.log(linkedList.join("--")) console.log(linkedList.removeAt(0)) console.log(linkedList.removeAt(1)) console.log(linkedList.removeAt(2)) console.log(linkedList.join("--")) console.log(linkedList.indexOf(20)) linkedList.remove(20) console.log(linkedList.join("--")) console.log(linkedList.find(10)) linkedList.clear() console.log(linkedList.size()) 最终输出如下 // 10--20--30 // 5--10--15--20--25--30 // 5 // 15 // 25 // 10--20--30 // 1 // 10--30 // ListNode { val: 10, next: ListNode { val: 30, next: null } } // 0 上面代码中少了一些参数校验,不过够我们学习用了,完成代码文末附链接 双向链表 上面我们说了单向链表,接下来我们来说双向链表,那么什么是双向链表呢?其实听名字就可以听出来,单向链表中每一个元素只有一个 next 指针,用来指向下一个节点,我们只能从链表的头部开始遍历整个链表,任何一个节点只能找到它的下一个节点,而不能找到它的上一个节点,双向链表中的每一个元素拥有两个指针,一个用来指向下一个节点,一个用来指向上一个节点,双向链表中,除了可以像单向链表一样从头部开始遍历之外,还可以从尾部进行遍历,如下图 同单向链表,我们首先创建链表节点类,不同的是,它需要多一个 prev 属性用来指向前一个节点 /** * @description: 创建双向链表单节点类 * @param {*} val 节点值 * @return {*} */ function ListNode(val) { this.val = val this.next = null this.prev = null } 双向链表类同单向链表多增加了一个尾部节点 tail /** * @description: 创建双向链表类 * @param {*} * @return {*} */ function DoubleLinkedList() { this.length = 0 this.head = null this.tail = null } 接下来我们来实现双向链表的原型方法 getElementAt(index) 首先就是,获取双向链表中索引所对应的元素,双向链表由于可以双向进行迭代查找,所以这里 getElementAt 方法我们可以进行优化,当索引大于链表长度 length/2 时,我们可以从后往前找,反之则从前向后找,这样可以更快找到该节点元素 // 获取双向链表中索引所对应的元素 DoubleLinkedList.prototype.getElementAt = function (index) { if (index < 0 || index >= this.length) return null let cur = null if (index > Math.floor (this.length / 2)) {/ / from back to front cur = this.tail let I = this.length-1 while (I > index) {cur = cur.prev imuri -}} else {/ / from back to back cur = this.head while (index--) { Cur = cur.next}} return cur}
Find (val)
The find method is similar to the getElementAt method, and the getElementAt method can be optimized, then the find can also be optimized after it is transformed into a two-way linked list. We think that since iterations can be carried out in both directions, wouldn't it be faster for us to iterate on both sides at the same time? in the case of two-way iteration, the whole linked list can be iterated only if it can not be found, which is more efficient.
/ / get a node in the bidirectional linked list DoubleLinkedList.prototype.find = function (val) {let curHead = this.head let curTail = this.tail while (curHead) {if (curHead.val = = val) return curHead curHead = curHead.next if (curTail.val = = val) return curTail curTail = curTail.prev} return null}
Append (val)
When it comes to our additional node elements, there is still some difference between two-way linked list append and one-way linked list.
When the linked list is empty, in addition to pointing the head to the currently added node, you should also point the tail to the currently added node
When the linked list is not empty, directly point the next of tail to the node node to be added, then modify the prev of node to point to the old tail, and finally modify tail to the newly added node
For the append operation of two-way linked list, we do not need to traverse the whole linked list from scratch. We can find the tail of the linked list directly through tail, which is more convenient than the operation of one-way linked list. Finally, we can add 1 to the value of length and modify the length of the linked list.
/ / append node DoubleLinkedList.prototype.append = function (val) {let node = new ListNode (val) if (this.head = null) {/ / to the bidirectional linked list. Both head and tail point to the currently added node this.head = node this.tail = node} else {/ / the linked list is not empty. Add the current node to the tail of the linked list this.tail.next = node node.prev = this.tail this.tail = node} this.length++}
Insert (index, val)
Then there is the method of inserting node elements, which is the same way of thinking, but it is not difficult. We pay attention to the discussion of tail and prev pointers, and add 1 to the length after insertion.
/ / insert node DoubleLinkedList.prototype.insert = function (index, val) {if (index) at the specified location of the two-way linked list
< 0 || index >This.length) return false / / insert into tail if (index = this.length) {this.append (val)} else {let node = new ListNode (val) if (index = 0) {/ / insert into head if (this.head = null) {this.head = node this.tail = node} else {node.next = this.head This.head.prev = node this.head = node}} else {/ / insert in the middle position let curNode = this.getElementAt (index) let prevNode = curNode.prev node.next = curNode node.prev = prevNode prevNode.next = node curNode.prev = node} this.length++} return true}
RemoveAt (index)
Delete the elements at the specified position in the two-way linked list, also pay attention to the discussion of tail and prev pointers, and then subtract the length by 1 after deletion
/ / deletes the element at the specified location in the two-way linked list and returns the value of this element DoubleLinkedList.prototype.removeAt = function (index) {if (index)
< 0 || index >= this.length) return null let current = this.head let prevNode if (index = 0) {/ / remove header element this.head = current.next this.head.prev = null if (this.length = 1) this.tail = null} else if (index = this.length-1) {/ / remove tail element current = this.tail this.tail = current.prev this.tail.next = null } else {/ / remove the intermediate element current = this.getElementAt (index) prevNode = current.prev prevNode.next = current.next current.next.prev = prevNode} this.length-- return current.val}
IndexOf (val)
Look up the element index in the two-way linked list, and with the above find method to lay the groundwork, it is simple and consistent.
/ / get the index DoubleLinkedList.prototype.indexOf = function (val) {let curHead = this.head let curTail = this.tail let idx = 0 while (curHead! = curTail) {if (curHead.val = = val) return idx curHead = curHead.next if (curTail.val = = val) return this.length-1-idx curTail = curTail.prev idx++} return-1} of the given element in the two-way linked list
Joinstring)
We can serialize the linked list in accordance with the one-way linked list above.
/ serialize bi-directional linked list DoubleLinkedList.prototype.join = function (string) {let cur = this.head let str =''while (cur) {str + = cur.val if (cur.next) str + = string cur = cur.next} return str}
That's all we'll introduce about the two-way linked list, and the rest of the method is relatively simple, so I won't repeat it. There is a complete code in the two-way linked list case at the end of the article.
Again, let's briefly test whether it's right or not.
Let doubleLinkedList = new DoubleLinkedList () doubleLinkedList.append (10) doubleLinkedList.append (15) doubleLinkedList.append (20) doubleLinkedList.append (25) console.log (doubleLinkedList.join (")) console.log (doubleLinkedList.getElementAt (0) .val) console.log (doubleLinkedList.getElementAt (1) .val) console.log (doubleLinkedList.getElementAt (5) console.log (doubleLinkedList.join (") console.log (doubleLinkedList.indexOf (10) console.log (doubleLinkedList.indexOf (25)) console.log ( DoubleLinkedList.indexOf (50)) doubleLinkedList.insert (0 5) doubleLinkedList.insert (3,18) doubleLinkedList.insert (6,30) console.log (doubleLinkedList.join (")) console.log (doubleLinkedList.find (10) .val) console.log (doubleLinkedList.removeAt (0)) console.log (doubleLinkedList.removeAt (1)) console.log (doubleLinkedList.removeAt (5) console.log (doubleLinkedList.remove (10)) console.log (doubleLinkedList.remove (100)) console.log (doubleLinkedList.join ("))
The above code output is as follows
/ / 10152025 / / 10 / / 15 / / null / / 10152025 / / 0 / / 3 / / 1 / / 5101518202530 / / 10 / 5 / 15 / null / 10 / null / / 18202530
Well, there's no mistake. A simple comparison is correct, No Problem.
Circular linked list
Let's look at another kind of linked list, the circular linked list. As the name implies, the tail node of the circular linked list points to its own head node.
Circular linked lists have one-way circular linked lists or two-way circular linked lists, as shown in the following figure
We will no longer write one by one here. You can try to write it yourself. Compared with our circular list above, we only need to pay attention to the lower tail node pointing to the head node.
Why is there no linked list built into JavaScript?
According to what we said above, linked lists have so many advantages, so why doesn't the language JavaScript have built-in data structures like linked lists?
In fact, in JS, arrays achieve almost all the functions of linked lists, so there is no need to bother again. You may be confused when you hear this. Doesn't it say that arrays do not perform as well as linked lists in some cases (such as header insertion, etc.)?
Let's speak with the facts, and now we use the one-way linked list class LinkedList completed above to do a simple time test with the native array.
Let linkedList = new LinkedList () let arr = [] / / Test attempts "Total 100000 insert nodes 50" / "Total 100000 insert nodes 50000" let count = 100 let insertIndex = 50 / / let count = 100000 / / let insertIndex = 50000 console.time ('linked list push operation') for (let I = 0; I < count) LinkedList.append +) {linkedList.append (I)} console.timeEnd ('linked list push operation') console.time ('array push operation') for (let I = 0; I < count ITunes +) {arr.push (I)} console.timeEnd ('array push operation') console.time ('linked list insert operation') linkedList.insert ('test node', insertIndex) console.timeEnd ('linked list insert operation') console.time ('array insert operation') arr.splice (insertIndex, 0 'test node') console.timeEnd ('array insert operation') console.time ('linked list remove operation') linkedList.removeAt (insertIndex) console.timeEnd ('linked list remove operation') console.time ('array remove operation') arr.splice (insertIndex, 1) console.timeEnd ('array remove operation')
Let's look at the results.
Append 100 pieces of data, insert elements in index 50, and then delete inserted elements
Append 100000 pieces of data, insert elements in index 50000, and then delete inserted elements
What?
From the test results, we can see that the performance of the native Array still crushes the linked list regardless of the small order of magnitude of cardinality 100 or the large order of magnitude of radix 100000.
That is to say, the efficiency of linked lists is higher than that of arrays, in fact, it does not exist in JS. Even if you create an array with a length of 100 million, then create an array with a length of 10, and add elements to the middle of the two arrays, you will find that the time used has nothing to do with the length of the array, which shows that the JS array meets the efficiency requirements of the linked list.
And in the array, we can also use the splice () method to add and delete elements to the specified position of the array. The test shows that the time required is also independent of the length of the array and can also meet the requirements of the linked list, while the subscript of the array can completely replace the head,tail,next,prev and other methods of the linked list, and in most cases it will be more convenient, coupled with the fact that there are not too many scenarios in which linked lists are used. So it can be said that the array in JS is full of linked lists.
Of course, this is only limited to the JavaScript language, which is related to the array implementation mechanism within JS. In fact, the array in JS is just called array, which is different from the concept of array in conventional language. Then the concept of array and its internal implementation are not within the scope of our discussion in this chapter. Leave a question first, and then start another article related to JS array when you have time in a few days. In fact, it is best to find the answer yourself. We say that JS is an interpretive high-level language, and its underlying implementation is not as simple and conformist as we seem.
Here, you may complain that it is not easy to finish this article, and now you tell me it is useless. Don't worry, put away the rotten eggs
Is the linked list useless in JavaScript?
As we said above, is it true that linked lists in JavaScript are useless?
In fact, it is not. For example, the Fiber architecture in React, one of the three magic weapons, uses linked lists as a data structure.
Fiber in English means fibrosis, that is, refinement, which divides a time-consuming task into many small pieces, each of which has a short running time, although the total time is still very long, but after each small piece is executed, it gives other tasks a chance to execute, so that the only thread will not be monopolized, and other tasks still have a chance to run. The Fiber in React fragmented the update process of the entire VDOM.
Previously, the render () method in React will receive a virtual DOM object and a real container DOM as the mount node after the virtual DOM rendering is completed. Its main function is to render the virtual DOM into a real DOM and mount it under the container. This method is recursive when updating. If there are a large number of nodes that need to be updated in the process of update, it will occupy the main thread of JS for a long time. And the whole recursive process can not be interrupted, because the JS thread and the GUI thread are mutually exclusive (see "hardcore JS" in detail), so you may see that the interface is somewhat stuttered in the case of a large number of updates.
Fiber architecture actually solves two problems: one is to ensure that the task is executed when the browser is idle, and the other is to fragment the task. Next, let's briefly talk about Fiber.
There is an experimental method requestIdleCallback (callback) in JS, which can pass in a callback function. The callback function can receive a deadline object, and the free time of the current browser can be obtained through the timeRemaining () method of the object. If there is free time, then a short period of tasks can be executed. If there is not enough time, continue requestIdleCallback and wait until the browser has free time again. This enables execution when the browser is idle.
But the virtual DOM is a tree structure, and when the task is interrupted, the tree structure cannot restore the previous task, so we need a new data structure, that is, our linked list, which can contain multiple pointers. The linked list adopted by Fiber contains three pointers, parent points to its parent Fiber node, child points to its child Fiber node, sibling points to its sibling Fiber node, and a Fiber node corresponds to a task node. In this way, the next node can be easily found, and then the execution of the task can be resumed.
This simple paragraph is the famous Fiber architecture, so do you think linked lists are useful?
Having said so much, in fact, for ordinary requirements, we JS really do not need to use linked lists, arrays can complete it, but in special requirements, linked lists have certain advantages, in short, three words, look at the requirements, moreover, we are now using JS to explain linked lists, but other conventional languages are not as powerful as arrays in JS, and with linked lists, we will be more comfortable with the next tree structure.
The above is what the linked list in JavaScript is like. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.