| { | ||
| "env": { | ||
| "es6": true, | ||
| "node": true | ||
| }, | ||
| "extends": [ | ||
| "eslint:recommended", | ||
| "plugin:@typescript-eslint/eslint-recommended" | ||
| ], | ||
| "globals": { | ||
| "Atomics": "readonly", | ||
| "SharedArrayBuffer": "readonly" | ||
| }, | ||
| "parser": "@typescript-eslint/parser", | ||
| "parserOptions": { | ||
| "ecmaVersion": 2018, | ||
| "sourceType": "module" | ||
| }, | ||
| "plugins": [ | ||
| "@typescript-eslint" | ||
| ], | ||
| "rules": { | ||
| "no-unused-vars": "off", | ||
| "@typescript-eslint/no-unused-vars": "error", | ||
| "indent": [ | ||
| "error", | ||
| 2 | ||
| ], | ||
| "linebreak-style": [ | ||
| "error", | ||
| "unix" | ||
| ], | ||
| "quotes": [ | ||
| "error", | ||
| "single" | ||
| ], | ||
| "semi": [ | ||
| "error", | ||
| "always" | ||
| ] | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
| export * from './lib/simpleSelection'; | ||
| export * from './lib/shellSort'; | ||
| export * from './lib/quickSort'; | ||
| export * from './lib/heapSort'; | ||
| export * from './lib/insertion'; |
| "use strict"; | ||
| function __export(m) { | ||
| for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
| } | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| __export(require("./lib/simpleSelection")); | ||
| __export(require("./lib/shellSort")); | ||
| __export(require("./lib/quickSort")); | ||
| __export(require("./lib/heapSort")); | ||
| __export(require("./lib/insertion")); | ||
| //# sourceMappingURL=index.js.map |
| import { NumberArray } from './type'; | ||
| export declare const heapSort: (arr: NumberArray) => NumberArray; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const swap = (arr, a, b) => { | ||
| let tmp = arr[a]; | ||
| arr[a] = arr[b]; | ||
| arr[b] = tmp; | ||
| }; | ||
| const rebuildFromTail = (arr, n) => { | ||
| if (arr.length == 1) { | ||
| return; | ||
| } | ||
| let i = 0; | ||
| if (n % 2 === 0) { | ||
| i = Math.floor(n / 2) - 1; | ||
| if (arr[n] > arr[i]) { | ||
| swap(arr, n, i); | ||
| } | ||
| if (i !== 0) { | ||
| rebuildFromTail(arr, i); | ||
| } | ||
| } | ||
| else { | ||
| i = Math.floor(n / 2); | ||
| if (arr[n] > arr[i]) { | ||
| swap(arr, n, i); | ||
| } | ||
| if (i !== 0) { | ||
| rebuildFromTail(arr, i); | ||
| } | ||
| } | ||
| }; | ||
| const rebuildFromHead = (arr, n) => { | ||
| if (arr.length == 1) { | ||
| return; | ||
| } | ||
| if (arr[2 * n + 1] === undefined && arr[2 * n + 2] === undefined) { | ||
| return; | ||
| } | ||
| switch (Math.max(arr[n], arr[2 * n + 1], arr[2 * n + 2])) { | ||
| case arr[n]: | ||
| break; | ||
| case arr[2 * n + 1]: | ||
| swap(arr, n, 2 * n + 1); | ||
| n = 2 * n + 1; | ||
| rebuildFromHead(arr, n); | ||
| break; | ||
| case arr[2 * n + 2]: | ||
| swap(arr, n, 2 * n + 2); | ||
| n = 2 * n + 2; | ||
| rebuildFromHead(arr, n); | ||
| break; | ||
| } | ||
| }; | ||
| exports.heapSort = (arr) => { | ||
| const heap = []; | ||
| for (let k = 0; k < arr.length; k++) { | ||
| heap.push(arr[k]); | ||
| rebuildFromTail(heap, heap.length - 1); | ||
| } | ||
| const result = []; | ||
| while (heap.length) { | ||
| swap(heap, 0, heap.length - 1); | ||
| result.push(heap.pop()); | ||
| rebuildFromHead(heap, 0); | ||
| } | ||
| return result.reverse(); | ||
| }; | ||
| //# sourceMappingURL=heapSort.js.map |
| import { NumberArray } from './type'; | ||
| export declare const insertionSort: (arr: NumberArray) => NumberArray; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.insertionSort = (arr) => { | ||
| const result = []; | ||
| for (let i = 0; i < arr.length; i++) { | ||
| for (var k = result.length - 1; k >= 0 && (result[k] > arr[i]); k--) { | ||
| result[k + 1] = result[k]; | ||
| } | ||
| result[k + 1] = arr[i]; | ||
| } | ||
| return result; | ||
| }; | ||
| //# sourceMappingURL=insertion.js.map |
| import { NumberArray } from './type'; | ||
| export declare const quickSort: (arr: NumberArray) => NumberArray; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| /** | ||
| * 交换数组指定下标的值 | ||
| * @param {数组} arr | ||
| * @param {下标1} a | ||
| * @param {下标2} b | ||
| */ | ||
| const swap = (arr, a, b) => { | ||
| if (arr[a] !== arr[b]) { | ||
| arr[a] = arr[a] ^ arr[b]; | ||
| arr[b] = arr[a] ^ arr[b]; | ||
| arr[a] = arr[a] ^ arr[b]; | ||
| } | ||
| }; | ||
| /** | ||
| * 以数组第一个元素为基准,将小于基准的放到左边,大于基准的放到右边,返回基准值的最后下标 | ||
| * @param {数组} arr | ||
| * @param {开始位置} start | ||
| * @param {结束位置} end | ||
| */ | ||
| const division = (arr, start, end) => { | ||
| const base = arr[start]; | ||
| while (start < end) { | ||
| while (start < end && arr[end] >= base) { | ||
| end--; | ||
| } | ||
| swap(arr, start, end); | ||
| while (start < end && arr[start] <= base) { | ||
| start++; | ||
| } | ||
| swap(arr, start, end); | ||
| } | ||
| return start; | ||
| }; | ||
| /** | ||
| * 通过递归分治,将数组不断切分成小片段, | ||
| * @param {*} arr | ||
| * @param {*} start | ||
| * @param {*} end | ||
| */ | ||
| const round = (arr, start, end) => { | ||
| if (start < end) { | ||
| const flag = division(arr, start, end); | ||
| round(arr, start, flag - 1); | ||
| round(arr, flag + 1, end); | ||
| } | ||
| return arr; | ||
| }; | ||
| exports.quickSort = (arr) => { | ||
| round(arr, 0, arr.length - 1); | ||
| return arr; | ||
| }; | ||
| //# sourceMappingURL=quickSort.js.map |
| import { NumberArray } from './type'; | ||
| export declare const shellSort: (arr: NumberArray) => NumberArray; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.shellSort = (arr) => { | ||
| let step = Math.floor(arr.length / 2); | ||
| while (step) { | ||
| for (let i = step; i < arr.length; i++) { | ||
| const tmp = arr[i]; | ||
| for (var j = i - step; j >= 0 && (arr[j] > tmp); j -= step) { | ||
| arr[j + step] = arr[j]; | ||
| } | ||
| arr[j + step] = tmp; | ||
| } | ||
| step = Math.floor(step / 2); | ||
| } | ||
| return arr; | ||
| }; | ||
| //# sourceMappingURL=shellSort.js.map |
| import { NumberArray } from './type'; | ||
| export declare const simpleSelectionSort: (arr: NumberArray) => NumberArray; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const swap = (arr, a, b) => { | ||
| if (arr[a] !== arr[b]) { | ||
| arr[a] = arr[a] ^ arr[b]; | ||
| arr[b] = arr[a] ^ arr[b]; | ||
| arr[a] = arr[a] ^ arr[b]; | ||
| } | ||
| }; | ||
| exports.simpleSelectionSort = (arr) => { | ||
| for (let i = 0; i < arr.length; i++) { | ||
| let pos = i; | ||
| for (let i = pos + 1; i < arr.length; i++) { | ||
| if (arr[pos] > arr[i]) { | ||
| pos = i; | ||
| } | ||
| } | ||
| if (arr[i] > arr[pos]) { | ||
| swap(arr, i, pos); | ||
| } | ||
| } | ||
| return arr; | ||
| }; | ||
| //# sourceMappingURL=simpleSelection.js.map |
| export declare type NumberArray = Array<number>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| //# sourceMappingURL=type.js.map |
+1
| const { quickSort, simpleSelection, shellSort, insertionSort } = require('./index'); |
| import { assert } from 'chai'; | ||
| import { describe, it } from 'mocha'; | ||
| import { heapSort, insertionSort, quickSort, shellSort, simpleSelectionSort } from '../src'; | ||
| describe('all', () => { | ||
| it('quickSort', () => { | ||
| const arr: Array<number> = [3, 5, 1, 2, 7, 3, 5, 9, 2, 6, 11, 3, 7]; | ||
| const sorted: Array<number> = [1, 2, 2, 3, 3, 3, 5, 5, 6, 7, 7, 9, 11]; | ||
| assert.deepEqual(quickSort(arr), sorted); | ||
| }); | ||
| it('shellSort', () => { | ||
| const arr: Array<number> = [3, 5, 1, 2, 7, 3, 5, 9, 2, 6, 11, 3, 7]; | ||
| const sorted: Array<number> = [1, 2, 2, 3, 3, 3, 5, 5, 6, 7, 7, 9, 11]; | ||
| assert.deepEqual(shellSort(arr), sorted); | ||
| }); | ||
| it('simpleSelection', () => { | ||
| const arr: Array<number> = [3, 5, 1, 2, 7, 3, 5, 9, 2, 6, 11, 3, 7]; | ||
| const sorted: Array<number> = [1, 2, 2, 3, 3, 3, 5, 5, 6, 7, 7, 9, 11]; | ||
| assert.deepEqual(simpleSelectionSort(arr), sorted); | ||
| }); | ||
| it('heapSort', () => { | ||
| const arr: Array<number> = [3, 5, 1, 2, 7, 3, 5, 9, 2, 6, 11, 3, 7]; | ||
| const sorted: Array<number> = [1, 2, 2, 3, 3, 3, 5, 5, 6, 7, 7, 9, 11]; | ||
| assert.deepEqual(heapSort(arr), sorted); | ||
| }); | ||
| it('insertion', () => { | ||
| const arr: Array<number> = [3, 5, 1, 2, 7, 3, 5, 9, 2, 6, 11, 3, 7]; | ||
| const sorted: Array<number> = [1, 2, 2, 3, 3, 3, 5, 5, 6, 7, 7, 9, 11]; | ||
| assert.deepEqual(insertionSort(arr), sorted); | ||
| }); | ||
| }); |
Sorry, the diff of this file is not supported yet
+22
-5
| { | ||
| "name": "bluesort", | ||
| "version": "1.0.1", | ||
| "version": "2.0.0", | ||
| "description": "", | ||
| "main": "index.js", | ||
| "main": "dist/index.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| "test": "npx mocha --recursive -r ts-node/register test/**/*.spec.ts", | ||
| "build": "npx eslint src/**/*.ts --fix && npx tsc", | ||
| "lint": "npx eslint src/**/*.ts --fix", | ||
| "cover": "npx nyc npm test" | ||
| }, | ||
@@ -19,3 +22,17 @@ "repository": { | ||
| }, | ||
| "homepage": "https://github.com/captainblue2013/bluesort#readme" | ||
| } | ||
| "homepage": "https://github.com/captainblue2013/bluesort#readme", | ||
| "devDependencies": { | ||
| "@types/chai": "^4.2.5", | ||
| "@types/mocha": "^5.2.7", | ||
| "@types/node": "^12.12.12", | ||
| "@typescript-eslint/eslint-plugin": "^2.8.0", | ||
| "@typescript-eslint/parser": "^2.8.0", | ||
| "chai": "^4.2.0", | ||
| "eslint": "^6.7.1", | ||
| "mocha": "^6.2.2", | ||
| "nodemon": "^2.0.1", | ||
| "nyc": "^14.1.1", | ||
| "ts-node": "^8.5.2", | ||
| "typescript": "^3.7.2" | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
-9
| 'use strict'; | ||
| let index = {}; | ||
| index.quickSort = require('./lib/quickSort'); | ||
| index.simpleSelection = require('./lib/simpleSelection'); | ||
| module.exports = index; |
| 'use strict'; | ||
| let quickSort = {}; | ||
| quickSort.count = 0; | ||
| quickSort.swap = function (arr,a,b) { | ||
| let tmp = arr[a]; | ||
| arr[a] = arr[b]; | ||
| arr[b] = tmp; | ||
| quickSort.count++; | ||
| } | ||
| quickSort.division = function (arr,start,end) { | ||
| let base = arr[start]; | ||
| while(start < end){ | ||
| while(start<end && arr[end]>=base){ | ||
| end-- ; | ||
| } | ||
| quickSort.swap(arr,start,end); | ||
| while(start<end && arr[start]<=base){ | ||
| start++; | ||
| } | ||
| quickSort.swap(arr,start,end); | ||
| } | ||
| return start; | ||
| } | ||
| quickSort.round = function (arr,start,end) { | ||
| if(start<end){ | ||
| let flag = quickSort.division(arr,start,end); | ||
| quickSort.round(arr,start,flag-1); | ||
| quickSort.round(arr,flag+1,end); | ||
| } | ||
| return arr; | ||
| } | ||
| quickSort.sort = function (arr) { | ||
| quickSort.count = 0; | ||
| quickSort.round(arr,0,arr.length-1); | ||
| return arr; | ||
| } | ||
| module.exports = quickSort.sort; | ||
| console.log(quickSort.sort([3,5,1,2,7,3,5,9,2,6,11,3,7])); | ||
| console.log(quickSort.count); |
| 'use strict'; | ||
| let simpleSelection = {}; | ||
| simpleSelection.count = 0; | ||
| simpleSelection.swap = function (arr,a,b) { | ||
| let tmp = arr[a]; | ||
| arr[a] = arr[b]; | ||
| arr[b] = tmp; | ||
| simpleSelection.count++; | ||
| } | ||
| simpleSelection.sort = function (arr) { | ||
| simpleSelection.count = 0; | ||
| for(let i = 0; i < arr.length;i++){ | ||
| let pos = i; | ||
| for(let i = pos+1;i < arr.length;i++){ | ||
| if(arr[pos] > arr[i]){ | ||
| pos = i; | ||
| } | ||
| } | ||
| if(arr[i] > arr[pos]){ | ||
| simpleSelection.swap(arr,i,pos); | ||
| } | ||
| } | ||
| return arr; | ||
| } | ||
| module.exports = simpleSelection.sort; | ||
| console.log(simpleSelection.sort([3,5,1,2,7,3,5,9,2,6,11,3,7])); | ||
| console.log(simpleSelection.count); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
89482
3603.73%21
250%270
297.06%0
-100%12
Infinity%1
Infinity%