Topics | Badges / URLs |
---|---|
License | |
Code Style | Google’s C++ style guide (Clang-Format Style Options) |
Common Functions | |
Programming Topics | |
CodeQL |
C language local leetcode practice overall folder structure:
- Prerequisite - This folder contains the basic configuration files and common function modules before getting started with the local leetcode practice.
- VSCode_Settings - VSCode settings
- Clean_Exe - Scripts to clean all .exe files
- Common_Functions - Common C functions used by different programming topics with quality check workflows deployed.
- Programming_Topics - (Programming Carl Series / Labuladong's Algorithm Cheat Sheet) - This folder contains the leetcode practice questions organized by programming topics.
- Misc - This folder contains miscellaneous topics.
To ensure code quality, all shared common code based on different programming topics will be placed in the Common_Functions folder following these workflows:
Workflows Functionality Source Code Code Style Check commonFuncLint.yml Unit Test (Google Test) commonFuncTest.yml
To start getting hands on the project, the fundamental code structure of each question is as follows:
. ├── cfg │ ├── compile_cfg.h /* common function configuration file */ │ └── method_cfg.h /* solution method configuration file */ ├── doc │ ├── sketch.drawio /* drawing sketch file */ │ └── sketch.excalidraw /* drawing sketch file */ ├── inc │ └── solution_name.h /* solution header file */ ├── src │ ├── solution_name__method_name_01.c /* solution method 01 source file */ │ ├── solution_name__method_name_02.c /* solution method 02 source file */ │ ├── ... │ └── solution_name__method_name_xx.c /* solution method XX source file */ └── main.c /* entry point */The call hierarchy between files is as follow:
The
main.c
file is the entry point of the program, which calls the solution method in thesolution_name__method_name_xx.c
file. Meanwhile, themain.c
file also contains the test cases for the selected solution method.The
cfg
folder contains the configuration files for the common functions and solution methods.
The
compile_cfg.h
file is the configuration file for common functions. By toggling the#define
macro, the corresponding common function can be enabled or disabled during compilation.The
method_cfg.h
file is the configuration file for solution methods. By toggling the#define
macro, the corresponding solution method can be enabled or disabled during compilation.The
doc
folder contains the documentation files and drawing sketches for the question.The
inc
folder contains the header files for the solution methods.The
src
folder contains the source files for the solution methods.
- The
solution_name__method_name_xx.c
file is the source file for a specific solution method. By toggling the#define
macro in themethod_cfg.h
file, the corresponding solution method can be enabled or disabled during compilation.For a complete example, please refer to the following file:
F02_Programming_Topics\F01_Data_Structure\01_Array\01_binarySearch\main.c
Flowchart source file: compilation_structure.drawio (hediet.vscode-drawio extension required)
- Windows
- Ubuntu
- Python 3.12.1
- gcc.exe (Rev7, Built by MSYS2 project) 13.1.0
- g++.exe (Rev7, Built by MSYS2 project) 13.1.0
- GNU gdb (GDB) 13.2
To execute the source code in VSCode, choose the desired
main.c
file and navigate to the following tab and options in the VSCode interface:Terminal -> Run Task... -> Build & Run Current Fileor simply press
Ctrl + Shift + BSource code: tasks.json and python build.py.
The
Code Runner
vscode extension provides a convenient way to execute themain.c
file directly.Source code: settings.json.
The gcc compilation process is as follows:
Search for the header files in
/01_Common_Functions/inc/commonDef/
and/01_Common_Functions/inc/
folders.Search for the header files in
${fileDirname}/cfg/
and${fileDirname}/inc/
folder.Search and compile all the source files in
/01_Common_Functions/src/*.c
and${fileDirname}/src/*.c
with${fileDirname}/main.c
as the entry point.Generate the executable file in
${fileDirname}/
folder with namemain.exe
.Source code: python build.py and settings.json.
To facilitate source code debugging in VSCode, select the
main.c
file that you wish to run. First, build and run the source code as described in the previous section. Then, click the following button in VSCode:Run and Debug (Ctil+Shift+D) -> (gdb) Debug Mainor simply press
F5Source code: launch.json.
To ensure a clean development environment, it is important to remove unnecessary executable files. The following steps can be used to clean all .exe files:
First, open the terminal by pressing
ctrl + ~then run
.\F00_Prerequisite\01_Clean_Exe\killExes.bat /* windows system */ ./F00_Prerequisite/01_Clean_Exe/killexe.sh /* linux system */Source code: killExes.bat and killExes.sh.
Now, please feel free to start the leetcode practice journey by selecting the desired programming topic in the Programming_Topics folder.
If there are any questions, please feel free to create an issue in the Issues or start a discussion in the Discussions.