⚡ 编程实验室🏗️ HTML🎨 CSS⚡ JavaScript🐍 Python🗄️ SQL☕ Java⚛️ React💚 Vue🟢 Node.js⚙️ C语言🐘 PHP🐹 Go🔷 TypeScript🐬 MySQL🔧 C++🎯 C#🦀 Rust🅱️ Bootstrap💡 jQuery🎸 Django🍃 MongoDB👗 Sass🎪 Kotlin📊 R语言📋 XML📊 Excel🐘 PostgreSQL🐳 Docker🅰️ Angular🎮 游戏🏠 网站首页

C++ algorithm 算法库

sort/unique/find/count/accumulate · 难度:进阶 · +20XP

algorithm 库

C++ algorithm 库提供 70+ 算法函数。配合 Lambda 表达式,数据处理极其强大。

常用算法

vector v = {3,1,4,1,5,9,2,6};
// 排序
sort(v.begin(), v.end());                    // 升序
sort(v.begin(), v.end(), greater());    // 降序
// 去重
sort(v.begin(), v.end());
auto it = unique(v.begin(), v.end());
v.erase(it, v.end());
// 查找
count(v.begin(), v.end(), 5);               // 计数
auto it = find(v.begin(), v.end(), 5);       // 查找
count_if(v.begin(), v.end(), [](int n){return n%2==0;});  // 条件计数
// 聚合
int sum = accumulate(v.begin(), v.end(), 0);
auto mx = *max_element(v.begin(), v.end());
auto mn = *min_element(v.begin(), v.end());
Ctrl+Enter
🚀 升级VIP
解锁全部课程+AI助手

🏆 学习排行

加载中...

📊 统计

📖 105 篇
0 完成
🔥 0