feat(algo): 实现冒泡排序算法(基础版 / 优化版 / 模板版)#1
Draft
str2num wants to merge 4 commits into
Draft
Conversation
- 新增 .gitignore,排除 build/ 与常见编译产物 - 新增 CMakeLists.txt,C++17 标准,开启 -Wall/-Wextra/-Wpedantic - 默认 Release 构建,目标包含静态库 bubble_sort 与可执行 bubble_sort_demo Co-authored-by: str2num <zzpeng863@163.com>
- src/bubble_sort.h: 声明 algo::BubbleSort(基础版)、 algo::BubbleSortOptimized(提前退出优化版)以及模板版本 BubbleSort<T, Compare>(std::vector<T>*, Compare) - src/bubble_sort.cc: 基础版与优化版实现 - src/main.cc: 演示 4 种调用:C 数组基础版/优化版、 std::vector<double> 默认升序、std::vector<int> 自定义降序 - 严格遵循 Google C++ Style,缩进改为 4 空格(用户规则 1) - 头文件与实现同目录,未拆分 include/(用户规则 5) Co-authored-by: str2num <zzpeng863@163.com>
- docs/01_你当前使用哪个大模型.md: 本次会话的 plan、技术方案、 系统变更说明与构建/验证记录(用户规则 4、7) - docs/prompt_log.md: 用户输入提示词日志(用户规则 6) Co-authored-by: str2num <zzpeng863@163.com>
Co-authored-by: str2num <zzpeng863@163.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
新增冒泡排序(Bubble Sort)C++ 实现,并搭建 CMake 构建脚手架。源码遵循 Google C++ Style,按用户偏好将缩进改为 4 空格;头文件与实现位于同一
src/目录,未拆分独立的include/。变更内容
CMakeLists.txt(C++17,开启-Wall -Wextra -Wpedantic,默认Release).gitignore,排除build/与常见编译产物src/bubble_sort.h:声明algo::BubbleSort(基础版)、algo::BubbleSortOptimized(提前退出优化版)以及模板版本BubbleSort<T, Compare>(std::vector<T>*, Compare)bubble_sort.cc:基础版与优化版实现main.cc:演示程序,覆盖 4 种调用方式docs/01_你当前使用哪个大模型.md:会话 plan、技术方案、系统变更与验证记录prompt_log.md:用户输入提示词日志技术要点
O(n^2)双层循环,相邻逆序则交换swapped标志位,序列已有序时提前退出,最好情况O(n)std::less<T>升序,可传入std::greater<T>{}等自定义比较器验证
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ cmake --build build -j ./build/bubble_sort_demo实际输出(已通过):
环境备注
本环境
/usr/bin/c++实际链接到clang++ 18,但仅安装了 GCC 13 的libstdc++,clang 默认选 GCC 14 multilib 会出现cannot find -lstdc++。配置 CMake 时需通过-DCMAKE_CXX_COMPILER=g++显式指定 GCC。建议后续通过 env-setup agent 修复(安装libstdc++-14-dev或锁定默认编译器)。提交历史
build:添加.gitignore与 CMake 顶层构建脚本feat(algo):实现冒泡排序算法及演示程序docs:新增会话 plan 文档与提示词日志