单链表遍历publicstaticvoidforLinked(Linkedlinked){Linkedtemp=linked;while(temp!=null){temp=temp.nextNode;}}添加publicstaticvoidaddLinked(Linkedlinked,intdata){LinkednewNode=newLinked(data);链接温度=链接;while(temp.nextNode!=null){temp=temp.nextNode;}temp.nextNode=newNode;}insertpublicstaticvoidinsertLinked(Linkedlinked,intvalue,intindex){LinkednewNode=newLinked(value);链接温度=链接;while(temp!=null){索引--;if(index==1){newNode.nextNode=temp.nextNode;temp.nextNode=newNode;}else{temp=temp.nextNode;}}}deletepublicstaticvoiddeleteLinked(Linkedlinked,intindex){Linkedtemp=linked;while(temp!=null){索引--;如果(索引==1){温度。nextNode=temp.nextNode.nextNode;}else{temp=temp.nextNode;}}}重点是用指针指向头节点,遍历指针
