单向链表(双向链表)
想复习复习数据结构 自己写了个单向链表的数据结构,我觉得如果会写单向的,双向的也就不是问题了,给在学的小伙伴们写注释吧
```function listNode(node) {// 用来创建实例的 new它
function Node(val) {//用来创建实例的 这个写在链表里面 用来创建节点对象
this.val = val;//对象里的value
this.next = null;//链表结构嘛,下一个指向
}
this.node = new Node()//调用上面的方法创建对象 自己打印看看
this.node = new Node(node)
// 查找
this.find = function (target) {
let cur = this.node;//自己打印搞清楚this是什么就好了 cur就是当前 target就是你的参数想找那个后面自己思考吧一样的
console.log(11111,this.node)
while (cur.val != target) {
cur = cur.next;
if (!cur) {
return false
}
}
return cur
}
// 插入
this.insert = function (node, target) {
let newNode = new Node(node)
let cur = this.find(target)
newNode.next = cur.next;
cur.next = newNode
}
\
}
let list = new listNode('pyx')
list.insert('wyt', 'pyx')
console.log(list)
console.log(list.find('pyx'))
//自己动手打印打印,这样才能对链表的结构更加清楚,记忆更加深刻
希望你们的职业生涯顺利
*