Skip to content

Commit

Permalink
2024.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
i12cu84 committed Jan 5, 2024
1 parent 346b6df commit 3380ad8
Show file tree
Hide file tree
Showing 148 changed files with 9,583 additions and 2 deletions.
133 changes: 131 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,27 @@
<details>
<summary>-> shared -> 知识分享</summary>
<pre><code>
<details>
<summary>-> algorithm -> 常规算法</summary>
<pre><code>
AVL-Tree-Cpp - AVL树
Bezier-Curve-Cpp - 贝塞尔曲线
B-Plus-Tree-Cpp - B+树
BRDF-Cpp - 双向反射分布函数
BSP-Tree-Cpp - 二叉空间划分
BSSRDF-Cpp - 双向散射表面反射分布函数
BVH-Cpp - 层次包围盒
Convex-hull-Algorithm-Cpp - 凸包
Huffman-Compression-Algorithm-Cpp - 哈夫曼编码
KD-Tree-Cpp - KD树
MCPT-Cpp - 蒙特卡洛路径追踪
NURBS-Cpp - 非均匀有理B样条曲线
Octree-Cpp - 八叉树
Ray-Tracing-Cpp - 光线追踪
Red-Black-Tree-Cpp - 红黑树
</code></pre>
</details>
<br>
<details>
<summary>-> app -> Python执行文件</summary>
<pre><code>
Expand All @@ -363,6 +384,98 @@
</details>
<br>
<details>
<summary>-> data -> 数值处理</summary>
<pre><code>
<details>
<summary>-> Data-Mining-Algorithm-Matlab -> 数据挖掘</summary>
<pre><code>
Apriori - 关联规则挖掘算法
K-means - K-均值算法
Hierarchical clustering - 分层聚类
ID3 - 决策树
Naive bayes classifier - 朴素贝叶斯分类器
Support vector machine - 支持向量机
Fuzzy C-means clustering algorithm - 模糊c均值聚类算法
</code></pre>
</details>
<br>
<details>
<summary>-> Intelligent-Computing-Matlab -> 智能计算</summary>
<pre><code>
BP neural network - BP神经网络
Hopfield neural network - Hopfield神经网络
Radial basis function - 径向基函数
Genetic algorithm - 遗传算法
Particle swarm optimization - 粒子群优化算法
Ant colony algorithm - 蚁群算法
</code></pre>
</details>
<br>
<details>
<summary>-> Numerical-Algebra-Matlab -> 数值代数</summary>
<pre><code>
Gaussian elimination method - 高斯消去法
Column pivot elimination - 列轴消元法
Chasing method - 追逐法
Root-squaring method - Root-squaring方法
Jacobi iteration method - 雅可比迭代法
Gaussian iteration method - 高斯迭代法
JOR method - 约旦迭代法
SOR method - 超松弛迭代法
Steepest descent method - 最速下降法
Conjugate gradient methods - 共轭梯度法
The steepest descent method and the rate of convergence - 最速下降法和收敛速度
Newton iteration method - 牛顿迭代法
Secant method - 割线法
Iteration method - 迭代法
</code></pre>
</details>
<br>
<details>
<summary>-> Numerical-Approximation-Matlab -> 数值逼近</summary>
<pre><code>
Lagrange's interpolation - 拉格朗日插值
Newton interpolation - 牛顿插值
Analogue function - 模拟
Hermite interpolation function - 埃尔米特插值
Spline interpolation - 样条插值
Polynomial canonical orthogonal fit - 多项式正则正交拟合
Newton-cotes formula - 牛顿-柯特斯公式
Euler's method - 欧拉方法
</code></pre>
</details>
<br>
<details>
<summary>-> Numerical-Methods-for-PDE-Matlab -> 偏微分方程数值解法</summary>
<pre><code>
PDE fun - 数值解法函数
Finite difference method - 有限差分法
Finite element difference method - 有限元差分法
Calculus of differences - 差分演算
Two dimensional heat conduction equation - 二维热传导方程
ADI - 求解偏微分方程的数值方法
Wave equation - 波动方程
Diffusion-convection equation - 对流扩散方程
</code></pre>
</details>
<br>
<details>
<summary>-> Optimization-Theory-and-Algorithms-Matlab -> 最优化理论</summary>
<pre><code>
Linear programming - 线性规划
Golden cut algorithm - 黄金分割算法
Ternary quadratic interpolation method - 三元二次插值法
Steepest descent method - 最速下降法
Newton method - 牛顿法
Conjugate gradient methods - 共轭梯度法
Uadratic programming - 二次规划
Rosen's gradient projection method - 梯度投影法
</code></pre>
</details>
</code></pre>
</details>
<br>
<details>
<summary>-> doc -> 文档</summary>
<pre><code>
agreement - 协议
Expand All @@ -381,7 +494,7 @@
</details>
<br>
<details>
<summary>-> modules -> 算法模块</summary>
<summary>-> modules -> 机器学习算法模块</summary>
<pre><code>
<details>
<summary>-> DeepLearningAlgorithm -> 深度学习算法</summary>
Expand Down Expand Up @@ -429,7 +542,7 @@
</details>
<br>
<details>
<summary>-> OtherAlgorithm -> 其他算法</summary>
<summary>-> OtherArtificialIntelligenceAlgorithm -> 其他人工智能算法</summary>
<pre><code>
KNN(K-NearestNeighbors) -> K最近邻
MarkovChains -> 马尔可夫链
Expand Down Expand Up @@ -459,8 +572,24 @@
</details>
<br>
<details>
<summary>-> paper -> 毕业设计</summary>
<pre><code>
[已整理,不赘述]
</code></pre>
</details>
<br>
<details>
<summary>-> plugins -> UE插件</summary>
<pre><code>
lib - 蓝图库插件
TP - 添加Tag/导出Tag插件
</code></pre>
</details>
<br>
<details>
<summary>-> private -> 笔者公开分享私有知识(转载请注明出处)</summary>
<pre><code>
AutoHotkey-quick-click-Follow - 自动跟随脚本
AutoAgree.js -> 自动点赞脚本
</code></pre>
</details>
Expand Down
142 changes: 142 additions & 0 deletions shared/algorithm/AVL-Tree-Cpp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#include<iostream>
using namespace std;

