# SortAlgorithms — 三种经典排序算法(C++17) ## 功能 使用纯 C++ 实现的三种排序算法,对整型数组进行**升序**排列: 1. **冒泡排序** (`bubbleSort`) — 相邻元素比较交换,稳定,O(n²) 2. **快速排序** (`quickSort`) — 分治递归,不稳定,平均 O(n log n) 3. **选择排序** (`selectionSort`) — 每轮选最小交换,不稳定,O(n²) ## 工程结构 ``` SortAlgorithms/ ├── CMakeLists.txt ├── README.md ├── include/ │ └── app.hpp # 公开函数声明(Doxygen 注释) ├── src/ │ ├── app.cpp # 排序算法实现 │ └── main.cpp # 命令行演示入口 └── tests/ └── basic_test.cpp # 基于 assert 的单元测试 ``` ## 编译与运行 ### 方式一:直接构建 ```bash mkdir build && cd build cmake .. cmake --build . ./SortAlgorithms # 运行演示 ./SortAlgorithms_test # 运行测试 ``` ### 方式二:使用 CMake 预设(如有) ```bash cmake --preset default cmake --build build ``` ## 接口说明 所有函数均定义在命名空间 `sort` 中,见 `include/app.hpp`。 ```cpp namespace sort { /// @brief 冒泡排序(升序) void bubbleSort(int arr[], int n); /// @brief 快速排序(递归入口) void quickSort(int arr[], int n); /// @brief 快速排序递归核心 void quickSort(int arr[], int low, int high); /// @brief 选择排序(升序) void selectionSort(int arr[], int n); } // namespace sort ``` ## 约束 - C++17 标准 - 不使用 `std::sort` 等标准库排序函数 - 支持空数组和单元素数组