随笔分类 - 使用 JavaScript 实现算法
摘要:
利用齐次坐标进行坐标转换 Games 101 第0次作业可视化表示 作业要求:给定一个点 P=(2,1), 将该点绕原点先逆时针旋转 45°,再平移 (1,2), 计算出 变换后点的坐标(要求用齐次坐标进行计算) 目的 了解齐次坐标表示矩阵的意义 使用 threejs 和 tweenjs 模拟坐标转
阅读全文

摘要:
算法--希尔排序可视化 一直都想做各种数据可视化 现用工具 echarts 做排序过程可视化 希尔排序 算法性能取决于 h function shellSort(array) { const N = array.length; let h = 1; while (h < N / 3) h = 3 *
阅读全文

摘要:JS设计模式之单例模式 单例模式--保证一个类仅有一个单例 1. 简单单例模式 // 简单单例模式 const Singleton = function (name) { this.name = name; }; Singleton.instance = null; Singleton.getIns
阅读全文
摘要:// 另存一个数组 function insertSort(arr){ const temArr = []; temArr[0] = arr[0]; for (let i = 1; i < arr.length; i++) { for(let j = i-1; j>=0; j--){ if(temA
阅读全文
摘要:function selectSort(arr){ for (let i = 0; i < arr.length; i++) { for (let j = i ; j < arr.length; j++){ if (arr[i] > arr[j]) { let tem = arr[i]; arr[i
阅读全文
摘要:/** * quick-find 算法, find 操作速度很快, find 只需要返回 id[X], * 但它无法处理大型问题, 因为它在每一次 union 时都要扫描整个数组 */ const inquirer = require("inquirer"); class UF{ construct
阅读全文
摘要:JavaScript 算法 1_3 生成器函数实现迭代功能 以算法 1_1 为例 类定义 // 类定义 class Stack{ constructor() { // 栈顶元素, 包括 next 和 ele this.first = null; this.count = 0; } isEmpty()
阅读全文
摘要:JavaScript 算法 1_2 先进先出队列 (链表实现) 队列, 先进先出, 和食堂排队打饭类似 1. 类定义 // 类定义 class Queue{ constructor() { // 队头元素, 包括 next 和 ele this.first = null; // 队尾元素 this.
阅读全文
摘要:JavaScript 算法 1_1 下压堆栈 (链表实现) 链表是一种递归的数据结构 1. 节点结构 node = { ele: null, next: null, } 这里使用了 ele 作为一个节点的元素内容, next 作为下个节点的索引 2. 构造链表 let next = {}; Obje
阅读全文