1
0
mirror of https://github.com/142vip/408CSFamily.git synced 2026-05-09 23:43:42 +08:00

feat: 工程化依赖升级,优化文档和基础配置 (#148)

This commit is contained in:
142vip.cn
2025-05-13 17:44:57 +08:00
committed by GitHub
parent 3878a438b0
commit 866d943b17
25 changed files with 569 additions and 898 deletions

View File

@@ -39,5 +39,6 @@ function binaryInsertSort(arr, len) {
// 测试用例
const dealArr = [5, 2, 7, 3, 18, 8, 12, 1]
console.log('插入排序前:', dealArr)
const sortResult = binaryInsertSort(dealArr, 7)
console.log('插入排序后:', sortResult)

View File

@@ -33,5 +33,6 @@ function BubbleSort(arr, len) {
const initArr = [1, 5, 8, 3, 2, 9, 16]
console.log(`冒泡排序前:${initArr}`)
const sortedArr = BubbleSort(initArr, 7)
console.log(`冒泡排序后:${sortedArr}`)

View File

@@ -48,5 +48,6 @@ function Partition(arr, low, high) {
const initArr = [2, 18, 6, 25, 19, 4, 8, 3, 7]
console.log(`快速排序处理前:${initArr}`)
const quickSortResult = QuickSort(initArr, 0, 8)
console.log(`快速排序处理后:${quickSortResult}`)

View File

@@ -50,6 +50,7 @@ function specialStraightInsertSort(arr, len, increment, groupIndex) {
const dealArr = [5, 8, 2, 16, 3, 9, 1]
console.log('插入排序前:', dealArr)
const sortResult = shellSort(dealArr, 7)
console.log('插入排序后:', sortResult)

View File

@@ -27,6 +27,6 @@ function straightInsertSort(arr, len) {
const dealArr = [5, 2, 7, 3, 18, 8, 12, 1]
console.log('插入排序前:', dealArr)
const sortResult = straightInsertSort(dealArr, 7)
const sortResult = straightInsertSort(dealArr, 7)
console.log('插入排序后:', sortResult)

View File

@@ -40,7 +40,7 @@ function binaryInsertSort(arr: number[], len: number): number[] {
// 测试用例
const dealArr = [5, 2, 7, 3, 18, 8, 12, 1]
console.log('插入排序前:', dealArr)
const sortResult = binaryInsertSort(dealArr, 7)
console.log('插入排序后:', sortResult)

View File

@@ -40,7 +40,7 @@ export function BubbleSort(arr: number[]): number[] {
/**
* 将两个变量数值交换
*/
export function switchValue(params: SwitchValue) {
export function switchValue(params: SwitchValue): SwitchValue {
const { a: newB, b: newA } = params
return { a: newA, b: newB }
}
@@ -48,5 +48,6 @@ export function switchValue(params: SwitchValue) {
// 用例
const initArr = [1, 5, 8, 3, 2, 9, 16]
console.log(`冒泡排序前:${initArr}`)
const sortedArr = BubbleSort(initArr)
console.log(`冒泡排序后:${sortedArr}`)

View File

@@ -4,7 +4,7 @@
* @param {int} low 数组低位角标 左指针
* @param {int} high 数组高位角标 右指针
*/
export function QuickSort(arr, low, high) {
export function QuickSort(arr: number[], low: number, high: number): number[] {
// low=high 说明只有一个元素,理解为有序,不做处理
// low>high 说明左、右指针已经重合,数组已经遍历完,需要跳出
if (low < high) {
@@ -26,7 +26,7 @@ export function QuickSort(arr, low, high) {
* @param {int} low 数组低位角标 左指针
* @param {int} high 数组高位角标 右指针
*/
export function Partition(arr, low, high) {
export function Partition(arr: number[], low: number, high: number): number {
// 假设低位指针对应数组角标元素为基准pivot
const pivot = arr[low]
while (low < high) {

View File

@@ -4,7 +4,7 @@
* @param {Array} arr 待排序数组
* @param {int} len 数组长度,可校验
*/
export function shellSort(arr: number[], len: number) {
export function shellSort(arr: number[], len: number): number[] {
// 校对数组长度
if (arr.length !== len) {
len = arr.length
@@ -28,7 +28,7 @@ export function shellSort(arr: number[], len: number) {
* @param {int} increment 增量步长
* @param {int} groupIndex 分组,第几个分组
*/
export function specialStraightInsertSort(arr: number[], len: number, increment: number, groupIndex: number) {
export function specialStraightInsertSort(arr: number[], len: number, increment: number, groupIndex: number): number[] {
if (arr.length !== len) {
len = arr.length
}
@@ -56,6 +56,7 @@ export function specialStraightInsertSort(arr: number[], len: number, increment:
const dealArr = [5, 8, 2, 16, 3, 9, 1]
console.log('插入排序前:', dealArr)
const sortResult = shellSort(dealArr, 7)
console.log('插入排序后:', sortResult)
@@ -64,7 +65,7 @@ console.log('插入排序后:', sortResult)
* - 返回已排序号的数组,从小到大
* @param {Array} arr
*/
export function shellSortBetter(arr) {
export function shellSortBetter(arr: number[]): number[] {
const len = arr.length
let increment = Math.floor(len / 2)

View File

@@ -1,7 +1,7 @@
/**
* 直接插入排序【JavaScript版本】
*/
export function straightInsertSort(arr: number[], len: number) {
export function straightInsertSort(arr: number[], len: number): number[] {
// 重新确定数组长度
if (arr.length !== len) {
len = arr.length
@@ -30,7 +30,7 @@ export function straightInsertSort(arr: number[], len: number) {
}
const dealArr = [5, 2, 7, 3, 18, 8, 12, 1]
console.log('插入排序前:', dealArr)
const sortResult = straightInsertSort(dealArr, 7)
console.log('插入排序后:', sortResult)