-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
feat: update to CXX standard 17 and add CMakeLists file to directories without them #2746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
realstealthninja
merged 50 commits into
TheAlgorithms:master
from
realstealthninja:cmake
Nov 4, 2024
Merged
Changes from 43 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
ed217d7
chore: add cache and build comment to git ignore
realstealthninja 79dd912
fix: add cmakelists to dynamic programming
realstealthninja b6ac253
fix: add cmakelists to greedy_algorithms
realstealthninja 3a442a0
fix: add cmakelists to operations_on_datastructures
realstealthninja c98fe80
fix: add cmakelists to range_queries
realstealthninja 2b40841
fix: add `dynamic_programmin`, `greedy_algorithms`, `range_queries` a…
realstealthninja 939ca4a
fix: init of transform_reduce in dynamic_programming
realstealthninja 8ed74c6
fix: add an include for functional in catalan_numbers
realstealthninja e3ae1d1
chore: bump CXX standard to 20
realstealthninja 4e524df
revert: bump CXX standard to 20
realstealthninja 382e9b2
chore: bump c++ version to 17 and add justification
realstealthninja a71fa6d
fix: compilation error in catalan numbers
realstealthninja 8d260bf
fix: add <set> header to longest increasing subsequence nlogn
realstealthninja 01cb061
fix: add cmath & algorithm header to mo.cpp
realstealthninja cf96959
fix: remove register key word from fast integer
realstealthninja 7ca7b58
fix: replace using namespace std with std::cin and std::cout
realstealthninja bddae75
docs: typo in c++17
realstealthninja 48f03b2
fix: memory leak in bellman_ford
realstealthninja 7da9561
fix: typo in bellman_ford
realstealthninja c7064a6
fix: typo in word_break
realstealthninja 7984cd4
fix: dynamic array in coin_change
realstealthninja efea5c6
fix dynamic array in egg_dropping puzzle
realstealthninja 747657d
Merge branch 'master' into cmake
realstealthninja 153a0dc
chore: remove unnecessary comment
realstealthninja 973eb90
fix: add vla to be an error
realstealthninja 3bed814
chore: add extra warnings
realstealthninja 49e9269
fix: use add_compile options instead of set()
realstealthninja 46f423c
fix: compile options are not strings
realstealthninja b796161
fix: vla in floyd_warshall
realstealthninja 3091f15
fix: vla in egg_dropping_puzzel
realstealthninja 94ca2df
fix: vla in coin_change
realstealthninja f7154b7
fix: vla in edit_distance
realstealthninja 4db1f40
fix: vla in floyd_warshall
realstealthninja 2b278e9
feat: remove kadane and replace it with kadane2
realstealthninja a0abcbe
fix: vla in longest_common_subsequence
realstealthninja 77e7eba
fix: int overflow in floyd_warshall
realstealthninja 1c2e186
fix: vla in lisnlogn
realstealthninja a16a4bc
fix: use const vector& instead of array
realstealthninja 6a55384
fix: use dynamic array instead of vla in knapsack
realstealthninja 1ed8329
fix: use of and in msvc is unsupported by default adding permissive f…
realstealthninja 7a16c31
test: make executables the tests themselves
realstealthninja 40be378
Revert "test: make executables the tests themselves"
realstealthninja 334fb7d
Merge branch 'master' into cmake
realstealthninja 79d40fb
fix: make dist constant in print
realstealthninja 62faa00
Merge branch 'master' into cmake
realstealthninja b4adae8
Merge branch 'master' into cmake
realstealthninja c4fa878
Merge branch 'master' into cmake
realstealthninja e004861
Merge branch 'master' into cmake
realstealthninja 902e297
fix: namespace issue in unbounded_0_1
realstealthninja 8e329d3
fix: include cstdint to fix compilation
realstealthninja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,9 @@ a.out | |
*.out | ||
*.app | ||
|
||
# Cache | ||
.cache/ | ||
|
||
# Build | ||
build/ | ||
git_diff.txt |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# If necessary, use the RELATIVE flag, otherwise each source file may be listed | ||
# with full pathname. RELATIVE may makes it easier to extract an executable name | ||
# automatically. | ||
file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) | ||
# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) | ||
# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) | ||
foreach( testsourcefile ${APP_SOURCES} ) | ||
# I used a simple string replace, to cut off .cpp. | ||
string( REPLACE ".cpp" "" testname ${testsourcefile} ) | ||
add_executable( ${testname} ${testsourcefile} ) | ||
|
||
set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) | ||
if(OpenMP_CXX_FOUND) | ||
target_link_libraries(${testname} OpenMP::OpenMP_CXX) | ||
endif() | ||
install(TARGETS ${testname} DESTINATION "bin/dynamic_programming") | ||
|
||
endforeach( testsourcefile ${APP_SOURCES} ) |
File renamed without changes.
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,74 @@ | ||
/** | ||
* @file | ||
* @brief Implementation of [Kadane | ||
* Algorithm](https://en.wikipedia.org/wiki/Kadane%27s_algorithm) | ||
* | ||
* @details | ||
* Kadane algorithm is used to find the maximum sum subarray in an array and | ||
* maximum sum subarray problem is the task of finding a contiguous subarray | ||
* with the largest sum | ||
* | ||
* ### Algorithm | ||
* The simple idea of the algorithm is to search for all positive | ||
* contiguous segments of the array and keep track of maximum sum contiguous | ||
* segment among all positive segments(curr_sum is used for this) | ||
* Each time we get a positive sum we compare it with max_sum and update max_sum | ||
* if it is greater than curr_sum | ||
* | ||
* @author [Ayush Singh](https://github.com/ayush523) | ||
*/ | ||
#include <array> | ||
#include <climits> | ||
#include <iostream> | ||
|
||
int maxSubArraySum(int a[], int size) { | ||
int max_so_far = INT_MIN, max_ending_here = 0; | ||
|
||
for (int i = 0; i < size; i++) { | ||
max_ending_here = max_ending_here + a[i]; | ||
if (max_so_far < max_ending_here) | ||
max_so_far = max_ending_here; | ||
|
||
if (max_ending_here < 0) | ||
max_ending_here = 0; | ||
/** | ||
* @namespace dynamic_programming | ||
* @brief Dynamic Programming algorithms | ||
*/ | ||
namespace dynamic_programming { | ||
/** | ||
* @namespace kadane | ||
* @brief Functions for | ||
* [Kadane](https://en.wikipedia.org/wiki/Kadane%27s_algorithm) algorithm. | ||
*/ | ||
namespace kadane { | ||
/** | ||
* @brief maxSubArray function is used to calculate the maximum sum subarray | ||
* and returns the value of maximum sum which is stored in the variable max_sum | ||
* @tparam N number of array size | ||
* @param n array where numbers are saved | ||
* @returns the value of maximum subarray sum | ||
*/ | ||
template <size_t N> | ||
int maxSubArray(const std::array<int, N> &n) { | ||
int curr_sum = | ||
0; // declaring a variable named as curr_sum and initialized it to 0 | ||
int max_sum = INT_MIN; // Initialized max_sum to INT_MIN | ||
for (int i : n) { // for loop to iterate over the elements of the array | ||
curr_sum += n[i]; | ||
max_sum = std::max(max_sum, curr_sum); // getting the maximum value | ||
curr_sum = std::max(curr_sum, 0); // updating the value of curr_sum | ||
} | ||
return max_so_far; | ||
return max_sum; // returning the value of max_sum | ||
} | ||
} // namespace kadane | ||
} // namespace dynamic_programming | ||
|
||
/** | ||
* @brief Main function | ||
* @returns 0 on exit | ||
*/ | ||
int main() { | ||
int n, i; | ||
std::cout << "Enter the number of elements \n"; | ||
std::cin >> n; | ||
int a[n]; // NOLINT | ||
for (i = 0; i < n; i++) { | ||
std::cin >> a[i]; | ||
const int N = 5; | ||
std::array<int, N> n{}; // declaring array | ||
// taking values of elements from user | ||
for (int i = 0; i < n.size(); i++) { | ||
std::cout << "Enter value of n[" << i << "]" | ||
<< "\n"; | ||
std::cin >> n[i]; | ||
} | ||
int max_sum = maxSubArraySum(a, n); | ||
std::cout << "Maximum contiguous sum is " << max_sum; | ||
int max_sum = dynamic_programming::kadane::maxSubArray<N>( | ||
n); // calling maxSubArray function | ||
std::cout << "Maximum subarray sum is " << max_sum; // Printing the answer | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.