//定义AVL节点结构体
struct AVLNode{
int key; //节点关键字
int height; //节点高度
AVLNode *left; //左子节点
AVLNode *right; //右子节点
AVLNode(int k):key(k),height(1),left(NULL),right(NULL){} //构造函数
};

//获取节点高度
int getHeight(AVLNode *node){
if(node==NULL) return 0;
return node->height;
}

//获取节点平衡因子
int getBalance(AVLNode *node){
if(node==NULL) return 0;
return getHeight(node->left)-getHeight(node->right);
}

//更新节点高度
void updateHeight(AVLNode *node){
node->height=max(getHeight(node->left),getHeight(node->right))+1;
}

//左旋
AVLNode* leftRotate(AVLNode *node){
AVLNode *r=node->right;
AVLNode *rl=r->left;
r->left=node;
node->right=rl;
updateHeight(node);
updateHeight(r);
return r;
}

//右旋
AVLNode* rightRotate(AVLNode *node){
AVLNode *l=node->left;
AVLNode *lr=l->right;
l->right=node;
node->left=lr;
updateHeight(node);
updateHeight(l);
return l;
}

//插入节点
AVLNode* insertNode(AVLNode *node,int key){
if(node==NULL) return new AVLNode(key);
if(key<node->key) node->left=insertNode(node->left,key);
else node->right=insertNode(node->right,key);
updateHeight(node);
int balance=getBalance(node);
if(balance>1 && key<node->left->key) return rightRotate(node);
if(balance>1 && key>node->left->key){
node->left=leftRotate(node->left);
return rightRotate(node);
}
if(balance<-1 && key>node->right->key) return leftRotate(node);
if(balance<-1 && key<node->right->key){
node->right=rightRotate(node->right);
return leftRotate(node);
}
return node;
}

//查找节点
AVLNode* searchNode(AVLNode *node,int key){
if(node==NULL || node->key==key) return node;
if(key<node->key) return searchNode(node->left,key);
else return searchNode(node->right,key);
}

//删除节点
AVLNode* deleteNode(AVLNode *node,int key){
if(node==NULL) return node;
if(key<node->key) node->left=deleteNode(node->left,key);
else if(key>node->key) node->right=deleteNode(node->right,key);
else{
if(node->left==NULL || node->right==NULL){
AVLNode *temp=node->left?node->left:node->right;
if(temp==NULL){
temp=node;
node=NULL;
}
else *node=*temp;
delete temp;
}
else{
AVLNode *temp=node->right;
while(temp->left!=NULL) temp=temp->left;
node->key=temp->key;
node->right=deleteNode(node->right,temp->key);
}
}
if(node==NULL) return node;
updateHeight(node);
int balance=getBalance(node);
if(balance>1 && getBalance(node->left)>=0) return rightRotate(node);
if(balance>1 && getBalance(node->left)<0){
node->left=leftRotate(node->left);
return rightRotate(node);
}
if(balance<-1 && getBalance(node->right)<=0) return leftRotate(node);
if(balance<-1 && getBalance(node->right)>0){
node->right=rightRotate(node->right);
return leftRotate(node);
}
return node;
}

//中序遍历
void inorderTraversal(AVLNode *node){
if(node==NULL) return;
inorderTraversal(node->left);
cout<<node->key<<" ";
inorderTraversal(node->right);
}

//测试样例
int main(){
AVLNode *root=NULL;
root=insertNode(root,10);
root=insertNode(root,20);
root=insertNode(root,30);
root=insertNode(root,40);
root=insertNode(root,50);
root=insertNode(root,25);
cout<<"Inorder traversal of the AVL tree is:"<<endl;
inorderTraversal(root);
cout<<endl;
root=deleteNode(root,30);
cout<<"Inorder traversal of the AVL tree after deleting 30 is:"<<endl;
inorderTraversal(root);
cout<<endl;
return 0;
}
Loading

0 comments on commit 3380ad8

Please sign in to comment.