STL 核心模块

很好!你想深入 STL(Standard Template Library)和容器算法,是学习 C++ 非常关键的一步。下面我给你整理一份STL 容器 + 算法的入门指南,适合从零起步掌握这部分内容。


🌟 一、STL 核心模块

STL 分为三大块,你主要先掌握前两块:

  1. 容器(Containers) 👉 存放数据的结构
  2. 算法(Algorithms) 👉 操作容器里的数据
  3. 迭代器(Iterators)👉 算法和容器的桥梁

📦 二、常用容器分类 + 用法示例

类型容器特点
顺序容器vector, list, deque有序访问,插入删除位置有限制
关联容器set, map自动排序,基于红黑树
无序容器unordered_set, unordered_map基于哈希表,查找快但无序
适配器stack, queue, priority_queue封装其他容器提供特定操作

例子:使用 vector

#include <vector>
#include <iostream>
using namespace std;int main() {vector<int> v = {1, 2, 3};v.push_back(4);       // 添加元素v.pop_back();         // 删除末尾cout << v[0] << endl; // 访问元素
}

🧠 三、常用算法(头文件 <algorithm>

STL 提供了 80 多种常用算法,先学这些最基础的:

分类代表函数用法示例
排序sort(v.begin(), v.end())排序 vector
查找find, count, binary_search判断是否存在某个元素
遍历for_each, transform应用函数到每个元素
修改reverse, replace, fill反转、替换、填充

例子:排序 + 查找

#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;int main() {vector<int> v = {3, 1, 4, 2};sort(v.begin(), v.end());      // 排序if (binary_search(v.begin(), v.end(), 3))cout << "Found 3" << endl;
}

🔄 四、迭代器的用法(配合容器+算法)

所有容器都有 .begin().end() 返回迭代器。

vector<int> v = {1, 2, 3};
for (auto it = v.begin(); it != v.end(); ++it)cout << *it << " ";

🛠 五、推荐学习顺序

  1. 掌握 vector, set, map 的基本用法
  2. 学会使用 sort, find, count, reverse 等常见算法
  3. 理解迭代器是怎么配合算法工作的
  4. 学会写 lambda 来配合 sortfor_each
  5. 开始写简单的项目/功能:统计词频、模拟排行榜、实现任务队列

好!下面是针对每类容器精心设计的小练习题 + 示例代码,每题只用一种容器,帮助你理解用法和适用场景:

🧱 1. 顺序容器练习题:vector

📌 题目:输入一组整数,输出其中所有大于5的数,按升序排列

✅ 示例代码:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;int main() {vector<int> nums = {3, 7, 1, 9, 5, 6};vector<int> result;for (int x : nums)if (x > 5) result.push_back(x);sort(result.begin(), result.end());  // 升序排序for (int x : result)cout << x << " ";  // 输出:6 7 9
}

🌲 2. 关联容器练习题:set

📌 题目:输入一组数字,输出去重后的升序结果

✅ 示例代码:

#include <iostream>
#include <set>
using namespace std;int main() {set<int> s;int a[] = {5, 1, 2, 2, 3, 5, 4};for (int x : a)s.insert(x);  // 自动排序+去重for (int x : s)cout << x << " ";  // 输出:1 2 3 4 5
}

⚡ 3. 无序容器练习题:unordered_map

📌 题目:统计字符串中每个字符的出现次数(频次统计)

✅ 示例代码:

#include <iostream>
#include <unordered_map>
using namespace std;int main() {string s = "abracadabra";unordered_map<char, int> freq;for (char c : s)freq[c]++;for (auto& p : freq)cout << p.first << ": " << p.second << endl;// 示例输出(顺序不固定):// a: 5// b: 2// r: 2// c: 1// d: 1
}

🎒 4. 容器适配器练习题:stack

📌 题目:检查一个括号字符串是否左右匹配

例如 "(()())" 匹配,"(()" 不匹配。

✅ 示例代码:

#include <iostream>
#include <stack>
using namespace std;bool isValid(string s) {stack<char> stk;for (char c : s) {if (c == '(') stk.push(c);else if (c == ')') {if (stk.empty()) return false;stk.pop();}}return stk.empty();
}int main() {string test = "(()())";cout << (isValid(test) ? "匹配" : "不匹配") << endl;
}

✅ 总结练习与容器匹配

