mirror of
https://github.com/142vip/408CSFamily.git
synced 2026-04-13 18:00:58 +08:00
perf: 升级依赖版本,支持锁定node18.18
This commit is contained in:
@@ -23,7 +23,7 @@ void BinaryInsertSort(ElemType Arr[],int n){
|
||||
}
|
||||
|
||||
// 跳出循环需要(lowIndex>heightIndex),
|
||||
// 说明待插入位置的角标在heightIndex之后,为 heightIndex+1,此时需要将(heightIndex,i)之间的所有元素后移
|
||||
// 说明待插入位置的角标在heightIndex之后,为 heightIndex+1,此时需要将(heightIndex,i)之间的所有元素后移
|
||||
|
||||
for(j=i-1;j>highIndex;--j){
|
||||
Arr[j+1]=Arr[j]
|
||||
|
||||
@@ -7,9 +7,11 @@ function binaryInsertSort(arr, len) {
|
||||
? len
|
||||
: arr.length
|
||||
|
||||
// 遍历
|
||||
for (let i = 1; i < len; i++) {
|
||||
const temp = arr[i]
|
||||
let lowIndex = 0; let highIndex = i - 1
|
||||
let lowIndex = 0
|
||||
let highIndex = i - 1
|
||||
|
||||
while (lowIndex <= highIndex) {
|
||||
// 注意:取整,javascript这里取整,会出现空指针
|
||||
@@ -29,15 +31,14 @@ function binaryInsertSort(arr, len) {
|
||||
}
|
||||
arr[highIndex + 1] = temp
|
||||
}
|
||||
|
||||
// 返回经过折半插入排序处理的有序数组
|
||||
return arr
|
||||
}
|
||||
|
||||
|
||||
// 测试用例
|
||||
const dealArr = [5, 2, 7, 3, 18, 8, 12, 1]
|
||||
console.log('插入排序前:', dealArr)
|
||||
const sortResult = binaryInsertSort(dealArr, 7)
|
||||
|
||||
console.log('插入排序后:', sortResult)
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ LinkList CreateListWithStartNode(LinkList &L){
|
||||
return L;
|
||||
}
|
||||
|
||||
|
||||
// 单链表尾插法
|
||||
LinkList CreateListWithEndNode(LinkList &L){
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@ typedef struct StackNode
|
||||
{
|
||||
int data;//结点数据域
|
||||
struct StackNode* next;//结点指针域
|
||||
}StackNode,* Linktop;
|
||||
}StackNode,* LinkTop;
|
||||
|
||||
//链栈的数据结构
|
||||
typedef struct LinkStack
|
||||
{
|
||||
Linktop top; //栈顶结点,定义了一个指向上个结构体的指针
|
||||
LinkTop top; //栈顶结点,定义了一个指向上个结构体的指针
|
||||
int count;//元素个数
|
||||
}LinkStack;
|
||||
|
||||
|
||||
@@ -9,9 +9,6 @@ typedef struct {
|
||||
int front,rear;
|
||||
} SqQueue;
|
||||
|
||||
|
||||
|
||||
|
||||
// 入队算法
|
||||
// 尾插法:Q.data[Q.rear]=x;Q.rear=(Q.rear+1)%Maxsize;Q.tag=1
|
||||
// 队空条件:Q.front== Q.rear且Q.tag==0
|
||||
@@ -25,8 +22,8 @@ int EnLoopQueue(SqQueue &Q, ElemType x){
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 出队算法
|
||||
// 头结点删除:x=Q.data[Q.front];Q.front=(Q.front +1)%Maxsize;Q.tag=0
|
||||
// 队满条件:Q.front == Q.rear且Q.tag=1
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/**
|
||||
* 基于分治法思想,将数组进行快速排序
|
||||
* @param {Array} arr 待排序的数组
|
||||
@@ -7,7 +6,7 @@
|
||||
*/
|
||||
function QuickSort(arr, low, high) {
|
||||
// low=high 说明只有一个元素,理解为有序,不做处理
|
||||
// low>high 说明左右指针已经重合,数组已经遍历完,需要跳出
|
||||
// low>high 说明左、右指针已经重合,数组已经遍历完,需要跳出
|
||||
if (low < high) {
|
||||
const pivotIndex = Partition(arr, low, high)
|
||||
// 处理左侧
|
||||
@@ -50,7 +49,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}`)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// 顺序表的基础操作
|
||||
|
||||
|
||||
|
||||
// 基础结构体
|
||||
define MaxSize 50;
|
||||
typedef struct{
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
/*
|
||||
* @Description: 顺序栈的相关操作
|
||||
* @Version: Beta1.0
|
||||
* @Author: 【B站&公众号】Rong姐姐好可爱
|
||||
* @Date: 2020-03-07 11:15:04
|
||||
* @LastEditors: 【B站&公众号】Rong姐姐好可爱
|
||||
* @LastEditTime: 2021-03-13 12:30:18
|
||||
*/
|
||||
|
||||
|
||||
// 定义栈中元素的最大个数
|
||||
# define MaxSize 50
|
||||
|
||||
@@ -43,7 +33,7 @@ bool Push(SqStack &S,ElemType x){
|
||||
}else{
|
||||
// 可进栈,栈顶指针+1,再元素入栈
|
||||
S.data[++S.top]=x;
|
||||
|
||||
|
||||
// 入栈成功
|
||||
return true;
|
||||
}
|
||||
@@ -58,7 +48,7 @@ bool Pop(SqStack &S,ElemType &x){
|
||||
}else{
|
||||
// 栈非空,先元素出栈,再进行指针-1
|
||||
x=S.data[S.top--];
|
||||
|
||||
|
||||
// 出栈成功,返回true
|
||||
return true;
|
||||
}
|
||||
@@ -66,15 +56,15 @@ bool Pop(SqStack &S,ElemType &x){
|
||||
|
||||
// 读(获取)栈顶元素
|
||||
bool GetTop(SqStack S,ElemType &x){
|
||||
|
||||
|
||||
if(S.top==-1){
|
||||
// 栈空,无栈顶元素,返回false
|
||||
return false;
|
||||
}else{
|
||||
|
||||
|
||||
// 通过栈顶指针,获取栈顶元素,赋值给变量x
|
||||
x=S.data[S.top];
|
||||
|
||||
|
||||
// 读取栈顶元素成功,返回true
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user