This article describes the definition and usage of JavaScript linked lists. Share it for your reference, as follows:
Link List
oneLink Listis a linear set of data elements, and the linear order of elements is not given by their physical location in memory. Instead, each element points to the next element. It is a data structure composed of a group of nodes, which together represent a sequence.
One disadvantage of linked lists is that access times are linear (and difficult to pipe).
class Node { constructor(val) { = val; = null; } }
Show link list
function display () { var currNode = ; while ( !( == null) ){ ( ); currNode = ; } }
Find
function find ( item ) { var currNode = ; while ( != item ){ currNode = ; } return currNode; }
insert
function insert ( newElement , item ) { var newNode = new Node( newElement ); var currNode = ( item ); = ; = newNode; }
delete
function findPrev( item ) { var currNode = ; while ( !( == null) && ( != item )){ currNode = ; } return currNode; } function remove ( item ) { var prevNode = ( item ); if( !( == null ) ){ = ; } }
Interested friends can use itOnline HTML/CSS/JavaScript code running tool:http://tools./code/HtmlJsRunTest the above code running effect.
For more information about JavaScript, readers who are interested in reading this site's special topic:Summary of JavaScript mathematical operations usage》、《Summary of JavaScript data structure and algorithm techniques》、《Summary of JavaScript array operation skills》、《Summary of JavaScript sorting algorithm》、《JavaScript traversal algorithm and skills summary》、《Summary of JavaScript search algorithm skills"and"Summary of JavaScript Errors and Debugging Skills》
I hope this article will be helpful to everyone's JavaScript programming.