Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the function of linked list by nodejs

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to achieve linked list function in nodejs". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "nodejs how to achieve linked list function" bar!

The implementation of the linked list is relatively simple, there are several modules use this function, timer is one of them.

'use strict'

Function init (list) {

List._idleNext = list

List._idlePrev = list

}

/ / Show the most idle item.

Function peek (list) {

If (list._idlePrev = list) return null

Return list._idlePrev

}

/ / Remove an item from its list.

Function remove (item) {

/ / item comes out completely, and the front and rear nodes are connected. Because there is no head and tail pointer, it does not need to be updated.

If (item._idleNext) {

Item._idleNext._idlePrev = item._idlePrev

}

If (item._idlePrev) {

Item._idlePrev._idleNext = item._idleNext

}

/ / reset the front and rear pointers

Item._idleNext = null

Item._idlePrev = null

}

/ / Remove an item from its list and place at the end.

/ / head insertion

Function append (list, item) {

If (item._idleNext | | item._idlePrev) {

Remove (item)

}

/ / Items are linked with _ idleNext-> (older) and _ idlePrev-> (newer)

/ / Note: This linkage (next being older) may seem counter-intuitive at first.

Item._idleNext = list._idleNext

Item._idlePrev = list

/ / The list _ idleNext points to tail (newest) and _ idlePrev to head (oldest).

List._idleNext._idlePrev = item

List._idleNext = item

}

Function isEmpty (list) {

Return list._idleNext = list

}

Module.exports = {

Init

Peek

Remove

Append

IsEmpty

}

At this point, I believe that everyone on the "nodejs how to achieve linked list function" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report