feat: 添加归并排序代码测试
This commit is contained in:
parent
595f97ee04
commit
86efe8d7b2
@ -2,14 +2,11 @@ import { generateRandomArray, measureTime, isSort } from "../util/index.mjs";
|
|||||||
import { shellSort } from "./shell-sort.mjs";
|
import { shellSort } from "./shell-sort.mjs";
|
||||||
import {insertionSort } from "./insertion-sort.mjs"
|
import {insertionSort } from "./insertion-sort.mjs"
|
||||||
import { bubbleSort } from "./bubble-sort.mjs"
|
import { bubbleSort } from "./bubble-sort.mjs"
|
||||||
|
import { mergeSort } from "./merge-sort.mjs";
|
||||||
|
|
||||||
let arr = generateRandomArray(10000)
|
let arr = generateRandomArray(10)
|
||||||
let arr2 = arr.slice()
|
|
||||||
let arr3 = arr.slice()
|
|
||||||
|
|
||||||
measureTime(bubbleSort,arr)
|
measureTime(bubbleSort,arr.slice())
|
||||||
measureTime(insertionSort,arr2)
|
measureTime(insertionSort,arr.slice())
|
||||||
measureTime(shellSort,arr3)
|
measureTime(shellSort,arr.slice())
|
||||||
console.log(isSort(arr));
|
let mergeArr = measureTime(mergeSort, arr.slice()) // 归并排序会返回一个新数组,不对原数组修改
|
||||||
console.log(isSort(arr2));
|
|
||||||
console.log(isSort(arr3));
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user