#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string.h> using namespace std; template<class K, class V> struct BSTreeNode { K _key; V _value; BSTreeNode<K, V>* _left; BSTreeNode<K, V>* _right; BSTreeNode(const K& key, const V& value) :_key(key) , _value(value) , _left(nullptr) , _right(nullptr) {} }; template<class K, class V> class BSTree { typedef BSTreeNode<K, V> Node; public: bool Insert(const K& key, const V& value) { if (_root == nullptr) { _root =new Node(key, value); return true; } Node* parent = nullptr; Node* cur = _root; while (cur) { if (cur->_key < key) { parent = cur; cur = cur->_right; } else if (cur->_key > key) { parent = cur; cur = cur->_left; } else { return false; } } cur = new Node(key, value); if (parent->_key < key) { parent->_right = cur; } else { parent->_left = cur; } return true; } Node* Find(const K& key) { Node* cur = _root; while (cur) { if (cur->_key < key) { cur = cur->_right; } else if (cur->_key > key) { cur = cur->_left; } else { return cur; } } return nullptr; } bool Erase(const K& key) { Node* parent = nullptr; Node* cur = _root; while (cur) { if (cur->_key < key) { parent = cur; cur = cur->_right; } else if (cur->_key > key) { parent = cur; cur = cur->_left; } else { // 删除 // 左为空 if (cur->_left == nullptr) { if (cur == _root) { _root = cur->_right; } else { if (parent->_left == cur) { parent->_left = cur->_right; } else { parent->_right = cur->_right; } } delete cur; } else if (cur->_right == nullptr) { if (cur == _root) { _root = cur->_left; } else { // 右为空 if (parent->_left == cur) { parent->_left = cur->_left; } else { parent->_right = cur->_left; } } delete cur; } else { // 左右都不为空 // 右子树最左节点 Node* replaceParent = cur; Node* replace = cur->_right; while (replace->_left) { replaceParent = replace; replace = replace->_left; } cur->_key = replace->_key; if (replaceParent->_left == replace) replaceParent->_left = replace->_right; else replaceParent->_right = replace->_right; delete replace; } return true; } } return false; } void InOrder() { _InOrder(_root); cout << endl; } private: void _InOrder(Node* root) { if (root == nullptr) { return; } _InOrder(root->_left); cout << root->_key << ":" << root->_value << endl; _InOrder(root->_right); } private: Node* _root = nullptr; }; void TestBSTree() { /*BSTree<string, string> dict; dict.Insert("insert", "插入"); dict.Insert("erase", "删除"); dict.Insert("left", "左边"); dict.Insert("string", "字符串"); string str; while (cin >> str) { auto ret = dict.Find(str); if (ret) { cout << str << ":" << ret->_value << endl; } else { cout << "单词拼写错误" << endl; } }*/ string strs[] = { "苹果", "西瓜", "苹果", "樱桃", "苹果", "樱桃", "苹果", "樱桃", "苹果" }; // 统计水果出现的次 BSTree<string, int> countTree; for (auto str : strs) { auto ret = countTree.Find(str); if (ret == NULL) { countTree.Insert(str, 1); } else { ret->_value++; } } countTree.InOrder(); } int main() { TestBSTree(); return 0; }二叉搜索树
张小明
前端开发工程师
5分钟快速部署Qwen3-Reranker-4B:vLLM+Gradio一站式解决方案
5分钟快速部署Qwen3-Reranker-4B:vLLMGradio一站式解决方案 1. 引言 1.1 业务场景与痛点分析 在当前信息爆炸的时代,文本检索、语义排序和多语言内容理解已成为搜索系统、推荐引擎和智能问答平台的核心能力。传统排序模型往往面临推理延迟高、跨语言支…
SGLang部署常见错误:host 0.0.0.0配置问题解决指南
SGLang部署常见错误:host 0.0.0.0配置问题解决指南 1. 引言 随着大语言模型(LLM)在各类业务场景中的广泛应用,高效、稳定的推理部署成为工程落地的关键环节。SGLang作为专为提升LLM推理性能而设计的框架,在优化吞吐量…
verl支持哪些LLM架构?主流模型兼容性测试
verl支持哪些LLM架构?主流模型兼容性测试 1. verl 介绍 verl 是一个灵活、高效且可用于生产环境的强化学习(RL)训练框架,专为大型语言模型(LLMs)的后训练设计。它由字节跳动火山引擎团队开源,…
BAAI/bge-m3性能测试:不同语言混合处理能力
BAAI/bge-m3性能测试:不同语言混合处理能力 1. 引言 1.1 多语言语义理解的技术背景 随着全球化信息流动的加速,跨语言、多语言内容处理已成为自然语言处理(NLP)领域的重要挑战。传统的语义相似度模型往往局限于单一语言环境&am…
看完就想试!通义千问2.5-7B打造的百万字长文档处理案例
看完就想试!通义千问2.5-7B打造的百万字长文档处理案例 1. 引言:为何选择通义千问2.5-7B-Instruct进行长文本处理? 在当前大模型应用场景中,长文档理解与生成能力已成为衡量模型实用性的关键指标。无论是法律合同分析、科研论文…
语音识别新体验:基于SenseVoice Small实现文字与情感事件标签同步识别
语音识别新体验:基于SenseVoice Small实现文字与情感事件标签同步识别 1. 引言 1.1 语音识别技术的演进与挑战 随着深度学习和大模型技术的发展,语音识别(ASR)已从传统的“语音转文字”逐步迈向多模态语义理解阶段。传统ASR系统…