Skip to content

数组中增加数据

  • push
  • unshift

splice

javascript
const a = [1,3]

a.splice(1,0, 2) // [1,2,3]

数组中删除数据

  • shift
  • pop
  • splice

先进后出 push pop

队列

先进先出 push shift

链表

链表的的构造函数

javascript
function ListNode(n) {
	this.value = n;
	this.next = null;
}

链表创建

javacript
const node1 = new ListNode(1);
node1.next = new ListNode(2);

链表元素的添加

javascript
const nodeInsert = new ListNode(100);

nodeInsert.next = node1.next;

node1.next = nodeInsert;

链表元素的删除

自动 gc

javascript
node1.next = nodeInsert.next;

nodeInset.next = null;

二叉树

javascript

function TreeNode(n) {
	this.value = n;
	this.left = this.right = null;
}

const node = new TreeNode(1);