class node {
next: null | node;
value: any;
constructor(value: any) {
this.value = value;
this.next = null;
}
}
class linkedList {
head: null | node;
length: number;
constructor() {
this.head = null;
this.length = 0;
}
insert(node: node) {
if (!this.head) {
this.length++;
this.head = node;
return;
}
node.next = this.head;
this.head = node;
this.length++;
}
delete(value: any) {
if (!this.head) {
throw Error('空链表, 无法删除');
}
let midHead = this.head;
if (midHead.value == value
JS链表的创建、插入、删除 以及链表合并
最新推荐文章于 2024-04-10 21:00:50 发布