栈是一种特殊的列表,栈内的元素只能通过列表的一端访问,这一端称为栈顶。咖啡厅内的一摞盘子是现实世界中常见的栈的例子。只能从最上面取盘子,盘子洗净后,也只能摞在这一摞盘子的最上面。栈被称为一种后入先出(LIFO,last-in-first-out)
的数据结构。
import { Stack } from "gxc-js-data-structure";
// 不传参数为空栈
const stack1 = new Stack();
// 可传入一个数组转换为栈
const stack2 = new Stack([]);
const stack1 = new Stack();
stack1.push(5);
const stack1 = new Stack();
stack1.pop();
const stack1 = new Stack();
stack1.peek();
const stack1 = new Stack();
stack1.isEmpty(); // true or false
const stack1 = new Stack();
stack1.size;
const stack1 = new Stack();
stack1.toString();
import { Queue } from "gxc-js-data-structure";
const queue1 = new Queue();
// 或者传入初始数组
const queue2 = new Queue([]);
import { Queue } from "gxc-js-data-structure";
const queue = new Queue();
queue.enqueue(item);
import { Queue } from "gxc-js-data-structure";
const queue = new Queue();
queue.dequeue();
import { Queue } from "gxc-js-data-structure";
const queue = new Queue();
queue.front();
const queue = new Queue();
queue.isEmpty(); // true or false
const queue = new Queue();
queue.size; // true or false
const queue = new Queue();
queue.toString(); // true or false
import { LinkedList } from "gxc-js-data-structure";
const lList = new LinkedList();
lList.size
lList.isEmpty
lList.insert(item, index) // index为插入位置,默认为链表尾部
lList.update(item, index) // index为指定节点位置
lList.find(index) // index为需要获取节点的位置