data-footstone
Advanced tools
Comparing version 0.1.1-alpha.0 to 0.1.1-alpha.1
{ | ||
"name": "data-footstone", | ||
"version": "0.1.1-alpha.0", | ||
"version": "0.1.1-alpha.1", | ||
"description": "data structure", | ||
@@ -29,3 +29,3 @@ "author": "feigebaobei <18515195415@163.com>", | ||
"clean": "echo 'fo clean'", | ||
"compile": "tsc", | ||
"compile": "tsc && npm run rollup", | ||
"prepare": "npm run compile", | ||
@@ -35,3 +35,2 @@ "pretest": "npm run compile", | ||
"prettier": "prettier", | ||
"prepublish": "npm run tsc && npm run rollup", | ||
"p": "prettier --write .", | ||
@@ -38,0 +37,0 @@ "pc": "prettier --check ." |
@@ -1,7 +0,89 @@ | ||
let bubbleSort = () => { }; | ||
let selectSort = () => { }; | ||
let insertSort = () => { }; | ||
let quickSort = () => { }; | ||
let quickSortSelf = () => { }; | ||
// n^2 | ||
let bubbleSort = (arr, order = 'asc') => { | ||
let len = arr.length; | ||
for (let i = 0; i < len; i++) { | ||
for (let j = 0; j < len - i - 1; j++) { | ||
switch (order) { | ||
case 'asc': | ||
if (arr[j] > arr[j + 1]) { | ||
[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]; | ||
} | ||
break; | ||
case 'des': | ||
if (arr[j] > arr[j + 1]) { | ||
[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
}; | ||
let selectSort = (arr) => { | ||
for (let i = 0; i < arr.length - 1; i++) { | ||
let minIndex = i; | ||
for (let j = i + 1; j < arr.length; j++) { | ||
if (arr[j] < arr[minIndex]) { | ||
minIndex = j; | ||
} | ||
} | ||
if (minIndex !== i) { | ||
[arr[i], arr[minIndex]] = [arr[minIndex], arr[i]]; | ||
} | ||
} | ||
}; | ||
let merge = (leftArr, rightArr) => { | ||
let tempArr = []; | ||
while (leftArr.length && rightArr.length) { | ||
if (leftArr[0] < rightArr[0]) { | ||
tempArr.push(leftArr.shift()); | ||
} | ||
else { | ||
tempArr.push(rightArr.shift()); | ||
} | ||
} | ||
return [...tempArr, ...leftArr, ...rightArr]; | ||
}; | ||
// nlogn | ||
let mergeSort = (arr) => { | ||
if (arr.length < 2) { | ||
return arr; | ||
} | ||
let m = arr.length >> 1; | ||
let left = arr.slice(0, m); | ||
let right = arr.slice(m); | ||
return merge(mergeSort(left), mergeSort(right)); | ||
}; | ||
// n^2 | ||
let insertSort = (arr) => { | ||
for (let i = 1; i < arr.length; i++) { | ||
let cur = arr[i]; | ||
let lastIndex = i - 1; | ||
while (lastIndex >= 0 && arr[lastIndex] > cur) { | ||
arr[lastIndex + 1] = arr[lastIndex]; | ||
lastIndex--; | ||
} | ||
arr[lastIndex + 1] = cur; | ||
return arr; | ||
} | ||
}; | ||
// nlogn | ||
let quickSort = (arr) => { | ||
if (arr.length < 1) { | ||
return arr; | ||
} | ||
let p = arr[arr.length >> 1]; | ||
let left; | ||
let right; | ||
arr.forEach(item => { | ||
if (item > p) { | ||
right.push(item); | ||
} | ||
else { | ||
left.push(item); | ||
} | ||
}); | ||
return [...(quickSort(left)), ...(quickSort(right))]; | ||
}; | ||
let heapSort = () => { }; | ||
let binarySearch = () => { }; | ||
export { bubbleSort, selectSort, insertSort, quickSort, quickSortSelf, binarySearch, }; | ||
export { bubbleSort, selectSort, insertSort, quickSort, heapSort, binarySearch, }; |
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
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.
Found 1 instance in 1 package
251832
4041
0