AVL 平衡二叉树 模板 发表于 2023-11-11 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182struct AVL { int value; int height; AVL *left; AVL *right; explicit AVL(int x) : value(x), height(1), left(nullptr), right(nullptr) {} static int max(int a, int b) { return a > b ? a : b; } static int getHeight(AVL *root) { if (!root) return 0; return root->height; } static AVL *insert(AVL *root, int value) { if (!root) return new AVL(value); if (value < root->value) { root->left = insert(root->left, value); if (getHeight(root->left) - getHeight(root->right) == 2) { if (value < root->left->value) { root = rotateLeft(root); } else { root = rotateLR(root); } } } if (value > root->value) { root->right = insert(root->right, value); if (getHeight(root->left) - getHeight(root->right) == -2) { if (value > root->right->value) { root = rotateRight(root); } else { root = rotateRL(root); } } } root->height = max(getHeight(root->left), getHeight(root->right)) + 1; return root; } static AVL *rotateLeft(AVL *root) { AVL *new_root = root->left; root->left = new_root->right; new_root->right = root; // Update Tree Height root->height = max(getHeight(root->left), getHeight(root->right)) + 1; new_root->height = max(getHeight(new_root->left), root->height) + 1; return new_root; } static AVL *rotateRight(AVL *root) { AVL *new_root = root->right; root->right = new_root->left; new_root->left = root; // Update Tree Height root->height = max(getHeight(root->left), getHeight(root->right)) + 1; new_root->height = max(getHeight(new_root->right), root->height) + 1; return new_root; } static AVL *rotateLR(AVL *root) { root->left = rotateRight(root->left); // LRL return rotateLeft(root); // L } static AVL *rotateRL(AVL *root) { root->right = rotateLeft(root->right); // RLR return rotateRight(root); // R }};
使用Yubikey在Windows和macOS下提供SSH私钥 发表于 2023-11-04 更新于 2023-11-11 看本文之前,你应该已经会使用 yubikey 官方的工具来创建 PIV 和 gpg-key。 阅读全文 »
macOS新系统配置脚本 发表于 2023-10-27 更新于 2023-11-11 介绍最近在玩黑苹果,因为系统不太稳定,就总需要重装,而且我不太喜欢用时间机器恢复数据。 于是我就写了一个脚本来进行一些重装以后的操作,比如安装需要的软件,改一些系统配置之类。 如果 App Store 有的应用我会默认使用它来安装,其次再使用 Homebrew 安装软件,比如微信之类的(装在容器里更放心)。 你可以自己修改这个脚本来适应你的情况。 阅读全文 »
黑苹果关闭SIP导致Steam闪退 发表于 2023-10-21 更新于 2023-11-11 起因在OpenCore中把 SIP 关了,本来想获得性能的提升,但是 Steam 和 Postman 打开以后闪退,调试信息显示显卡相关的问题。 Steam 会先启动更新器,更新完成后,登录窗口打不开,而 Postman 是直接闪退,而且没有崩溃提示。 解决再把 SIP 打开就好了。