Skip to content

Commit d9241ce

Browse files
Merge branch 'master' into patch-1
2 parents 082ffeb + d1bb156 commit d9241ce

File tree

127 files changed

+7001
-36254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+7001
-36254
lines changed

.github/workflows/approved-label.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jobs:
55
name: Add "approved" label when approved
66
runs-on: ubuntu-latest
77
steps:
8-
- name: Add "approved" label when approved
9-
uses: pullreminders/label-when-approved-action@master
10-
env:
11-
APPROVALS: "1"
12-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13-
ADD_LABEL: "approved"
14-
REMOVE_LABEL: ""
8+
- name: Add "approved" label when approved
9+
uses: abinoda/label-when-approved-action@v1.0.7
10+
env:
11+
APPROVALS: "1"
12+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
ADD_LABEL: "approved"
14+
REMOVE_LABEL: ""

.github/workflows/awesome_workflow.yml

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,24 @@
11
name: Awesome CI Workflow
22
on: [push, pull_request]
33
permissions:
4+
pull-requests: write
45
contents: write
6+
issues: write
57

68
jobs:
79
MainSequence:
810
name: Code Formatter
911
runs-on: ubuntu-latest
1012
steps:
1113
- uses: actions/checkout@v4
14+
- uses: cpp-linter/cpp-linter-action@v2
15+
id: linter
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1218
with:
13-
fetch-depth: 0
14-
- uses: actions/setup-python@v4
15-
- name: requirements
16-
run: |
17-
sudo apt-get -qq update
18-
sudo apt-get -qq install clang-tidy clang-format
19-
# checks are passing with less errors when used with this version.
20-
# The default installs v6.0 which did not work out well in my tests
21-
- name: Setup Git Specs
22-
run: |
23-
git config --global user.name github-actions[bot]
24-
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
25-
- name: Filename Formatter
26-
run: |
27-
wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/filename_formatter.sh
28-
chmod +x filename_formatter.sh
29-
./filename_formatter.sh . .cpp,.hpp
30-
- name: Get file changes
31-
run: |
32-
git branch
33-
git diff --diff-filter=dr --name-only origin/master > git_diff.txt
34-
echo "Files changed-- `cat git_diff.txt`"
35-
- name: Configure for static lint checks
36-
# compiling first gives clang-tidy access to all the header files and settings used to compile the programs.
37-
# This will check for macros, if any, on linux and not for Windows. But the use of portability checks should
38-
# be able to catch any errors for other platforms.
39-
run: cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
40-
- name: Lint modified files
41-
shell: bash
42-
run: python3 scripts/file_linter.py
43-
- name: Commit and push changes
44-
run: |
45-
git diff DIRECTORY.md
46-
git commit -am "clang-format and clang-tidy fixes for ${GITHUB_SHA::8}" || true
47-
git push origin HEAD:$GITHUB_REF || true
19+
style: "file"
20+
tidy-checks: ".clang-tidy"
21+
thread-comments: ${{ github.event_name == 'pull_request' && 'update' }}
4822

4923
build:
5024
name: Compile checks
@@ -59,6 +33,8 @@ jobs:
5933
- uses: actions/checkout@v4
6034
with:
6135
submodules: true
36+
- name: GCC problem matcher
37+
uses: ammaraskar/[email protected]
6238
- run: |
6339
cmake -B ./build -S .
6440
cmake --build build --parallel 4

.github/workflows/gh-pages.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Doxygen CI
22

3-
on:
3+
on:
44
push:
55
branches: [master]
66

