链表和数组数组是一系列有序的排列,链表不能直接标记为索引值。链表类的实现1.定义一个类,它有自己的属性,必须有一个长度和一个表头。类LinkList{构造函数(){这个。length=0this.head=null}}2.需要有一个查找方法,后面的增删改查也需要用到getElementAt(position){//做一个校验提高效率if(position<0||position>=this.length)returnnullletcurrent=this.headfor(leti=0;ithis.length)returnfalseletnode=newNode(元素)如果(位置===0){node.next=this.headthis.head=node}else{//找到之前的位置letprevious=this.getElementAt(position-1)//1->3=>>2->3node.next=previous.next//1->2previous.next=node//1->2->3}this.length++returntrue}4.移除方法removeAt(position){if(position<0||position>this.length)returnfalseletcurrent=this.headif(position===0){this.head=current.next}else{//找到上一个索引值letprevious=this.getElementAt(positoin-1)//找到索引值,2current=previous.next//上一个索引值直接指向下一个索引值,即跳过索引值//1->2->3=>>1->3previous.next=current.next}this.length--returncurrent.element}5.根据value找到索引indexOf(element){letcurrent=this.headfor(leti=0;i=this.length)returnnull;让current=this.head;for(leti=0;ithis.length)returnfalse;让节点=新节点(元素);if(position===0){node.next=this.head;this.head=节点;}else{letprevious=this.getElementAt(position-1);node.next=previous.next;前一个.下一个=节点;}这个长度++;返回真;}removeAt(位置){如果(位置<0||位置>this.length)返回false;让current=this.head;if(position===0){this.head=current.next;}else{letprevious=this.getElementAt(position-1);当前=上一个.下一个;上一个.下一个=当前.下一个;}this.length--;返回当前元素;}indexOf(元素){让current=this.head;for(leti=0;i