前言
一、链表是什么?
链表是一种物理存储单元上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。
二、使用步骤
1.创建单向链表
代码如下(示例):
class Node{
constructor(data){
this.data=data
this.next=null
}
}
class linklisted{
constructor(data){
this.head=null
this.length=0
}
append(value){
let node=new Node(value)
if(this.head==null){
this.head=node
this.length++
}else{
let current=this.head
while(current.next){
current=current.next
}
current.next=node
this.length++
}
}
2.创建链表并往里面插入元素往链表里面插入元素
代码如下(示例):
let list=new linklisted()
list.append(1