Comparing version 0.1.12 to 0.1.13
export declare function pivot(data: number[], left: number, right: number): number; | ||
export declare function quickSort(data: number[]): void; | ||
export declare function quickSelectPivot(data: number[], left: number, right: number): number; | ||
export declare function quickSelect(data: number[], kth: number): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.quickSort = exports.pivot = void 0; | ||
exports.quickSelect = exports.quickSelectPivot = exports.quickSort = exports.pivot = void 0; | ||
function swap(data, i, j) { | ||
@@ -32,1 +32,32 @@ var temp = data[i]; | ||
exports.quickSort = quickSort; | ||
function quickSelectPivot(data, left, right) { | ||
var p = right; | ||
for (var i = right - 1; i >= left; i--) { | ||
if (data[p] < data[i]) { | ||
swap(data, p - 1, i); | ||
swap(data, p - 1, p); | ||
p -= 1; | ||
} | ||
} | ||
return p; | ||
} | ||
exports.quickSelectPivot = quickSelectPivot; | ||
function _quickSelect(data, left, right, index) { | ||
var p = quickSelectPivot(data, left, right); | ||
if (p === index) { | ||
return data[p]; | ||
} | ||
else if (p < index) { | ||
return _quickSelect(data, p + 1, right, index); | ||
} | ||
else { | ||
return _quickSelect(data, left, p - 1, index); | ||
} | ||
} | ||
// 1th index: data.length - 1 | ||
// 2th index: data.length - 2 | ||
// kth index: data.length - k | ||
function quickSelect(data, kth) { | ||
return _quickSelect(data, 0, data.length - 1, data.length - kth); | ||
} | ||
exports.quickSelect = quickSelect; |
{ | ||
"name": "flex-algo", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"description": "\"SDK for commonly used data structure and algorithms\"", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21243
570