@@ -15,7 +15,7 @@ jobs:
1515
run: |
1616
brew install graphviz ninja doxygen
1717
- name: configure
18-
run: cmake -G Ninja -B ./build -S .
18+
run: cmake -G Ninja -Duse_libclang=ON -DCMAKE_CXX_COMPILER=clang++ -B ./build -S .
1919
- name: build
2020
run: cmake --build build -t doc
2121
- name: gh-pages
@@ -28,7 +28,7 @@ jobs:
2828
git config --global user.name "$GITHUB_ACTOR"
2929
git config --global user.email "[email protected]"
3030
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
31-
rm -rf d* && rm *.html && rm *.svg && rm *.map && rm *.md5 && rm *.png && rm *.js && rm *.css
31+
rm -rf d* && rm *.html && rm *.svg && rm *.map && rm *.md5 && rm *.png && rm *.js
3232
git add .
3333
cp -rp ./build/html/* . && rm -rf ./build && ls -lah
3434
git add .

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@ a.out
3434
*.out
3535
*.app
3636

37+
# Cache
38+
.cache/
39+
40+
# Build
3741
build/
3842
git_diff.txt

CMakeLists.txt

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
cmake_minimum_required(VERSION 3.22)
2-
project(Algorithms_in_C++
2+
project(TheAlgorithms/C++
33
LANGUAGES CXX
44
VERSION 1.0.0
55
DESCRIPTION "Set of algorithms implemented in C++."
66
)
77

8-
# set(CMAKE_CXX_CPPLINT "~/anaconda3/bin/cpplint --filter=-legal/copyright --std=c++11")
9-
# find_program(CLANG_FORMAT "clang-format")
10-
11-
set(CMAKE_CXX_STANDARD 11)
8+
# C++ standard
9+
set(CMAKE_CXX_STANDARD 17)
1210
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1311

12+
# Additional warnings and errors
1413
if(MSVC)
15-
# set(CMAKE_CXX_STANDARD 14)
1614
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
17-
endif(MSVC)
15+
add_compile_options(/W4 /permissive-)
16+
else()
17+
add_compile_options(-Wall -Wextra -Wno-register -Werror=vla)
18+
endif()
1819

1920
option(USE_OPENMP "flag to use OpenMP for multithreading" ON)
2021
if(USE_OPENMP)
@@ -38,6 +39,10 @@ add_subdirectory(graphics)
3839
add_subdirectory(probability)
3940
add_subdirectory(backtracking)
4041
add_subdirectory(bit_manipulation)
42+
add_subdirectory(dynamic_programming)
43+
add_subdirectory(greedy_algorithms)
44+
add_subdirectory(range_queries)
45+
add_subdirectory(operations_on_datastructures)
4146
add_subdirectory(data_structures)
4247
add_subdirectory(machine_learning)
4348
add_subdirectory(numerical_methods)
@@ -49,47 +54,30 @@ add_subdirectory(physics)
4954

5055
cmake_policy(SET CMP0054 NEW)
5156
cmake_policy(SET CMP0057 NEW)
57+
5258
find_package(Doxygen OPTIONAL_COMPONENTS dot dia)
53-
if(DOXYGEN_FOUND)
54-
set(DOXYGEN_GENERATE_MAN NO)
55-
set(DOXYGEN_USE_MATHJAX YES)
56-
set(DOXYGEN_GENERATE_HTML YES)
57-
# set(DOXYGEN_HTML_TIMESTAMP YES)
58-
set(DOXYGEN_EXTRACT_STATIC YES)
59-
set(DOXYGEN_INLINE_SOURCES YES)
60-
set(DOXYGEN_CREATE_SUBDIRS YES)
61-
set(DOXYGEN_EXTRACT_PRIVATE YES)
62-
set(DOXYGEN_GENERATE_TREEVIEW YES)
63-
set(DOXYGEN_STRIP_CODE_COMMENTS NO)
64-
set(DOXYGEN_EXT_LINKS_IN_WINDOW YES)
65-
set(DOXYGEN_BUILTIN_STL_SUPPORT YES)
66-
set(DOXYGEN_EXCLUDE_PATTERNS */build/*)
67-
set(DOXYGEN_ENABLE_PREPROCESSING YES)
68-
set(DOXYGEN_CLANG_ASSISTED_PARSING YES)
69-
set(DOXYGEN_FILE_PATTERNS *.cpp *.h *.hpp *.md)
70-
set(DOXYGEN_MATHJAX_EXTENSIONS TeX/AMSmath TeX/AMSsymbols)
71-
set(DOXYGEN_TAGFILES "doc/cppreference-doxygen-web.tag.xml=http://en.cppreference.com/w/")
59+
if(DOXYGEN_FOUND)
7260
if(MSVC)
7361
set(DOXYGEN_CPP_CLI_SUPPORT YES)
7462
endif()
75-
set(DOXYGEN_MATHJAX_RELPATH "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML")
63+
7664
if(Doxygen_dot_FOUND)
7765
set(DOXYGEN_HAVE_DOT YES)
78-
set(DOXYGEN_CALL_GRAPH YES)
79-
set(DOXYGEN_INTERACTIVE_SVG YES)
80-
set(DOXYGEN_DOT_IMAGE_FORMAT "svg")
8166
endif()
67+
8268
if(OPENMP_FOUND)
8369
set(DOXYGEN_PREDEFINED "_OPENMP=1")
8470
endif()
71+
8572
if(GLUT_FOUND)
8673
set(DOXYGEN_PREDEFINED ${DOXYGEN_PREDEFINED} "GLUT_FOUND=1")
8774
endif()
8875

8976
doxygen_add_docs(
9077
doc
91-
${PROJECT_SOURCE_DIR}
78+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
9279
COMMENT "Generate documentation"
80+
CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile
9381
)
9482
endif()
9583

DIRECTORY.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
## Cpu Scheduling Algorithms
4343
* [Fcfs Scheduling](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/cpu_scheduling_algorithms/fcfs_scheduling.cpp)
44+
* [Non Preemptive Sjf Scheduling](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/cpu_scheduling_algorithms/non_preemptive_sjf_scheduling.cpp)
4445

4546
## Data Structures
4647
* [Avltree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/data_structures/avltree.cpp)
@@ -94,7 +95,7 @@
9495
## Dynamic Programming
9596
* [0 1 Knapsack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/0_1_knapsack.cpp)
9697
* [Abbreviation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/abbreviation.cpp)
97-
* [Armstrong Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/armstrong_number.cpp)
98+
* [Armstrong Number Templated](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/armstrong_number_templated.cpp)
9899
* [Bellman Ford](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/bellman_ford.cpp)
99100
* [Catalan Numbers](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/catalan_numbers.cpp)
100101
* [Coin Change](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/coin_change.cpp)
@@ -106,11 +107,10 @@
106107
* [Floyd Warshall](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/floyd_warshall.cpp)
107108
* [House Robber](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/house_robber.cpp)
108109
* [Kadane](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/kadane.cpp)
109-
* [Kadane2](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/kadane2.cpp)
110110
* [Longest Common String](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/longest_common_string.cpp)
111111
* [Longest Common Subsequence](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/longest_common_subsequence.cpp)
112112
* [Longest Increasing Subsequence](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/longest_increasing_subsequence.cpp)
113-
* [Longest Increasing Subsequence (Nlogn)](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/longest_increasing_subsequence_(nlogn).cpp)
113+
* [Longest Increasing Subsequence Nlogn](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/longest_increasing_subsequence_nlogn.cpp)
114114
* [Longest Palindromic Subsequence](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/longest_palindromic_subsequence.cpp)
115115
* [Matrix Chain Multiplication](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/matrix_chain_multiplication.cpp)
116116
* [Maximum Circular Subarray](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/maximum_circular_subarray.cpp)
@@ -119,9 +119,10 @@
119119
* [Partition Problem](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/partition_problem.cpp)
120120
* [Searching Of Element In Dynamic Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/searching_of_element_in_dynamic_array.cpp)
121121
* [Shortest Common Supersequence](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/shortest_common_supersequence.cpp)
122-
* [Subset Sum](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/subset_sum.cpp)
122+
* [Subset Sum Dynamic](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/subset_sum_dynamic.cpp)
123123
* [Trapped Rainwater](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/trapped_rainwater.cpp)
124124
* [Tree Height](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/tree_height.cpp)
125+
* [Unbounded 0 1 Knapsack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/unbounded_0_1_knapsack.cpp)
125126
* [Word Break](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/dynamic_programming/word_break.cpp)
126127

127128
## Games
@@ -163,7 +164,7 @@
163164
* [Binary Addition](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/binary_addition.cpp)
164165
* [Boruvkas Minimum Spanning Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/boruvkas_minimum_spanning_tree.cpp)
165166
* [Digit Separation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/digit_separation.cpp)
166-
* [Dijkstra](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/dijkstra.cpp)
167+
* [Dijkstra Greedy](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/dijkstra_greedy.cpp)
167168
* [Gale Shapley](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/gale_shapley.cpp)
168169
* [Huffman](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/huffman.cpp)
169170
* [Jump Game](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/greedy_algorithms/jump_game.cpp)
@@ -339,7 +340,7 @@
339340
* [Persistent Seg Tree Lazy Prop](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/range_queries/persistent_seg_tree_lazy_prop.cpp)
340341
* [Prefix Sum Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/range_queries/prefix_sum_array.cpp)
341342
* [Segtree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/range_queries/segtree.cpp)
342-
* [Sparse Table](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/range_queries/sparse_table.cpp)
343+
* [Sparse Table Range Queries](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/range_queries/sparse_table_range_queries.cpp)
343344

344345
## Search
345346
* [Binary Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/HEAD/search/binary_search.cpp)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This repository is a collection of open-source implementation of a variety of al
2222
* Well documented source code with detailed explanations provide a valuable resource for educators and students alike.
2323
* Each source code is atomic using [STL classes](https://en.wikipedia.org/wiki/Standard_Template_Library) and _no external libraries_ are required for their compilation and execution. Thus, the fundamentals of the algorithms can be studied in much depth.
2424
* Source codes are [compiled and tested](https://github.com/TheAlgorithms/C-Plus-Plus/actions?query=workflow%3A%22Awesome+CI+Workflow%22) for every commit on the latest versions of three major operating systems viz., Windows, MacOS, and Ubuntu (Linux) using MSVC 19 2022, AppleClang 14.0.0, and GNU 11.3.0 respectively.
25-
* Strict adherence to [C++11](https://en.wikipedia.org/wiki/C%2B%2B11) standard ensures portability of code to embedded systems as well like ESP32, ARM Cortex, etc. with little to no changes.
25+
* Strict adherence to [C++17](https://en.wikipedia.org/wiki/C%2B%2B17) standard ensures portability of code to embedded systems as well like [ESP32](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/cplusplus.html#c-language-standard), [ARM Cortex](https://developer.arm.com/documentation/101458/2404/Standards-support/Supported-C-C---standards-in-Arm-C-C---Compiler), etc. with little to no changes.
2626
* Self-checks within programs ensure correct implementations with confidence.
2727
* Modular implementations and OpenSource licensing enable the functions to be utilized conveniently in other applications.
2828

backtracking/subarray_sum.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
#include <cassert> /// for assert
17+
#include <cstdint>
1718
#include <iostream> /// for IO operations
1819
#include <unordered_map> /// for unordered_map
1920
#include <vector> /// for std::vector

backtracking/subset_sum.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <cassert> /// for assert
13+
#include <cstdint>
1314
#include <iostream> /// for IO operations
1415
#include <vector> /// for std::vector
1516

backtracking/wildcard_matching.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
#include <cassert> /// for assert
15+
#include <cstdint>
1516
#include <iostream> /// for IO operations
1617
#include <vector> /// for std::vector
1718

0 commit comments

Comments
 (0)