容器小题练习关键词
vector筛选+排序线性数据
set去重+排序唯一集合
unordered_map统计频率快速查找
stack括号匹配后进先出

下面按 四大类 + 每类具体容器 给出简单易懂的例子和对应代码,帮助你快速掌握它们的用法。


1. 顺序容器(Sequence Containers)

1.1 vector

场景:存一组学生分数,按索引随机访问

#include <iostream>
#include <vector>
using namespace std;int main() {vector<int> scores = {85, 90, 78};scores.push_back(92);         // 在末尾添加一个分数cout << "第三个学生的分数是:" << scores[2] << endl;  // 随机访问return 0;
}

1.2 list

场景:存一条火车车厢编号,频繁在中间插入/删除

#include <iostream>
#include <list>
using namespace std;int main() {list<string> train = {"Car1", "Car3"};auto it = train.begin();++it;                          // 指向 "Car3"train.insert(it, "Car2");      // 在中间插入for (auto& c : train)cout << c << " ";          // 输出:Car1 Car2 Car3 return 0;
}

1.3 deque

场景:实现一个简单的滑动窗口

#include <iostream>
#include <deque>
using namespace std;int main() {deque<int> window;int nums[] = {1,2,3,4,5};for (int x : nums) {window.push_back(x);        // 新元素入队if (window.size() > 3)      // 窗口大小保持 3window.pop_front();     // 弹出最旧元素cout << "当前窗口:";for (int y : window) cout << y;cout << endl;}return 0;
}

2. 关联容器(Associative Containers)

2.1 set

场景:自动去重并升序存储数字

#include <iostream>
#include <set>
using namespace std;int main() {set<int> s = {4, 2, 5, 2, 3};// 重复的 2 会自动去掉,元素自动排序cout << "排序后的唯一元素:";for (int x : s) cout << x << " ";  // 输出:2 3 4 5return 0;
}

2.2 map

场景:模拟电话簿,用姓名查电话

#include <iostream>
#include <map>
using namespace std;int main() {map<string, string> phonebook;phonebook["Alice"] = "123-456";phonebook["Bob"]   = "987-654";cout << "Alice 的电话是:" << phonebook["Alice"] << endl;return 0;
}

3. 无序容器(Unordered Containers)

3.1 unordered_set

场景:快速检测某元素是否出现过

#include <iostream>
#include <unordered_set>
using namespace std;int main() {unordered_set<string> seen;string tokens[] = {"apple","banana","apple"};for (auto& t : tokens) {if (seen.count(t))cout << t << " 已出现过\n";else {cout << t << " 首次出现\n";seen.insert(t);}}return 0;
}

3.2 unordered_map

场景:统计字符串中每个字符的出现次数

#include <iostream>
#include <unordered_map>
using namespace std;int main() {string s = "banana";unordered_map<char,int> cnt;for (char c : s)cnt[c]++;for (auto& p : cnt)cout << p.first << " 出现了 " << p.second << " 次\n";return 0;
}

4. 容器适配器(Container Adapters)

4.1 stack

场景:检查括号匹配

#include <iostream>
#include <stack>
using namespace std;bool isValid(string s) {stack<char> st;for (char c : s) {if (c == '(') st.push(c);else if (c == ')') {if (st.empty()) return false;st.pop();}}return st.empty();
}int main() {cout << (isValid("(()())") ? "匹配" : "不匹配") << endl;return 0;
}

4.2 queue

场景:打印机任务队列,先进先出

#include <iostream>
#include <queue>
using namespace std;int main() {queue<string> jobs;jobs.push("doc1"); jobs.push("doc2");while (!jobs.empty()) {cout << "打印 " << jobs.front() << endl;jobs.pop();}return 0;
}

4.3 priority_queue

场景:任务调度,优先级高的先执行

#include <iostream>
#include <queue>
using namespace std;int main() {// 默认最大堆priority_queue<pair<int,string>> pq;pq.push({1,"低优先"}); pq.push({5,"高优先"});pq.push({3,"中优先"});while (!pq.empty()) {cout << pq.top().second << endl;pq.pop();}// 输出:高优先 → 中优先 → 低优先return 0;
}

区分 set, multiset, map, multimap


1. set

  • 特点:自动排序、去重
  • 典型场景:提取一段文本中的不重复单词并按字母序输出
#include <iostream>
#include <set>
#include <sstream>
#include <string>
using namespace std;int main() {string text = "apple orange banana apple pear banana";istringstream iss(text);set<string> s;string w;while (iss >> w) {s.insert(w);  // 重复单词只保留一个,自动按字母序排序}cout << "不重复单词(按序):";for (const auto& word : s) {cout << word << " ";}// 输出:banana apple orange pearreturn 0;
}

2. multiset

  • 特点:自动排序、允许重复
  • 典型场景:统计一组成绩的分布(但还想保留原始次数顺序)
#include <iostream>
#include <set>
using namespace std;int main() {multiset<int> scores = {85, 90, 78, 90, 85, 92};// 自动排序,但保留重复值cout << "所有成绩(升序,含重复):";for (int sc : scores) {cout << sc << " ";}// 输出:78 85 85 90 90 92return 0;
}

3. map

  • 特点:键唯一、自动排序 key → value
  • 典型场景:统计单词出现频率
#include <iostream>
#include <map>
#include <sstream>
#include <string>
using namespace std;int main() {string text = "apple banana apple pear banana apple";istringstream iss(text);map<string,int> freq;string w;while (iss >> w) {freq[w]++;  // key 不存在时自动插入,value 初始为 0}cout << "单词频率:\n";for (auto& p : freq) {cout << p.first << " -> " << p.second << "\n";}// 按字母序输出:// apple -> 3// banana -> 2// pear -> 1return 0;
}

4. multimap

  • 特点:允许重复 key → value(一个 key 可对应多个 value)
  • 典型场景:一个人选修多门课程
#include <iostream>
#include <map>
#include <string>
using namespace std;int main() {multimap<string, string> courses;courses.insert({"Alice", "Math"});courses.insert({"Bob",   "Physics"});courses.insert({"Alice", "English"});courses.insert({"Bob",   "Chemistry"});// 遍历所有同学及其课程cout << "选课列表:\n";for (auto& p : courses) {cout << p.first << " 选修 " << p.second << "\n";}// 如果只想看 Alice 的课程:cout << "\nAlice 的课程:\n";auto range = courses.equal_range("Alice");for (auto it = range.first; it != range.second; ++it) {cout << it->second << "\n";}// 输出:// Math// Englishreturn 0;
}

通过这四个例子,你可以看到:

  • set:帮你去重并排序
  • multiset:排序但保留重复
  • map:唯一 key → 单一 value
  • multimap:同一个 key 下可有多个 value

区分 unordered_set, unordered_multiset, unordered_map, unordered_multimap

好的,我把每个容器的例子都写得更详细一些,涵盖常用操作(插入、查找、删除、遍历等),并加上注释说明。


1. unordered_set(无序不重复集合)

场景:记录一段日志里出现过的错误代码,只关心是否出现过

#include <iostream>
#include <unordered_set>
using namespace std;int main() {// 准备一段“错误码”序列int errors[] = {101, 202, 303, 101, 404, 202, 505};// 定义 unordered_set 容器,记录首次出现的错误码unordered_set<int> seen;// 遍历所有错误码for (int code : errors) {// count 返回 0 或 1,表示容器里是否已有该元素if (seen.count(code)) {cout << "错误码 " << code << " 已记录过,跳过\n";} else {cout << "首次出现错误码 " << code << ",记录\n";seen.insert(code);  // 插入新元素}}cout << "\n最终记录的错误码有 " << seen.size() << " 个:";for (auto c : seen)             // 无序遍历cout << c << " ";cout << endl;// 删除某个错误码int to_remove = 303;if (seen.erase(to_remove))      // erase 返回删除的元素数量cout << "已删除错误码 " << to_remove << "\n";return 0;
}

要点

  • 插入:insert(val)
  • 查找:count(key)find(key)
  • 删除:erase(key)
  • 遍历:范围 for(顺序不固定)

2. unordered_multiset(无序可重复集合)

场景:统计商品售出记录中各商品的销售次数

#include <iostream>
#include <unordered_set>
using namespace std;int main() {// 假设售出商品 ID 列表int sales[] = {1001,1002,1001,1003,1002,1001,1004};// unordered_multiset 允许重复unordered_multiset<int> bag;// 插入所有售出记录for (int id : sales) {bag.insert(id);}// 想知道某个商品卖了多少次int query = 1001;cout << "商品 " << query << " 共售出 "<< bag.count(query) << " 次。\n";// 遍历所有记录(会重复显示)cout << "所有售出商品 ID(包含重复):";for (int id : bag)cout << id << " ";cout << endl;// 删除一次售出记录(只删除一个实例)auto it = bag.find(query);if (it != bag.end()) {bag.erase(it);cout << "删除一次 " << query << " 的记录后,剩余 "<< bag.count(query) << " 次。\n";}return 0;
}

要点

  • 插入:insert(val)
  • 统计:count(key)
  • 查找一个实例:find(key)
  • 删除单个实例:erase(iterator)erase(key)(后者会删掉所有实例)

3. unordered_map(无序键→值映射)

场景:统计一段文字里每个单词出现的次数,并支持查询、删除

#include <iostream>
#include <unordered_map>
#include <sstream>
using namespace std;int main() {string text = "apple orange banana apple pear banana";istringstream iss(text);// 定义字符到出现次数的映射unordered_map<string,int> freq;// 统计词频string w;while (iss >> w) {freq[w]++;  // 如果 key 不存在,会自动插入并初始化为 0}// 输出所有词频cout << "词频统计:\n";for (auto& p : freq) {cout << p.first << " -> " << p.second << "\n";}// 查询某个单词string query = "banana";auto it = freq.find(query);if (it != freq.end()) {cout << query << " 出现了 " << it->second << " 次\n";} else {cout << query << " 没出现过\n";}// 删除某个单词的统计freq.erase("pear");cout << "删除 pear 后,剩余 " << freq.size() << " 个单词记录。\n";return 0;
}

要点

  • 插入/修改:operator[]emplace(key,val)
  • 查找:find(key)
  • 删除:erase(key)erase(iterator)
  • 遍历:for (auto& p : map)

4. unordered_multimap(无序键→多值映射)

场景:一个作者可能有多本书,要存储“作者 → 书名”并支持查找、遍历

#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;int main() {// 定义作者到书名的多映射unordered_multimap<string,string> library;library.emplace("Alice", "C++ Primer");library.emplace("Bob",   "Effective C++");library.emplace("Alice", "STL 源码剖析");library.emplace("Bob",   "现代 C++ 设计");// 遍历全部条目cout << "馆藏列表:\n";for (auto& p : library) {cout << p.first << " 著《" << p.second << "》\n";}// 查找某位作者的所有书string author = "Alice";cout << "\n查询 " << author << " 的作品:\n";auto range = library.equal_range(author);for (auto it = range.first; it != range.second; ++it) {cout << it->second << "\n";}// 删除某本特定书(必须先找到对应 pair 的 iterator)for (auto it = range.first; it != range.second; ++it) {if (it->second == "C++ Primer") {library.erase(it);cout << "\n已删除 Alice 的《C++ Primer》\n";break;}}return 0;
}

要点

  • 插入:emplace(key,val)insert({key,val})
  • 查找所有值:equal_range(key) 返回 [first, second)
  • 删除单条记录:erase(iterator)

分别介绍这八种关联容器

一、有序关联容器(红黑树,所有操作 O(log n))

1. std::set<Key, Compare, Alloc>

  • 键唯一,自动按 Compare 排序(默认 <)。
  • 典型接口
    • insert(k)emplace(k):插入元素
    • erase(it)erase(key):按迭代器或键删除
    • find(key):查找,返回迭代器或 end()
    • count(key):键存在返回 1,否则 0
    • 范围查询:lower_bound(key)upper_bound(key)equal_range(key)
  • 遍历保证从小到大。
#include <iostream>
#include <set>
using namespace std;int main() {set<int> s;// 插入s.insert(3);s.insert(1);s.emplace(2);      // 总共 {1,2,3}// 查找if (s.find(2) != s.end())cout << "Found 2\n";// 遍历cout << "遍历 set:";for (int x : s) cout << x << ' ';   // 1 2 3cout << endl;// 下界、上界auto lb = s.lower_bound(2);  // 指向 2auto ub = s.upper_bound(2);  // 指向 3// 删除s.erase(1);   // 删除键为1的元素cout << "删除后大小:" << s.size() << endl;
}

2. std::multiset<Key, Compare, Alloc>

  • 允许重复键,其他与 set 相同。
  • 插入不会合并相同键;
  • 区间操作equal_range(key) 返回 [first, second)
#include <iostream>
#include <set>
using namespace std;int main() {multiset<string> ms;ms.insert("apple");ms.insert("banana");ms.insert("apple");  // 允许重复// 查看所有 "apple"auto range = ms.equal_range("apple");cout << "\"apple\" 出现次数:";for (auto it = range.first; it != range.second; ++it)cout << *it << ' ';cout << endl;  // apple apple// 删除所有 "apple"ms.erase(range.first, range.second);cout << "删除后大小:" << ms.size() << endl;
}

3. std::map<Key, T, Compare, Alloc>

  • 键唯一,每个键对应一个值。
  • 访问
    • operator[](key):不存在则插入默认值并返回引用
    • at(key):不存在抛 out_of_range
  • 查找/删除set
  • 遍历按键升序,访问 pair<const Key,T>
#include <iostream>
#include <map>
using namespace std;int main() {map<int, string> m;m[1] = "one";                 // 插入或修改m.insert({2, "two"});         // 插入// m[3] 默认插入 "",再赋值m[3] = "three";// 查找auto it = m.find(2);if (it != m.end())cout << "key=2, value=" << it->second << endl;// 范围遍历cout << "遍历 map:\n";for (auto& [k,v] : m)cout << k << " → " << v << "\n";// 区间删除 1 ≤ key < 3auto it1 = m.lower_bound(1);auto it3 = m.lower_bound(3);m.erase(it1, it3);cout << "删除区间后大小:" << m.size() << endl;
}

4. std::multimap<Key, T, Compare, Alloc>

  • 允许重复键,其他同 map
  • 取相同键所有值equal_range(key)
#include <iostream>
#include <map>
using namespace std;int main() {multimap<int, string> mm;mm.emplace(1, "uno");mm.emplace(1, "ichi");mm.emplace(2, "dos");auto range = mm.equal_range(1);cout << "key=1 的所有值:";for (auto it = range.first; it != range.second; ++it)cout << it->second << ' ';cout << endl;// 删除其中一个 pairauto it = range.first;mm.erase(it);cout << "删除一个后剩余:" << mm.count(1) << " 个\n";
}

二、无序关联容器(哈希表,平均 O(1),最坏 O(n))

1. std::unordered_set<Key, Hash, KeyEqual, Alloc>

  • 键唯一,底层是哈希桶+链表/开放寻址。
  • 常用接口
    • reserve(n):预留至少能放下 n 个元素
    • max_load_factor(f):设置最大负载因子
    • bucket_count()load_factor():查看当前桶数和负载
  • 查找/插入/删除平均 O(1)。
#include <iostream>
#include <unordered_set>
using namespace std;int main() {unordered_set<int> us;us.reserve(100);                   // 至少 100 个桶us.insert({3,1,4,1,5});            // 重复的1会被忽略cout << "元素:";for (int x : us) cout << x << ' '; // 无序输出cout << endl;cout << "count(1)=" << us.count(1) << endl;  // 1 或 0us.erase(3);cout << "erase后 size=" << us.size() << endl;
}

2. std::unordered_multiset<Key, Hash, KeyEqual, Alloc>

  • 允许重复键,其他同 unordered_set
  • 获取所有相同键equal_range(key)
#include <iostream>
#include <unordered_set>
using namespace std;int main() {unordered_multiset<int> ums;ums.insert(2);ums.insert(2);ums.insert(3);auto range = ums.equal_range(2);cout << "2 出现次数:";for (auto it = range.first; it != range.second; ++it)cout << *it << ' ';cout << endl;
}

3. std::unordered_map<Key, T, Hash, KeyEqual, Alloc>

  • 键唯一,哈希字典。
  • 访问mapoperator[]at()
  • reserverehash 可控制性能。
#include <iostream>
#include <unordered_map>
using namespace std;int main() {unordered_map<string,int> um;um.reserve(50);um["apple"] = 3;um.emplace("banana", 2);cout << "apple 个数:" << um["apple"] << endl;if (um.find("cherry")==um.end())cout << "no cherry\n";// 自定义哈希和相等struct Point { int x,y; };struct PointHash { size_t operator()(Point const& p) const noexcept {return p.x*31 + p.y;}};struct PointEq { bool operator()(Point const& a, Point const& b) const noexcept {return a.x==b.x && a.y==b.y;}};unordered_map<Point,string,PointHash,PointEq> mp;mp[{1,2}] = "A";cout << mp[{1,2}] << endl;
}

4. std::unordered_multimap<Key, T, Hash, KeyEqual, Alloc>

  • 允许重复键,其他同 unordered_map
  • 取所有同键equal_range
#include <iostream>
#include <unordered_map>
using namespace std;int main() {unordered_multimap<int,string> umm;umm.emplace(1,"a");umm.emplace(1,"b");umm.emplace(2,"c");for (auto it = umm.equal_range(1).first; it != umm.equal_range(1).second; ++it)cout << it->second << ' ';cout << endl;
}

三、选型建议

  1. 需要排序/范围查询 → 选有序(set/map)。
  2. 追求最快查插且无需排序 → 选无序(unordered_*)。
  3. 是否允许重复键 → 普通版 vs. multi 版。
  4. 自定义排序/哈希 → 提供 CompareHash/KeyEqual

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/80134.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2024沈阳区域赛,D - Dot Product Game

题目链接 树状数组求逆序对 #include<bits/stdc.h> using namespace std; using lllong long; typedef pair<int,int>PII; typedef priority_queue<int> upq; typedef priority_queue<int,vector<int>,greater<int>> dpq; const int M99…

简易博客点赞系统实现

简易博客点赞系统 好久没写 Java 了&#xff0c;整个简单的项目进行康复训练。 基于 Spring Boot SSM MySQL Mybatis-Plus Knife4j Swagger 的一个简易博客点赞系统 开源地址&#xff1a;https://github.com/FangMoyu/simple-thumb 功能 登录获取当前登录用户获取博客…

一个既简单又诡异的问题

public class DaYaoGuai {static String s;public static void main(String[] args) {Thread t1 new Thread(){Overridepublic void run() {try {Thread.sleep(1000);} catch (InterruptedException e) {throw new RuntimeException(e);}s"深圳";}};t1.start();Thre…

使用docker在manjaro linux系统上运行windows和ubuntu

因为最近项目必须要使用指定版本的solidworks和maxwell&#xff08;都只能在win系统上使用&#xff09;, 且目前的ubuntu容器是没有桌面的&#xff0c;导致我运行不了一些带图形的ros2功能。无奈之下&#xff0c;决定使用docker-compose写一下配置文件&#xff0c;彻底解决问题…

Elasticsearch中的_source字段讲解

_source 在 Elasticsearch 查询中用于限制返回的字段,类似于 SQL 中的 SELECT 指定列。 代码示例: esSearchResults = es_service.search_documents({"query": {"terms": {"file_id":

【论文阅读20】-CNN-Attention-BiGRU-滑坡预测(2025-03)

这篇论文主要探讨了基于深度学习的滑坡位移预测模型&#xff0c;结合了MT-InSAR&#xff08;多时相合成孔径雷达干涉测量&#xff09;观测数据&#xff0c;提出了一种具有可解释性的滑坡位移预测方法。 [1] Zhou C, Ye M, Xia Z, et al. An interpretable attention-based deep…

C++ 的 IO 流

&#x1f4ac; &#xff1a;如果你在阅读过程中有任何疑问或想要进一步探讨的内容&#xff0c;欢迎在评论区畅所欲言&#xff01;我们一起学习、共同成长~&#xff01; &#x1f44d; &#xff1a;如果你觉得这篇文章还不错&#xff0c;不妨顺手点个赞、加入收藏&#xff0c;并…

spring cloud gateway前面是否必须要有个nginx

在 **"客户端 → Nginx (前置限流) → Spring Cloud Gateway → 微服务(Sentinel 熔断限流)"** 的架构中&#xff0c;**Spring Cloud Gateway 前面并不强制要求必须有 Nginx**&#xff0c;是否需要取决于具体场景。以下是详细分析&#xff1a; 一、必须使用 Nginx 的…

Spark和Hadoop之间的对比和联系

&#xff08;一&#xff09;Spark概述 Spark是一种基于内存的快速、通用、可拓展的大数据分析计算引擎。Hadoop是一个分布式系统基础架构。 1&#xff09;官网地址&#xff1a;Apache Spark™ - Unified Engine for large-scale data analytics 2&#xff09;文档查看地址&…

多线程进阶(Java)

注&#xff1a;此博文为本人学习过程中的笔记 1.常见的锁策略 当我们需要自己实现一把锁时&#xff0c;需要关注锁策略。Java提供的synchronized已经非常好用了&#xff0c;覆盖了绝大多数的使用场景。此处的锁策略并不是和Java强相关的&#xff0c;只要涉及到并发编程&#…

c++STL——stack、queue、priority_queue的模拟实现

文章目录 stack、queue、priority_queue的模拟实现使用部分模拟实现容器适配器deque的介绍原理真实结构deque的迭代器deque的操作deque的优缺点 stack的模拟实现按需实例化queue的模拟实现priority_queue的模拟实现为何引入仿函数代码实现 stack、queue、priority_queue的模拟实…

【深度学习—李宏毅教程笔记】Transformer

目录 一、序列到序列&#xff08;Seq2Seq&#xff09;模型 1、Seq2Seq基本原理 2、Seq2Seq模型的应用 3、Seq2Seq模型还能做什么&#xff1f; 二、Encoder 三、Decoder 1、Decoder 的输入与输出 2、Decoder 的结构 3、Non-autoregressive Decoder 四、Encoder 和 De…

C++镌刻数据密码的树之铭文:二叉搜索树

文章目录 1.二叉搜索树的概念2.二叉搜索树的实现2.1 二叉搜索树的结构2.2 二叉搜索树的节点寻找2.2.1 非递归2.2.2 递归 2.3 二叉搜索树的插入2.3.1 非递归2.3.2 递归 2.4 二叉搜索树的删除2.4.1 非递归2.4.2 递归 2.5 二叉搜索树的拷贝 3.二叉树的应用希望读者们多多三连支持小…

系统架构设计师:流水线技术相关知识点、记忆卡片、多同类型练习题、答案与解析

流水线记忆要点‌ ‌公式 总时间 (n k - 1)Δt 吞吐率 TP n / 总时间 → 1/Δt&#xff08;max&#xff09; 加速比 S nk / (n k - 1) | 效率 E n / (n k - 1) 关键概念 周期&#xff1a;最长段Δt 冲突‌&#xff1a; ‌数据冲突&#xff08;RAW&#xff09; → 旁路/…

强制重装及验证onnxruntime-gpu是否正确工作

#工作记录 我们经常会遇到明明安装了onnxruntime-gpu或onnxruntime后&#xff0c;无法正常使用的情况。 一、强制重新安装 onnxruntime-gpu 及其依赖 # 强制重新安装 onnxruntime-gpu 及其依赖 pip install --force-reinstall --no-cache-dir onnxruntime-gpu1.18.0 --extra…

桌面我的电脑图标不见了怎么恢复 恢复方法指南

在Windows操作系统中&#xff0c;“我的电脑”或在较新版本中称为“此电脑”的图标&#xff0c;是访问硬盘驱动器、外部存储设备和系统文件的重要入口。然而&#xff0c;有些用户可能会发现桌面上缺少了这个图标&#xff0c;这可能是由于误操作、系统设置更改或是不小心删除造成…

2025.04.20【Lollipop】| Lollipop图绘制命令简介

Customize markers See the different options allowing to customize the marker on top of the stem. Customize stems See the different options allowing to customize the stems. 文章目录 Customize markersCustomize stems Lollipop图简介R语言中的Lollipop图使用ggp…

docker-compose搭建kafka

1、单节点docker-compose.yml version: 3 services:zookeeper:image: zookeeper:3.8container_name: zookeeperports:- "2181:2181"volumes:- ./data/zookeeper:/dataenvironment:ZOO_MY_ID: 1ZOO_MAX_CLIENT_CNXNS: 100kafka:image: bitnami/kafka:3.7container_na…

【问题】一招解决vscode输出和终端不一致的困扰

背景&#xff08;闲话Trae&#xff09; Trae是挺好&#xff0c;用了几天&#xff0c;发现它时不时检查文件&#xff0c;一检测就转悠半天&#xff0c;为此我把当前环境清空&#xff0c;就留一个正在调的程序&#xff0c;结果还照样检测&#xff0c;虽然没影响什么&#xff0c;…

Git,本地上传项目到github

一、Git的安装和下载 https://git-scm.com/ 进入官网&#xff0c;选择合适的版本下载 二、Github仓库创建 点击右上角New新建一个即可 三、本地项目上传 1、进入 要上传的项目目录&#xff0c;右键&#xff0c;选择Git Bash Here&#xff0c;进入终端Git 2、初始化临时仓库…