xzz的驿站

各种排序算法的typescript实现

选择排序 /* 选择排序 */ function selectionSort(nums: number[]): void { let n = nums.length; // 外循环:未排序区间为 [i, n-1]

xzz2021 xzz2021 Published on 2026-04-11

typescript模拟实现特殊数据

双向链表(DoublyLinkedList): 头插入/尾插入/头删除/尾删除/指定插入/指定删除/获取指定项 class ListNode<T> { public val: T; public prev: ListNode<T> | null = n

xzz2021 xzz2021 Published on 2026-04-11

二叉树遍历方式

先定义二叉树,从上到下,根节点为1,左叶为2,右叶为3;左叶2的下一级左叶为4,右叶为5,依次类推 层序遍历: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] 左右横线左右横线 前序遍历: [ 1, 2, 4, 7, 8, 5, 3, 6, 9, 10 ] 左下右上左下右上斜线

xzz2021 xzz2021 Published on 2026-04-03

集合的运算分析及实现

集合的运算分析及模拟实现 概念: 并集: 两者包含的所有元素 // 模拟实现 const union = (setA, setB) => { const unionAB = new Set() setA.forEach(

xzz2021 xzz2021 Published on 2024-02-19