自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(141)
  • 资源 (1)
  • 收藏
  • 关注

原创 数据结构 js 实现avl平衡树

/** * 平衡二叉搜索树 avl */let alert = console.log;// console.log = () => {};class TreeNode { constructor(value, leftNode, rightNode) { this.value = value; this.leftNode = leftNode; this.rightNode = rightNode; }}/** * 1、创建 create(){}

2022-05-25 19:27:27 244

原创 数据结构 js 判断二叉树是不是一棵平衡树

/** * 判断一棵树是不是 avl平衡树 */const { tree } = require("./utils/BinarySearchTree");function isAvlTree(root) { if (root == undefined || root == null) { return { level: 0, isAvl: true, }; } let leftDelta = isAvlTree(root.leftNode);

2022-05-23 20:27:42 244

原创 数据结构 js 翻转二叉树

/** * 翻转二叉树 */const { tree } = require("./utils/BinarySearchTree");/** * 翻转树 */function reverseTree(root) { if (root == undefined || root == null) { return; } let queue = []; root.level = 1; queue.push(root); while (queue.length)

2022-05-23 20:25:36 472

原创 数据结构 js获取树的最大层次

/*** * 获取树的最大层级 */const { tree } = require("./utils/BinarySearchTree");/*** * 遍历方式获取树的最大层次 */function getTreeMaxLevel(root) { if (!root.leftNode && !root.rightNode) { return 1; } let maxLeftLevel = 0; if (root.leftNode) { m

2022-05-21 17:45:08 805

原创 数据结构 js获取树的最小层次

/*** * 获取树的最小层级 */const { tree } = require("./utils/BinarySearchTree");/** * 通过递归遍历的方式来获取最小层级 * */function getTreeMinLevel(root) { //表明是个叶子节点,就返回。 if (!root.leftNode && !root.rightNode) { return 1; } let leftLevel = Number.POS

2022-05-21 17:42:59 645

原创 数据结构 js 非递归形式的后序遍历

/** * 非递归形式的后序遍历 */const { tree } = require("./utils/BinarySearchTree");let stack = [];let preNode;function postOrderDisplayByStack(root, str = "") { while (root || stack.length) { //找到最左节点 while (root) { stack.push(root); root

2022-05-21 16:36:28 180

原创 数据结构 js 非递归形式的中序遍历

const { tree } = require("./utils/BinarySearchTree");//非递归形式的中序遍历//因为 console.log 会换行,不能将所有内容收集成一行。所以使用 str 来收集要打印的内容。/** * 进行 */let stack = [];function InOrderDisplayByStack(root, str = "") { if (root == undefined || root == null) { return

2022-05-21 15:06:15 120

原创 数据结构 js 实现层序遍历

const { tree } = require("./utils/BinarySearchTree");function levelOrderDisplay(root, str = "") { if (root == undefined || root == null) { return ""; } let queue = []; queue.push(root); //定义一个队列,将元素按照层级进入队列,出队列;当队列为空时,树的遍历完成。 while (queu

2022-05-21 10:27:52 464

原创 数据结构 js 实现递归后序遍历

const { tree } = require("./utils/BinarySearchTree");//中序遍历//因为 console.log 会换行,不能将所有内容收集成一行。所以使用 str 来收集要打印的内容。function InOrderDisplay(root, str = "") { if (root == undefined || root == null) { return ""; } //判断是否存在左子树,存在则递归左子树。 if (root.

2022-05-21 10:16:37 133

原创 数据结构 js 实现递归前序遍历

const { tree } = require("./utils/BinarySearchTree");//中序遍历//因为 console.log 会换行,不能将所有内容收集成一行。所以使用 str 来收集要打印的内容。function InOrderDisplay(root, str = "") { if (root == undefined || root == null) { return ""; } //判断是否存在左子树,存在则递归左子树。 if (root.

2022-05-21 10:15:54 150

原创 数据结构 js 实现递归中序遍历

BinarySearchTree 的内容来自于二叉查找树文章的代码。const { tree } = require("./utils/BinarySearchTree");//中序遍历//因为 console.log 会换行,不能将所有内容收集成一行。所以使用 str 来收集要打印的内容。function InOrderDisplay(root, str = "") { if (root == undefined || root == null) { return ""; }

2022-05-21 10:14:18 151

原创 数据结构 js实现二叉查找树

二叉查找树二叉查找树(BST), 又叫做二叉排序树,二叉搜索树,是一种对查找和排序都有用的特殊二叉树。二叉查找树或者空树,或者满足下面三个性质:1、若其左子树非空,则左子树上所有结点的值都小于根节点的值。2、若其右子树非空,则右子树上所有结点的值都大于根节点的值。3、其左右子树都是一棵二叉查找树。二叉查找树的特性:左子树 < 根 < 右子树, 即二叉查找树的中序遍历是一个递增序列。二叉查找树的查询因为二叉查找树的中序遍历有序性,即得到的递增的序列,由于有序,查找与二分查找类似,

2022-05-21 09:44:14 658

原创 数据结构 -js 实现希尔排序

仅仅提供代码实现,原理请问度娘。1、 数据和工具类module.exports.list = [9, 3, 4, 32, 42, 3, 45, 33, 2, 76, 89, 34];module.exports.swap = function (list, i, j) { let temp = list[i]; list[i] = list[j]; list[j] = temp;};module.exports.display = function (list) { let

2022-05-18 15:19:37 104

原创 数据结构 -js 实现选择排序

仅仅提供代码实现,原理请问度娘。1、 数据和工具类module.exports.list = [9, 3, 4, 32, 42, 3, 45, 33, 2, 76, 89, 34];module.exports.swap = function (list, i, j) { let temp = list[i]; list[i] = list[j]; list[j] = temp;};module.exports.display = function (list) { let

2022-05-18 15:18:48 74

原创 数据结构 -js 实现基数排序

仅仅提供代码实现,原理请问度娘。1、 数据和工具类module.exports.list = [9, 3, 4, 32, 42, 3, 45, 33, 2, 76, 89, 34];module.exports.swap = function (list, i, j) { let temp = list[i]; list[i] = list[j]; list[j] = temp;};module.exports.display = function (list) { let

2022-05-18 15:17:58 125

原创 数据结构 -js 实现快速排序

仅仅提供代码实现,原理请问度娘。快速排序是冒泡排序的升级版本,每次都确定一个数的排序后的位置。且将数组进行分治处理。1、 数据和工具类module.exports.list = [9, 3, 4, 32, 42, 3, 45, 33, 2, 76, 89, 34];module.exports.swap = function (list, i, j) { let temp = list[i]; list[i] = list[j]; list[j] = temp;};module

2022-05-18 15:17:00 73

原创 数据结构 -js 实现归并排序

仅仅提供代码实现,原理请问度娘。1、 数据和工具类module.exports.list = [9, 3, 4, 32, 42, 3, 45, 33, 2, 76, 89, 34];module.exports.swap = function (list, i, j) { let temp = list[i]; list[i] = list[j]; list[j] = temp;};module.exports.display = function (list) { let

2022-05-18 15:15:27 95

原创 数据结构 -js 实现插入排序

仅仅提供代码实现,原理请问度娘。1、 数据和工具类module.exports.list = [9, 3, 4, 32, 42, 3, 45, 33, 2, 76, 89, 34];module.exports.swap = function (list, i, j) { let temp = list[i]; list[i] = list[j]; list[j] = temp;};module.exports.display = function (list) { let

2022-05-18 15:14:24 157

原创 数据结构 -js 实现堆排序

1、 数据和工具类module.exports.list = [9, 3, 4, 32, 42, 3, 45, 33, 2, 76, 89, 34];module.exports.swap = function (list, i, j) { let temp = list[i]; list[i] = list[j]; list[j] = temp;};module.exports.display = function (list) { let str = ""; for (

2022-05-18 15:13:31 97

原创 数据结构 -js 实现计数排序

仅仅提供代码实现,原理请问度娘。1、 数据和工具类module.exports.list = [9, 3, 4, 32, 42, 3, 45, 33, 2, 76, 89, 34];module.exports.swap = function (list, i, j) { let temp = list[i]; list[i] = list[j]; list[j] = temp;};module.exports.display = function (list) { let

2022-05-18 15:12:26 144

原创 数据结构 -js 实现桶排序

仅仅提供代码实现,原理请问度娘。1、 数据和工具类module.exports.list = [9, 3, 4, 32, 42, 3, 45, 33, 2, 76, 89, 34];module.exports.swap = function (list, i, j) { let temp = list[i]; list[i] = list[j]; list[j] = temp;};module.exports.display = function (list) { let

2022-05-18 15:11:24 153

原创 数据结构 -js 实现冒泡排序

仅仅提供代码实现,原理请问度娘。1、 数据和工具类module.exports.list = [9, 3, 4, 32, 42, 3, 45, 33, 2, 76, 89, 34];module.exports.swap = function (list, i, j) { let temp = list[i]; list[i] = list[j]; list[j] = temp;};module.exports.display = function (list) { let

2022-05-18 15:09:56 114

原创 vue-router3源码注视系列 /src/index.js

/* @flow *///install: vue.use( VueRouter ) 时调用的 install() 方法。import { install } from ‘./install’//START: 初始化 route 对象。import { START } from ‘./util/route’//assert, warn: 断言和警告import { assert, warn } from ‘./util/warn’//inBrowser: 判断是不是处于浏览器环境。impor

2022-04-18 14:49:09 870

原创 Html5 history对象详解

这个文章记录的是 html5 原生的 history 对象,不是 vue-router 的 history。作用history 接口允许操作浏览器的曾经在标签页或者框架里访问的会话历史记录。window.history: 返回当前会话的 history 状态。属性history.length只读,返回一个整数,该证书表示会话历史中元素的数目,包括当前加载的页。history.scrollRestoration允许 web 应用程序在历史导航上显示的设置默认滚动恢复行为。此属性可以

2022-04-15 16:13:57 1477

原创 vue-router 官方文档学习

安装npm install vue-router简单使用# 在 main.js 文件中import Vue froom 'vue'import VueRouter from 'vue-router'Vue.use(VueRouter);import User from '@/views/User'import Login from '@/views/Login'let vueRouter = new VueRouter({ routes: [ { path: "/"

2022-04-02 15:58:56 4913

原创 vue-router3 源码注释系列 /src/create-matcher.js

/* @flow */import type VueRouter from './index'import { resolvePath } from './util/path'import { assert, warn } from './util/warn'import { createRoute } from './util/route'import { fillParams } from './util/params'import { createRouteMap } from './c

2022-03-30 13:52:49 334 1

原创 vue-router3 源码注释系列 /src/util/query.js

/* @flow */import { warn } from './warn'//判断字符为 !'()* 的正则表达式。const encodeReserveRE = /[!'()*]/g/* 1、c.charCodeAt(0) 获取字符的 ascii 编码,返回的是数字。 2、number.toString(16) 返回 16 进制数字编码的字符串形式。 3、!'()* 转换成的形式为 %21%27%28%29%2a。 */const encodeReserveReplacer

2022-03-28 17:02:16 1159

原创 vue-router3 源码注释系列 /src/util/push-state.js

/* @flow *///用于判断是否是浏览器环境import { inBrowser } from './dom'//保存滚动的位置(x,y).import { saveScrollPosition } from './scroll'// genStateKey 生成基于当前时间时间戳的key。// setStateKey 更新key。// getStateKey 获取key。import { genStateKey, setStateKey, getStateKey } from '.

2022-03-28 16:59:34 830

原创 vue-router3 源码注释系列 /src/util/path.js

/* @flow *//** * resolvePath(): 解析路径 * 第一个参数: 相对路径,要跳转路径的 pathname。 * 第二个参数: 基准路径。 * 第三个参数: 是否需要拼接基准地址。 */export function resolvePath( relative: string, base: string, append?: boolean): string { //判断 relative 是否是以 “/” 开头。 const first

2022-03-28 16:56:56 490

原创 vue-router3 源码注释系列 /src/util/location.js

/* @flow */import type VueRouter from '../index'// parsePath:用于拆分成 { path: string, query: object, hash: string } 的形式。// resolvePath: 用于将相对路径根据 current route 拼接路径成绝对形式的路径。import { parsePath, resolvePath } from './path'//resolveQuery() 将所有的 query 统一到一个

2022-03-28 16:55:32 841

原创 vue-router3 源码注释系列 /src/util/scroll.js

/* @flow */import type Router from '../index'import { assert } from './warn'//getStateKey: 用于获取时间戳key; //setStateKey: 用于设置时间戳key;import { getStateKey, setStateKey } from './state-key'//浅拷贝对象的属性。import { extend } from './misc'//用于保存对应的页面的 scrollpo

2022-03-25 21:00:16 760

原创 Vue $once 函数

Vue $once 函数1、作用$once 是一个函数,可以为 vue 实例绑定一个自定义事件,但是这个事件只会被触发一次,触发之后就会被移除。 类似的监听函数有: $on.2、使用与 $on(1) $once('xxxx', ()=>{...}) 与 $on('xxx', ()=>{...}) 的用法类似。(2) $once 只监听一次; $on 一直监听。3、使用 $once 清除定时器mounted(){ let count = 1; let timer = se

2022-03-25 16:38:57 2677

原创 vue-router3源码注解系列 /src/create-route-map.js

/* @flow *//* 用于路径匹配的正则表达式对象。*/import Regexp from 'path-to-regexp'//用于清理 uri 上连续重复的 / 。import { cleanPath } from './util/path'//断言,警告。import { assert, warn } from './util/warn'/* createRouteMap() 函数: 第一个参数 routes 就是 new VueRouter( { routes

2022-03-25 11:29:39 562

原创 vuex,vue-router源码系列注释说明

最近有点忙,不能及时更新对应的注释文章。关于更新内容不适合博客阅读的说明:1、更新内容只是为了自己回顾,以及帮助在看源码的同学可以对比,而不是教人从0到1的学会源码如何实现。所以没注意内容排版。2、vuex3,vuex-persistence 的源码注释的是 github 仓库地址, 能点 star 的说声谢谢。3、vue-router 会在 4-23 号之前更新完,但因为开发任务比较重,只能不定时更新了。4、紧接着是 axios, vue 的源码,然后是 vuex4, vuerouter4,vu

2022-03-24 10:02:15 458 1

原创 vue-router3源码注释系列 /src/install.js

import View from './components/view'import Link from './components/link'//用于保存创建 vue 的实力。export let _Vue/** * import VueRouter from 'vur-router' * Vue.use(VueRouter) 的时候就调用该 install 方法。 * * 注意点: 虽然 install 方法会在 router 创建之前就被调用。但是被混合的方法 { * b

2022-03-21 10:26:27 328

原创 vuex3.0源码注释系列 vuex-persistedstate源码注释

import { Store, MutationPayload } from "vuex";import merge from "deepmerge";import * as shvl from "shvl";interface Storage { getItem: (key: string) => any; setItem: (key: string, value: any) => void; removeItem: (key: string) => void;}

2022-03-19 10:59:26 680

原创 vuex3源码注释系列 /src/helper.js mapState,mapMutation,mapGetter,mapAction 源码解析

import { isObject } from "./util";/** * vuex 中使用的四个辅助函数的来源文件 /src/helpers.js。 * mapState, * mapMutations, * mapGetters, * mapActions, * createNamespacedHelpers *//* mapState 经过 调用normalizeNamespace() 之后,返回的结果,这个结果就是个函数。 我们调用的 mapState 是如下函数:

2022-03-17 11:22:22 906

原创 vuex3源码注释系列 /src/store.js

import applyMixin from "./mixin";import devtoolPlugin from "./plugins/devtool";import ModuleCollection from "./module/module-collection";import { forEachValue, isObject, isPromise, assert, partial } from "./util";let Vue; // bind on install/*** * V

2022-03-16 20:17:56 847

原创 vuex3源码注释系列 /src/plugins/logger.js

// Credits: borrowed code from fcomb/redux-loggerimport { deepCopy } from "../util";/** * 关于 createLogger 的使用: ===> 以插件的方式进行使用。用于打印 vuex 使用过程中的消息日志。 * import { createLogger } from 'vuex'; const store = new Vuex.store({ state: {},

2022-03-16 11:24:39 322

原创 vuex3源码注释系列 /src/module/module-collection.js

import Module from "./module";import { assert, forEachValue } from "../util";/** * rawRootModule 参数就是 Vuex.Store(options) 中的 options 值。 * * ModuleCollection 实例。在 store 对象上是 store._modules 属性。 * { * root: 指向 rawModule 第一层的数据转换成的 Module 实例

2022-03-16 10:33:49 191

vue-router官网文档学习

vue-router官网文档学习

2022-04-11

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除