当前位置: 首页 > Web前端 > JavaScript

【数据结构】JavaScriptLinkedList实现

时间:2023-03-27 00:41:05 JavaScript

完整可运行代码classNode{constructor(data){this.data=datathis.next=null}}classLinkedList{constructor(){this.head=nullthis.length=0}append(data){constnewNode=newNode(data)if(this.length===0){this.head=newNode}else{让current=this.headwhile(current.next){current=current.next}current.next=newNode}this.length++}}//constlinkedList=newLinkedList()linkedList.append('AA')linkedList.append('BB')linkedList.append('CC')console.log(链表)