My collection of algorithm and data structure solutions.
- (Optional)Install vcpkg :
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
- add install path to system environment variable
VCPKG_ROOT : set VCPKG_ROOT="C:\path\to\vcpkg"; set PATH=%VCPKG_ROOT%;%PATH%
- Install Xmake :
winget install xmake
- Develop with VS:
- Run
xmake project -k vsxmake -m "debug,release"
- Open the generated VS solution file in
vsxmake20xx folder. Exercise projects are grouped by their source path, such as Algorithms/binary_search, and source, header, metadata, and test files appear directly beneath their target.
- Choose Release/Debug x64 and Build in Visual Studio.
- Develop with VSCode:
- (Optional) Set Debug/Release mode:
xmake config -m [debug|release] -y
- (Optional) Make compile_commands.json file:
xmake project -k compile_commands .vscode
- Open vscode with Developer Command Prompt for VSxx
- Run an Exercise target:
- Build:
xmake build xxx
- Run:
xmake run xxx [-d]
Each Exercise is built as an independent Catch2 test executable. Xmake manages Catch2 3.15.x, discovers Exercise directories recursively, and creates one target for every valid exercise.json plus *_test.cpp pair. Every Exercise depends on the basic support library and is excluded from the default build.
- Create a Problem Exercise while retaining the problem's native public API:
# Simple
xmake new --kind=problem --root=algorithms/sort --id=LC215 --slug=kth_largest_element
# Full
xmake new --kind=problem --root=algorithms/sort --id=LC215 --slug=kth_largest_element `
--name="Kth Largest Element" --difficulty=Medium `
--tip="Quick select" --url=https://leetcode.com/problems/kth-largest-element-in-an-array/
This maps to directory and target lc215_kth_largest_element, namespace AlgoCpp::Problem::Algorithm::LC215, and Catch2 tags [problem][algorithm][sort][lc215].
- Create a reusable Template Exercise without an external problem ID:
xmake new --kind=template --root=data_structures/array --slug=dynamic_array
This maps to directory and target ds_dynamic_array, namespace AlgoCpp::Template::DataStructure::DynamicArray, and tags [template][data_structure][array][dynamic_array]. The initial scaffold contains commented interface examples and a failing placeholder test; replace that placeholder with real assertions after choosing the Exercise's natural API.
- The top-level root determines the namespace domain:
algorithms → Algorithm, data_structures → DataStructure, and reviews → Review. Problem IDs and slugs are safely normalized and reported. Unsafe input, an unsupported root, an existing target, or a duplicate Problem ID fails without leaving a partial Exercise. --url is optional for both Problem and Template Exercises; when supplied, it is stored in metadata and emitted once as // refs : URL above the generated header.
A typical Exercise is:
lc215_kth_largest_element/
├── kth_largest_element.h
├── kth_largest_element.cpp
├── kth_largest_element_test.cpp
├── duplicates_test.cpp # optional; any number of *_test.cpp files
└── exercise.json
Use the same Catch2 TEST_CASE form for Huawei, LeetCode, and Template Exercises; invoke each Exercise through its natural public API:
TEST_CASE("LC215 finds the kth largest element", "[problem][algorithm][sort][lc215]")
{
Solution solution;
std::vector<int> nums{3, 2, 1, 5, 6, 4};
REQUIRE(solution.findKthLargest(nums, 2) == 5);
}
TEST_CASE("HJ02 counts characters without case sensitivity", "[problem][review][huawei][hj02]")
{
REQUIRE(CountChar("ABCabc", 'A') == 2);
}
Run one Exercise or every Exercise Test:
xmake run lc215_kth_largest_element
xmake test
exercise.json is the catalog source of truth. Regenerate the managed README region with xmake index, or verify that it is current without writing via xmake index --check. The index follows the algorithms and data_structures directory categories; Review Exercises remain buildable but are intentionally omitted.