<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
//Node类:element用来保存节点上的数据,next用来保存指向下一个节点的链接。使用构造函数创建节点:
function Node(element)
{
this.element=element;
this.next=null;
}
//该类的功能包括插入删除节点、在列表中查找给定的值。
function LList()
{
this.head=new Node('head');//使用一个Node对象来保存该链表的头节点,head节点的next属性被初始化为null,当有新元素插入时,next会指向新的元素
this.find=find;
this.insert=insert;
this.remove=remove;
this.findPrevious=findPrevious;
this.display=display;
}
//插入新节点:向链表中插入一个节点,需要修改它前面的节点(前驱),使其指向新加入的节点,而新加入的节点则指向原来前驱指向的节点
//find方法:遍历链表,查找给定数据。如果找到数据,该方法就返回保存该数据的节点()
function find(item)//在已知节点的后面插入
{
v
单向链表实现:插入节点、删除节点操作
最新推荐文章于 2024-05-03 10:09:31 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)