From 9c138a56819547a3a028d1eb05bd6b84c955d610 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:45:13 +0530 Subject: [PATCH 001/131] fix: add to subset_sum.cpp --- backtracking/subset_sum.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/backtracking/subset_sum.cpp b/backtracking/subset_sum.cpp index fad820920a5..bcc8ae744bd 100644 --- a/backtracking/subset_sum.cpp +++ b/backtracking/subset_sum.cpp @@ -10,6 +10,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector From 6629fd20592a97c5a459787205214ba74b965427 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:45:49 +0530 Subject: [PATCH 002/131] fix: add to subarray_sum.cpp --- backtracking/subarray_sum.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/backtracking/subarray_sum.cpp b/backtracking/subarray_sum.cpp index 8001d74cc0d..fde1fe98798 100644 --- a/backtracking/subarray_sum.cpp +++ b/backtracking/subarray_sum.cpp @@ -14,6 +14,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for unordered_map #include /// for std::vector From 392aed2f889cfbfc675ca90394da75cdc6da916e Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:46:21 +0530 Subject: [PATCH 003/131] fix: add to wildcard_matching.cpp --- backtracking/wildcard_matching.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/backtracking/wildcard_matching.cpp b/backtracking/wildcard_matching.cpp index d9163a41b48..b637f9f2d03 100644 --- a/backtracking/wildcard_matching.cpp +++ b/backtracking/wildcard_matching.cpp @@ -12,6 +12,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector From f71bd16b9e0b5af2c873f955ea0bbe93821d5e42 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:47:07 +0530 Subject: [PATCH 004/131] fix: add to count_bit_flips.cpp --- bit_manipulation/count_bits_flip.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bit_manipulation/count_bits_flip.cpp b/bit_manipulation/count_bits_flip.cpp index 5a6584b7241..61b2cd5c576 100644 --- a/bit_manipulation/count_bits_flip.cpp +++ b/bit_manipulation/count_bits_flip.cpp @@ -20,6 +20,7 @@ * @author [Yash Raj Singh](https://github.com/yashrajyash) */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations /** * @namespace bit_manipulation From 79104ec0bcecf89a8b365803e9dc1e1c58d9e97b Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:47:44 +0530 Subject: [PATCH 005/131] fix: add to count_of_set_bits.cpp --- bit_manipulation/count_of_set_bits.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bit_manipulation/count_of_set_bits.cpp b/bit_manipulation/count_of_set_bits.cpp index f2d802061cc..5e34c4df053 100644 --- a/bit_manipulation/count_of_set_bits.cpp +++ b/bit_manipulation/count_of_set_bits.cpp @@ -16,6 +16,7 @@ * @author [Prashant Thakur](https://github.com/prashant-th18) */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations /** * @namespace bit_manipulation From d5503817cdf0bd34393a11923042fc2770ee5c3d Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:48:35 +0530 Subject: [PATCH 006/131] fix: add to trailing_ciphers.cpp --- bit_manipulation/count_of_trailing_ciphers_in_factorial_n.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bit_manipulation/count_of_trailing_ciphers_in_factorial_n.cpp b/bit_manipulation/count_of_trailing_ciphers_in_factorial_n.cpp index aa2ceb3dd8a..493094de552 100644 --- a/bit_manipulation/count_of_trailing_ciphers_in_factorial_n.cpp +++ b/bit_manipulation/count_of_trailing_ciphers_in_factorial_n.cpp @@ -18,6 +18,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations /** From b66991f94ba3c301159243ef18925118ee2c321d Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:49:01 +0530 Subject: [PATCH 007/131] fix: add to hamming_distance.cpp --- bit_manipulation/hamming_distance.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bit_manipulation/hamming_distance.cpp b/bit_manipulation/hamming_distance.cpp index 62879cf4883..feb315410c5 100644 --- a/bit_manipulation/hamming_distance.cpp +++ b/bit_manipulation/hamming_distance.cpp @@ -12,7 +12,8 @@ * @author [Ravishankar Joshi](https://github.com/ravibitsgoa) */ -#include /// for assert +#include /// for assert +#include #include /// for io operations /** From 13f09a662f12a0d2776e82f54775b492c0b6bc27 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:49:55 +0530 Subject: [PATCH 008/131] doc: include doc for hamming_distance --- bit_manipulation/hamming_distance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bit_manipulation/hamming_distance.cpp b/bit_manipulation/hamming_distance.cpp index feb315410c5..1f6685ffca8 100644 --- a/bit_manipulation/hamming_distance.cpp +++ b/bit_manipulation/hamming_distance.cpp @@ -12,8 +12,8 @@ * @author [Ravishankar Joshi](https://github.com/ravibitsgoa) */ -#include /// for assert -#include +#include /// for assert +#include /// for integral typedefs #include /// for io operations /** From 6b986a9ac4db7b4fd3a0fccf9f2870d4d3ed9a6c Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:54:22 +0530 Subject: [PATCH 009/131] fix: add to next_higher_numebr_with_same_number_of_set_bits.cpp --- .../next_higher_number_with_same_number_of_set_bits.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp b/bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp index d93884d4e11..06f91c61943 100644 --- a/bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp +++ b/bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp @@ -16,6 +16,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations /** From 9639d766418a46187313286e42a8fa616e41c55a Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:56:53 +0530 Subject: [PATCH 010/131] fix: add to power_of_2.cpp --- bit_manipulation/power_of_2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bit_manipulation/power_of_2.cpp b/bit_manipulation/power_of_2.cpp index c62bfdaa3f5..14092e8952c 100644 --- a/bit_manipulation/power_of_2.cpp +++ b/bit_manipulation/power_of_2.cpp @@ -16,6 +16,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations /** From 8517a66d1e4d303858dcf6923add0b8b53aea332 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:07:44 +0530 Subject: [PATCH 011/131] fix: add to set_kth_bit.cpp --- bit_manipulation/set_kth_bit.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bit_manipulation/set_kth_bit.cpp b/bit_manipulation/set_kth_bit.cpp index a58e663b163..04e69c6a04b 100644 --- a/bit_manipulation/set_kth_bit.cpp +++ b/bit_manipulation/set_kth_bit.cpp @@ -19,6 +19,7 @@ */ #include /// for assert +#include /// for integral typdefs #include /// for IO operations /** From 49fbaf6285c2ac1c641fd07d7119dfefebdccdcb Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:09:00 +0530 Subject: [PATCH 012/131] fix: add to bit_manipulation/set_kth_bit.cpp --- bit_manipulation/travelling_salesman_using_bit_manipulation.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp b/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp index 31243ed2921..5eac30bc776 100644 --- a/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp +++ b/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp @@ -22,6 +22,7 @@ */ #include /// for std::min #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for limits of integral types #include /// for std::vector From 4b16caa985d7a6a94d5e50c4d0720ec4c402d908 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:10:34 +0530 Subject: [PATCH 013/131] fix: add to bit_manipulation/travelling_salesman_using_bit_manipulation.cpp --- ciphers/base64_encoding.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ciphers/base64_encoding.cpp b/ciphers/base64_encoding.cpp index a592226a5e7..52bce90ff9a 100644 --- a/ciphers/base64_encoding.cpp +++ b/ciphers/base64_encoding.cpp @@ -13,6 +13,7 @@ */ #include /// for `std::array` #include /// for `assert` operations +#include /// for integral typedefs #include /// for IO operations /** From 84c2957f09ce79597bf6ce7bd41642a00e6e38ff Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:11:07 +0530 Subject: [PATCH 014/131] fix: add to ciphers/base64_encoding.cpp --- ciphers/hill_cipher.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ciphers/hill_cipher.cpp b/ciphers/hill_cipher.cpp index 1fef0f32e2d..a57935bf610 100644 --- a/ciphers/hill_cipher.cpp +++ b/ciphers/hill_cipher.cpp @@ -35,6 +35,7 @@ #include #include +#include /// for integral typedefs #include #include #include From 89dfe607d0f14b8a897c88959607890374d17d27 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:12:01 +0530 Subject: [PATCH 015/131] fix: add to ciphers/hill_cipher.cpp --- ciphers/uint128_t.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ciphers/uint128_t.hpp b/ciphers/uint128_t.hpp index d50cb4ffb2d..141864c8d5f 100644 --- a/ciphers/uint128_t.hpp +++ b/ciphers/uint128_t.hpp @@ -8,6 +8,7 @@ */ #include /// for `std::reverse` and other operations +#include /// for integral typedefs #include /// for `std::cout` overload #include /// for `std::string` #include /// for `std::pair` library From 1a0b5cf7f162bdd2143ca940265cca98bd7b9746 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:12:39 +0530 Subject: [PATCH 016/131] fix: add to ciphers/uint128_t.hpp --- cpu_scheduling_algorithms/fcfs_scheduling.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cpu_scheduling_algorithms/fcfs_scheduling.cpp b/cpu_scheduling_algorithms/fcfs_scheduling.cpp index 4fc61af6bce..6eab989e4f2 100644 --- a/cpu_scheduling_algorithms/fcfs_scheduling.cpp +++ b/cpu_scheduling_algorithms/fcfs_scheduling.cpp @@ -11,6 +11,7 @@ #include /// for sorting #include /// for assert +#include /// for integral typedefs #include /// random number generation #include /// for time #include /// for formatting the output From 4792c814bf0600af692f061542661fe812bd2e17 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:13:53 +0530 Subject: [PATCH 017/131] fix: add to data_structures/dsu_path_compression.cpp --- data_structures/dsu_path_compression.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/data_structures/dsu_path_compression.cpp b/data_structures/dsu_path_compression.cpp index 022e632a784..9dff7b40bb0 100644 --- a/data_structures/dsu_path_compression.cpp +++ b/data_structures/dsu_path_compression.cpp @@ -19,6 +19,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector From 11d2437158eb33d3bb1948adefc834c87442e751 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:14:22 +0530 Subject: [PATCH 018/131] fix: add to data_structures/dsu_path_compression.cpp --- data_structures/dsu_union_rank.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/data_structures/dsu_union_rank.cpp b/data_structures/dsu_union_rank.cpp index 8936d6d6964..4ca53bb76f6 100644 --- a/data_structures/dsu_union_rank.cpp +++ b/data_structures/dsu_union_rank.cpp @@ -20,6 +20,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector From ef59b45129cb4f8f3df5af30fa4e5b27e4282a99 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:16:07 +0530 Subject: [PATCH 019/131] fix add to datastructures/list_array>cpp --- data_structures/list_array.cpp | 344 +++++++++++++++++---------------- 1 file changed, 178 insertions(+), 166 deletions(-) diff --git a/data_structures/list_array.cpp b/data_structures/list_array.cpp index 05c66ed84fa..8995b6ce2e1 100644 --- a/data_structures/list_array.cpp +++ b/data_structures/list_array.cpp @@ -4,17 +4,20 @@ * * @details * The list_array is the implementation of list represented using array. - * We can perform basic CRUD operations as well as other operations like sorting etc. + * We can perform basic CRUD operations as well as other operations like sorting + * etc. * * ### Algorithm * It implements various method like insert, sort, search etc. efficiently. * You can select the operation and methods will do the rest work for you. - * You can insert element, sort them in order, search efficiently, delete values and print the list. + * You can insert element, sort them in order, search efficiently, delete values + * and print the list. */ -#include /// for io operations -#include /// for std::array -#include /// for assert +#include /// for std::array +#include /// for assert +#include /// for integral typedefs +#include /// for io operations /** * @namespace data_structures @@ -23,181 +26,190 @@ namespace data_structures { /** * @namespace list_array - * @brief Functions for [Dynamic Array](https://en.wikipedia.org/wiki/Dynamic_array) algorithm + * @brief Functions for [Dynamic + * Array](https://en.wikipedia.org/wiki/Dynamic_array) algorithm */ namespace list_array { +/** + * @brief Structure of List with supporting methods. + */ +template +struct list { + std::array data{}; // Array that implement list + uint64_t top = 0; // Pointer to the last element + bool isSorted = false; // indicator whether list is sorted or not /** - * @brief Structure of List with supporting methods. + * @brief Search an element in the list using binarySearch. + * @param dataArr list + * @param first pointer to the first element in the remaining list + * @param last pointer to the last element in the remaining list + * @param val element that will be searched + * @return index of element in the list if present else -1 */ - template - struct list { - std::array data{}; // Array that implement list - uint64_t top = 0; // Pointer to the last element - bool isSorted = false; // indicator whether list is sorted or not - /** - * @brief Search an element in the list using binarySearch. - * @param dataArr list - * @param first pointer to the first element in the remaining list - * @param last pointer to the last element in the remaining list - * @param val element that will be searched - * @return index of element in the list if present else -1 - */ - uint64_t BinarySearch(const std::array &dataArr, const uint64_t &first, const uint64_t &last, - const uint64_t &val) { - // If both pointer cross each other means no element present in the list which is equal to the val - if (last < first) { - return -1; - } - uint64_t mid = (first + last) / 2; - // check whether current mid pointer value is equal to element or not - if (dataArr[mid] == val) - return mid; - // if current mid value is greater than element we have to search in first half - else if (val < dataArr[mid]) - return (BinarySearch(dataArr, first, mid - 1, val)); - // if current mid value is greater than element we have to search in second half - else if (val > dataArr[mid]) - return (BinarySearch(dataArr, mid + 1, last, val)); - - std::cerr << __func__ << ":" << __LINE__ << ": Undefined condition\n"; + uint64_t BinarySearch(const std::array &dataArr, + const uint64_t &first, const uint64_t &last, + const uint64_t &val) { + // If both pointer cross each other means no element present in the list + // which is equal to the val + if (last < first) { return -1; } + uint64_t mid = (first + last) / 2; + // check whether current mid pointer value is equal to element or not + if (dataArr[mid] == val) + return mid; + // if current mid value is greater than element we have to search in + // first half + else if (val < dataArr[mid]) + return (BinarySearch(dataArr, first, mid - 1, val)); + // if current mid value is greater than element we have to search in + // second half + else if (val > dataArr[mid]) + return (BinarySearch(dataArr, mid + 1, last, val)); - /** - * @brief Search an element using linear search - * @param dataArr list - * @param val element that will be searched - * @return index of element in the list if present else -1 - */ - uint64_t LinearSearch(const std::array &dataArr, const uint64_t &val) const { - // Going through each element in the list - for (uint64_t i = 0; i < top; i++) { - if (dataArr[i] == val) { - return i; // element found at ith index - } + std::cerr << __func__ << ":" << __LINE__ << ": Undefined condition\n"; + return -1; + } + + /** + * @brief Search an element using linear search + * @param dataArr list + * @param val element that will be searched + * @return index of element in the list if present else -1 + */ + uint64_t LinearSearch(const std::array &dataArr, + const uint64_t &val) const { + // Going through each element in the list + for (uint64_t i = 0; i < top; i++) { + if (dataArr[i] == val) { + return i; // element found at ith index } - // element is not present in the list - return -1; } + // element is not present in the list + return -1; + } - /* - * @brief Parent function of binarySearch and linearSearch methods - * @param val element that will be searched - * @return index of element in the list if present else -1 - */ - uint64_t search(const uint64_t &val) { - uint64_t pos; // pos variable to store index value of element. - // if list is sorted, binary search works efficiently else linear search is the only option - if (isSorted) { - pos = BinarySearch(data, 0, top - 1, val); - } else { - pos = LinearSearch(data, val); - } - // if index is equal to -1 means element does not present - // else print the index of that element - if (pos != -1) { - std::cout << "\nElement found at position : " << pos; - } else { - std::cout << "\nElement not found"; - } - // return the index of element or -1. - return pos; + /* + * @brief Parent function of binarySearch and linearSearch methods + * @param val element that will be searched + * @return index of element in the list if present else -1 + */ + uint64_t search(const uint64_t &val) { + uint64_t pos; // pos variable to store index value of element. + // if list is sorted, binary search works efficiently else linear search + // is the only option + if (isSorted) { + pos = BinarySearch(data, 0, top - 1, val); + } else { + pos = LinearSearch(data, val); + } + // if index is equal to -1 means element does not present + // else print the index of that element + if (pos != -1) { + std::cout << "\nElement found at position : " << pos; + } else { + std::cout << "\nElement not found"; } + // return the index of element or -1. + return pos; + } - /** - * @brief Sort the list - * @returns void - */ - void sort() { - //Going through each element in the list - for (uint64_t i = 0; i < top; i++) { - uint64_t min_idx = i; // Initialize the min variable - for (uint64_t j = i + 1; j < top; j++) { - // check whether any element less than current min value - if (data[j] < data[min_idx]) { - min_idx = j; // update index accordingly - } + /** + * @brief Sort the list + * @returns void + */ + void sort() { + // Going through each element in the list + for (uint64_t i = 0; i < top; i++) { + uint64_t min_idx = i; // Initialize the min variable + for (uint64_t j = i + 1; j < top; j++) { + // check whether any element less than current min value + if (data[j] < data[min_idx]) { + min_idx = j; // update index accordingly } - // swap min value and element at the ith index - std::swap(data[min_idx], data[i]); } - // mark isSorted variable as true - isSorted = true; + // swap min value and element at the ith index + std::swap(data[min_idx], data[i]); } + // mark isSorted variable as true + isSorted = true; + } - /** - * @brief Insert the new element in the list - * @param val element that will be inserted - * @returns void - */ - void insert(const uint64_t &val) { - // overflow check - if (top == N) { - std::cout << "\nOverflow"; - return; - } - // if list is not sorted, insert at the last - // otherwise place it to correct position - if (!isSorted) { - data[top] = val; - top++; - } else { - uint64_t pos = 0; // Initialize the index variable - // Going through each element and find correct position for element - for (uint64_t i = 0; i < top - 1; i++) { - // check for the correct position - if (data[i] <= val && val <= data[i + 1]) { - pos = i + 1; // assign correct pos to the index var - break; // to get out from the loop - } - } - // if all elements are smaller than the element - if (pos == 0) { - pos = top - 1; - } - // shift all element to make a room for new element - for (uint64_t i = top; i > pos; i--) { - data[i] = data[i - 1]; + /** + * @brief Insert the new element in the list + * @param val element that will be inserted + * @returns void + */ + void insert(const uint64_t &val) { + // overflow check + if (top == N) { + std::cout << "\nOverflow"; + return; + } + // if list is not sorted, insert at the last + // otherwise place it to correct position + if (!isSorted) { + data[top] = val; + top++; + } else { + uint64_t pos = 0; // Initialize the index variable + // Going through each element and find correct position for element + for (uint64_t i = 0; i < top - 1; i++) { + // check for the correct position + if (data[i] <= val && val <= data[i + 1]) { + pos = i + 1; // assign correct pos to the index var + break; // to get out from the loop } - top++; // Increment the value of top. - data[pos] = val; // Assign the value to the correct index in the array } - } - - /** - * @brief To remove the element from the list - * @param val element that will be removed - * @returns void - */ - void remove(const uint64_t &val) { - uint64_t pos = search(val); // search the index of the value - // if search returns -1, element does not present in the list - if (pos == -1) { - std::cout << "\n Element does not present in the list "; - return; + // if all elements are smaller than the element + if (pos == 0) { + pos = top - 1; } - std::cout << "\n" << data[pos] << " deleted"; // print the appropriate message - // shift all the element 1 left to fill vacant space - for (uint64_t i = pos; i < top; i++) { - data[i] = data[i + 1]; + // shift all element to make a room for new element + for (uint64_t i = top; i > pos; i--) { + data[i] = data[i - 1]; } - top--; // decrement the top variable to maintain last index + top++; // Increment the value of top. + data[pos] = + val; // Assign the value to the correct index in the array } + } - /** - * @brief Utility function to print array - * @returns void - */ - void show() { - // Going through each element in the list - std::cout << '\n'; - for (uint64_t i = 0; i < top; i++) { - std::cout << data[i] << " "; // print the element - } + /** + * @brief To remove the element from the list + * @param val element that will be removed + * @returns void + */ + void remove(const uint64_t &val) { + uint64_t pos = search(val); // search the index of the value + // if search returns -1, element does not present in the list + if (pos == -1) { + std::cout << "\n Element does not present in the list "; + return; + } + std::cout << "\n" + << data[pos] << " deleted"; // print the appropriate message + // shift all the element 1 left to fill vacant space + for (uint64_t i = pos; i < top; i++) { + data[i] = data[i + 1]; + } + top--; // decrement the top variable to maintain last index + } + + /** + * @brief Utility function to print array + * @returns void + */ + void show() { + // Going through each element in the list + std::cout << '\n'; + for (uint64_t i = 0; i < top; i++) { + std::cout << data[i] << " "; // print the element } - }; // structure list -} // namespace list_array -} // namespace data_structures + } +}; // structure list +} // namespace list_array +} // namespace data_structures /** * @brief Test implementations @@ -216,19 +228,19 @@ static void test() { L.insert(20); L.insert(18); assert(L.top == 7); - L.show(); // To print the array + L.show(); // To print the array // Remove testing - L.remove(12); // Remove Duplicate value in the list - L.remove(15); // Remove the existing value in the list + L.remove(12); // Remove Duplicate value in the list + L.remove(15); // Remove the existing value in the list assert(L.top == 5); - L.remove(50); // Try to remove the non-existing value in the list + L.remove(50); // Try to remove the non-existing value in the list assert(L.top == 5); // LinearSearch testing - assert(L.search(11) == 0); // search for the existing element + assert(L.search(11) == 0); // search for the existing element assert(L.search(12) == 2); - assert(L.search(50) == -1); // search for the non-existing element + assert(L.search(50) == -1); // search for the non-existing element // Sort testing L.sort(); @@ -236,9 +248,9 @@ static void test() { L.show(); // BinarySearch testing - assert(L.search(11) == 1); // search for the existing element + assert(L.search(11) == 1); // search for the existing element assert(L.search(12) == 2); - assert(L.search(50) == -1); // search for the non-existing element + assert(L.search(50) == -1); // search for the non-existing element } /** @@ -246,6 +258,6 @@ static void test() { * @returns 0 on exit */ int main() { - test(); // Execute the tests + test(); // Execute the tests return 0; } From b8e55922150fdc2acacf689004937a1d19876759 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:17:03 +0530 Subject: [PATCH 020/131] fix add to datastructures/queue_using_array.cpp --- data_structures/queue_using_array.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/data_structures/queue_using_array.cpp b/data_structures/queue_using_array.cpp index 8b9b387c5b8..cbd84a62397 100644 --- a/data_structures/queue_using_array.cpp +++ b/data_structures/queue_using_array.cpp @@ -18,6 +18,7 @@ * @author [Farbod Ahmadian](https://github.com/farbodahm) */ #include /// for std::array +#include /// for integral typedefs #include /// for io operations constexpr uint16_t max_size{10}; ///< Maximum size of the queue From 0d184428e1ce432c5ab2d2cbe00d0a2efefc45ae Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:17:36 +0530 Subject: [PATCH 021/131] fix: add to sparse_table.cpp --- data_structures/sparse_table.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/data_structures/sparse_table.cpp b/data_structures/sparse_table.cpp index b99616ae6b0..507dd39449d 100644 --- a/data_structures/sparse_table.cpp +++ b/data_structures/sparse_table.cpp @@ -24,6 +24,7 @@ #include /// for std::array #include /// for assert +#include /// for integral typedefs #include /// for IO operations /** From 82cb276f44249b4a71915a94cd8ba1cc5006a6da Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:17:50 +0530 Subject: [PATCH 022/131] fix: add to stack_using_list_queue.cpp --- data_structures/stack_using_queue.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/data_structures/stack_using_queue.cpp b/data_structures/stack_using_queue.cpp index b849fcf053a..7867d55caa0 100644 --- a/data_structures/stack_using_queue.cpp +++ b/data_structures/stack_using_queue.cpp @@ -9,6 +9,7 @@ * @author [tushar2407](https://github.com/tushar2407) */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for queue data structure From 5421cfcdeb8d0e7b71611b511509f1dc1a2b70f5 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:18:06 +0530 Subject: [PATCH 023/131] fix: add to treap.cpp --- data_structures/treap.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/data_structures/treap.cpp b/data_structures/treap.cpp index 522876941b1..5be3b241643 100644 --- a/data_structures/treap.cpp +++ b/data_structures/treap.cpp @@ -19,6 +19,7 @@ #include /// For array #include /// For assert +#include /// for integral typedefs #include /// For IO operations /** @@ -157,11 +158,9 @@ struct Treap { } if (k == key[x]) { return size[childs[x][0]] + 1; - } - else if (k < key[x]) { + } else if (k < key[x]) { return _get_rank(childs[x][0], k); - } - else { + } else { return size[childs[x][0]] + cnt[x] + _get_rank(childs[x][1], k); } } From b752f55fa19dbde1a40f07dd139cc112f6f6bfb1 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:18:32 +0530 Subject: [PATCH 024/131] fix: add to graham_scan_functions.hpp --- geometry/graham_scan_functions.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/geometry/graham_scan_functions.hpp b/geometry/graham_scan_functions.hpp index f6e05095e74..58002db266d 100644 --- a/geometry/graham_scan_functions.hpp +++ b/geometry/graham_scan_functions.hpp @@ -39,6 +39,7 @@ * *******************************************************************************/ #include /// for std::swap +#include /// for integral typedefs #include /// for mathematics and datatype conversion #include /// for IO operations #include /// for std::stack From 549aad5ce68c6b7f15613eb90f98f1dd31673a0f Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:26:48 +0530 Subject: [PATCH 025/131] fix: add to graph/** --- graph/bidirectional_dijkstra.cpp | 1 + graph/connected_components_with_dsu.cpp | 19 ++++++++++++------- graph/cycle_check_directed_graph.cpp | 1 + graph/is_graph_bipartite2.cpp | 1 + graph/travelling_salesman_problem.cpp | 1 + 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/graph/bidirectional_dijkstra.cpp b/graph/bidirectional_dijkstra.cpp index deef6622758..5f6d369287c 100644 --- a/graph/bidirectional_dijkstra.cpp +++ b/graph/bidirectional_dijkstra.cpp @@ -14,6 +14,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for io operations #include /// for variable INF #include /// for the priority_queue of distances diff --git a/graph/connected_components_with_dsu.cpp b/graph/connected_components_with_dsu.cpp index c0194e85163..72c4f34fe2b 100644 --- a/graph/connected_components_with_dsu.cpp +++ b/graph/connected_components_with_dsu.cpp @@ -3,20 +3,24 @@ * @brief [Disjoint union](https://en.wikipedia.org/wiki/Disjoint_union) * * @details - * The Disjoint union is the technique to find connected component in graph efficiently. + * The Disjoint union is the technique to find connected component in graph + * efficiently. * * ### Algorithm - * In Graph, if you have to find out the number of connected components, there are 2 options + * In Graph, if you have to find out the number of connected components, there + * are 2 options * 1. Depth first search * 2. Disjoint union - * 1st option is inefficient, Disjoint union is the most optimal way to find this. + * 1st option is inefficient, Disjoint union is the most optimal way to find + * this. * * @author Unknown author * @author [Sagar Pandya](https://github.com/sagarpandyansit) */ -#include /// for IO operations -#include /// for std::set -#include /// for std::vector +#include /// for integer typedefs +#include /// for IO operations +#include /// for std::set +#include /// for std::vector /** * @namespace graph @@ -25,7 +29,8 @@ namespace graph { /** * @namespace disjoint_union - * @brief Functions for [Disjoint union](https://en.wikipedia.org/wiki/Disjoint_union) implementation + * @brief Functions for [Disjoint + * union](https://en.wikipedia.org/wiki/Disjoint_union) implementation */ namespace disjoint_union { uint32_t number_of_nodes = 0; // denotes number of nodes diff --git a/graph/cycle_check_directed_graph.cpp b/graph/cycle_check_directed_graph.cpp index 8a651cfc5f6..fbe6063ca96 100644 --- a/graph/cycle_check_directed_graph.cpp +++ b/graph/cycle_check_directed_graph.cpp @@ -7,6 +7,7 @@ * */ +#include /// for integral typedefs #include // for std::cout #include // for std::map #include // for std::queue diff --git a/graph/is_graph_bipartite2.cpp b/graph/is_graph_bipartite2.cpp index f1b04d0707b..d55f2c84b53 100644 --- a/graph/is_graph_bipartite2.cpp +++ b/graph/is_graph_bipartite2.cpp @@ -15,6 +15,7 @@ * @author [tushar2407](https://github.com/tushar2407) */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for queue data structure #include /// for vector data structure diff --git a/graph/travelling_salesman_problem.cpp b/graph/travelling_salesman_problem.cpp index 28df3e93155..8b46080093f 100644 --- a/graph/travelling_salesman_problem.cpp +++ b/graph/travelling_salesman_problem.cpp @@ -19,6 +19,7 @@ #include /// for std::min #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for limits of integral types #include /// for std::vector From 2ec9d7fe4997a12402b241f07b782bff78836679 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:27:08 +0530 Subject: [PATCH 026/131] fix: add integral typdefs to hashing/** --- hashing/md5.cpp | 1 + hashing/sha1.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/hashing/md5.cpp b/hashing/md5.cpp index aad75731007..2a0f289f3c4 100644 --- a/hashing/md5.cpp +++ b/hashing/md5.cpp @@ -41,6 +41,7 @@ #include /// Used for std::copy #include /// Used for std::array #include /// Used for assert +#include /// for integral typedefs #include /// Used for std::memcopy #include /// Used for IO operations #include /// Used for strings diff --git a/hashing/sha1.cpp b/hashing/sha1.cpp index 106da827296..5b55e58c6ba 100644 --- a/hashing/sha1.cpp +++ b/hashing/sha1.cpp @@ -32,6 +32,7 @@ #include /// For std::copy #include /// For std::array #include /// For assert +#include /// for integral typedefs #include /// For std::memcopy #include /// For IO operations #include /// For strings From afd4ccbc5e138beb2156a16ccd824d352bed0020 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:29:17 +0530 Subject: [PATCH 027/131] fix: add to math/** --- math/aliquot_sum.cpp | 1 + math/check_factorial.cpp | 1 + math/double_factorial.cpp | 1 + math/eulers_totient_function.cpp | 14 +- math/factorial.cpp | 2 +- math/fibonacci.cpp | 4 +- math/fibonacci_matrix_exponentiation.cpp | 163 +++++++++--------- math/fibonacci_sum.cpp | 1 + math/finding_number_of_digits_in_a_number.cpp | 1 + math/integral_approximation.cpp | 35 ++-- math/inv_sqrt.cpp | 2 +- math/largest_power.cpp | 105 ++++++----- math/lcm_sum.cpp | 1 + math/linear_recurrence_matrix.cpp | 1 + math/magic_number.cpp | 1 + math/modular_division.cpp | 1 + math/modular_exponentiation.cpp | 2 +- math/modular_inverse_simple.cpp | 1 + math/n_bonacci.cpp | 2 +- math/n_choose_r.cpp | 2 +- math/sieve_of_eratosthenes.cpp | 15 +- math/string_fibonacci.cpp | 1 + math/sum_of_binomial_coefficient.cpp | 1 + 23 files changed, 196 insertions(+), 162 deletions(-) diff --git a/math/aliquot_sum.cpp b/math/aliquot_sum.cpp index 6d94d53a1be..837be6b2f00 100644 --- a/math/aliquot_sum.cpp +++ b/math/aliquot_sum.cpp @@ -20,6 +20,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations /** diff --git a/math/check_factorial.cpp b/math/check_factorial.cpp index 0be45b89509..05898fbcde8 100644 --- a/math/check_factorial.cpp +++ b/math/check_factorial.cpp @@ -10,6 +10,7 @@ * @author [ewd00010](https://github.com/ewd00010) */ #include /// for assert +#include /// for integral typedefs #include /// for cout /** diff --git a/math/double_factorial.cpp b/math/double_factorial.cpp index 72feda60c4e..878f87ec446 100644 --- a/math/double_factorial.cpp +++ b/math/double_factorial.cpp @@ -10,6 +10,7 @@ */ #include +#include /// for integral typedefs #include /** Compute double factorial using iterative method diff --git a/math/eulers_totient_function.cpp b/math/eulers_totient_function.cpp index f1752e9e92a..da03a2531c6 100644 --- a/math/eulers_totient_function.cpp +++ b/math/eulers_totient_function.cpp @@ -1,6 +1,7 @@ /** * @file - * @brief Implementation of [Euler's Totient](https://en.wikipedia.org/wiki/Euler%27s_totient_function) + * @brief Implementation of [Euler's + * Totient](https://en.wikipedia.org/wiki/Euler%27s_totient_function) * @description * Euler Totient Function is also known as phi function. * \f[\phi(n) = @@ -24,8 +25,9 @@ * @author [Mann Mehta](https://github.com/mann2108) */ -#include /// for IO operations -#include /// for assert +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations /** * @brief Mathematical algorithms @@ -39,12 +41,14 @@ namespace math { uint64_t phiFunction(uint64_t n) { uint64_t result = n; for (uint64_t i = 2; i * i <= n; i++) { - if (n % i != 0) continue; + if (n % i != 0) + continue; while (n % i == 0) n /= i; result -= result / i; } - if (n > 1) result -= result / n; + if (n > 1) + result -= result / n; return result; } diff --git a/math/factorial.cpp b/math/factorial.cpp index acfa053d89a..a6b039da45b 100644 --- a/math/factorial.cpp +++ b/math/factorial.cpp @@ -12,8 +12,8 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for I/O operations - /** * @namespace * @brief Mathematical algorithms diff --git a/math/fibonacci.cpp b/math/fibonacci.cpp index 4e3c15de86e..1cd50e7cef3 100644 --- a/math/fibonacci.cpp +++ b/math/fibonacci.cpp @@ -9,8 +9,8 @@ * @see fibonacci_large.cpp, fibonacci_fast.cpp, string_fibonacci.cpp */ #include +#include /// for integral typedefs #include - /** * Recursively compute sequences * @param n input @@ -31,7 +31,7 @@ uint64_t fibonacci(uint64_t n) { * Function for testing the fibonacci() function with a few * test cases and assert statement. * @returns `void` -*/ + */ static void test() { uint64_t test_case_1 = fibonacci(0); assert(test_case_1 == 0); diff --git a/math/fibonacci_matrix_exponentiation.cpp b/math/fibonacci_matrix_exponentiation.cpp index 1a119d210aa..3dd4c721337 100644 --- a/math/fibonacci_matrix_exponentiation.cpp +++ b/math/fibonacci_matrix_exponentiation.cpp @@ -1,101 +1,103 @@ /** - * @file + * @file * @brief This program computes the N^th Fibonacci number in modulo mod * input argument . * * Takes O(logn) time to compute nth Fibonacci number - * + * * * \author [villayatali123](https://github.com/villayatali123) * \author [unknown author]() - * @see fibonacci.cpp, fibonacci_fast.cpp, string_fibonacci.cpp, fibonacci_large.cpp + * @see fibonacci.cpp, fibonacci_fast.cpp, string_fibonacci.cpp, + * fibonacci_large.cpp */ -#include -#include #include +#include /// for integral typedefs +#include +#include /** * This function finds nth fibonacci number in a given modulus * @param n nth fibonacci number - * @param mod modulo number + * @param mod modulo number */ -uint64_t fibo(uint64_t n , uint64_t mod ) -{ - std::vector result(2,0); - std::vector> transition(2,std::vector(2,0)); - std::vector> Identity(2,std::vector(2,0)); - n--; - result[0]=1, result[1]=1; - Identity[0][0]=1; Identity[0][1]=0; - Identity[1][0]=0; Identity[1][1]=1; - - transition[0][0]=0; - transition[1][0]=transition[1][1]=transition[0][1]=1; - - while(n) - { - if(n%2) - { - std::vector> res(2, std::vector(2,0)); - for(int i=0;i<2;i++) - { - for(int j=0;j<2;j++) - { - for(int k=0;k<2;k++) - { - res[i][j]=(res[i][j]%mod+((Identity[i][k]%mod*transition[k][j]%mod))%mod)%mod; - } - } - } - for(int i=0;i<2;i++) - { - for(int j=0;j<2;j++) - { - Identity[i][j]=res[i][j]; - } - } - n--; - } - else{ - std::vector> res1(2, std::vector(2,0)); - for(int i=0;i<2;i++) - { - for(int j=0;j<2;j++) - { - for(int k=0;k<2;k++) - { - res1[i][j]=(res1[i][j]%mod+((transition[i][k]%mod*transition[k][j]%mod))%mod)%mod; - } - } - } - for(int i=0;i<2;i++) - { - for(int j=0;j<2;j++) - { - transition[i][j]=res1[i][j]; - } - } - n=n/2; - } - } - return ((result[0]%mod*Identity[0][0]%mod)%mod+(result[1]%mod*Identity[1][0]%mod)%mod)%mod; +uint64_t fibo(uint64_t n, uint64_t mod) { + std::vector result(2, 0); + std::vector> transition(2, + std::vector(2, 0)); + std::vector> Identity(2, std::vector(2, 0)); + n--; + result[0] = 1, result[1] = 1; + Identity[0][0] = 1; + Identity[0][1] = 0; + Identity[1][0] = 0; + Identity[1][1] = 1; + + transition[0][0] = 0; + transition[1][0] = transition[1][1] = transition[0][1] = 1; + + while (n) { + if (n % 2) { + std::vector> res(2, + std::vector(2, 0)); + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + for (int k = 0; k < 2; k++) { + res[i][j] = + (res[i][j] % mod + + ((Identity[i][k] % mod * transition[k][j] % mod)) % + mod) % + mod; + } + } + } + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + Identity[i][j] = res[i][j]; + } + } + n--; + } else { + std::vector> res1( + 2, std::vector(2, 0)); + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + for (int k = 0; k < 2; k++) { + res1[i][j] = + (res1[i][j] % mod + ((transition[i][k] % mod * + transition[k][j] % mod)) % + mod) % + mod; + } + } + } + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + transition[i][j] = res1[i][j]; + } + } + n = n / 2; + } + } + return ((result[0] % mod * Identity[0][0] % mod) % mod + + (result[1] % mod * Identity[1][0] % mod) % mod) % + mod; } /** * Function to test above algorithm */ -void test() -{ - assert(fibo(6, 1000000007 ) == 8); +void test() { + assert(fibo(6, 1000000007) == 8); std::cout << "test case:1 passed\n"; - assert(fibo(5, 1000000007 ) == 5); + assert(fibo(5, 1000000007) == 5); std::cout << "test case:2 passed\n"; - assert(fibo(10 , 1000000007) == 55); + assert(fibo(10, 1000000007) == 55); std::cout << "test case:3 passed\n"; - assert(fibo(500 , 100) == 25); + assert(fibo(500, 100) == 25); std::cout << "test case:3 passed\n"; - assert(fibo(500 , 10000) == 4125); + assert(fibo(500, 10000) == 4125); std::cout << "test case:3 passed\n"; std::cout << "--All tests passed--\n"; } @@ -103,11 +105,12 @@ void test() /** * Main function */ -int main() -{ - test(); - uint64_t mod=1000000007; - std::cout<<"Enter the value of N: "; - uint64_t n=0; std::cin>>n; - std::cout<> n; + std::cout << n << "th Fibonacci number in modulo " << mod << ": " + << fibo(n, mod) << std::endl; } diff --git a/math/fibonacci_sum.cpp b/math/fibonacci_sum.cpp index 5107578888e..4c52951deca 100644 --- a/math/fibonacci_sum.cpp +++ b/math/fibonacci_sum.cpp @@ -13,6 +13,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for std::cin and std::cout #include /// for std::vector diff --git a/math/finding_number_of_digits_in_a_number.cpp b/math/finding_number_of_digits_in_a_number.cpp index 32ddd649ec3..e94a6c21728 100644 --- a/math/finding_number_of_digits_in_a_number.cpp +++ b/math/finding_number_of_digits_in_a_number.cpp @@ -18,6 +18,7 @@ #include /// for assert #include /// for log calculation +#include /// for integral typedefs #include /// for IO operations /** diff --git a/math/integral_approximation.cpp b/math/integral_approximation.cpp index 7e72ef4042b..033742f633b 100644 --- a/math/integral_approximation.cpp +++ b/math/integral_approximation.cpp @@ -1,18 +1,29 @@ /** * @file - * @brief Compute integral approximation of the function using [Riemann sum](https://en.wikipedia.org/wiki/Riemann_sum) - * @details In mathematics, a Riemann sum is a certain kind of approximation of an integral by a finite sum. It is named after nineteenth-century German mathematician Bernhard Riemann. - * One very common application is approximating the area of functions or lines on a graph and the length of curves and other approximations. - * The sum is calculated by partitioning the region into shapes (rectangles, trapezoids, parabolas, or cubics) that form a region similar to the region being measured, then calculating the area for each of these shapes, and finally adding all of these small areas together. - * This approach can be used to find a numerical approximation for a definite integral even if the fundamental theorem of calculus does not make it easy to find a closed-form solution. - * Because the region filled by the small shapes is usually not the same shape as the region being measured, the Riemann sum will differ from the area being measured. - * This error can be reduced by dividing up the region more finely, using smaller and smaller shapes. As the shapes get smaller and smaller, the sum approaches the Riemann integral. - * \author [Benjamin Walton](https://github.com/bwalton24) - * \author [Shiqi Sheng](https://github.com/shiqisheng00) + * @brief Compute integral approximation of the function using [Riemann + * sum](https://en.wikipedia.org/wiki/Riemann_sum) + * @details In mathematics, a Riemann sum is a certain kind of approximation of + * an integral by a finite sum. It is named after nineteenth-century German + * mathematician Bernhard Riemann. One very common application is approximating + * the area of functions or lines on a graph and the length of curves and other + * approximations. The sum is calculated by partitioning the region into shapes + * (rectangles, trapezoids, parabolas, or cubics) that form a region similar to + * the region being measured, then calculating the area for each of these + * shapes, and finally adding all of these small areas together. This approach + * can be used to find a numerical approximation for a definite integral even if + * the fundamental theorem of calculus does not make it easy to find a + * closed-form solution. Because the region filled by the small shapes is + * usually not the same shape as the region being measured, the Riemann sum will + * differ from the area being measured. This error can be reduced by dividing up + * the region more finely, using smaller and smaller shapes. As the shapes get + * smaller and smaller, the sum approaches the Riemann integral. \author + * [Benjamin Walton](https://github.com/bwalton24) \author [Shiqi + * Sheng](https://github.com/shiqisheng00) */ -#include /// for assert -#include /// for mathematical functions -#include /// for passing in functions +#include /// for assert +#include /// for mathematical functions +#include /// for integral typedefs +#include /// for passing in functions #include /// for IO operations /** diff --git a/math/inv_sqrt.cpp b/math/inv_sqrt.cpp index ef490ddf918..1f625e1cf8a 100644 --- a/math/inv_sqrt.cpp +++ b/math/inv_sqrt.cpp @@ -10,9 +10,9 @@ #include /// for assert #include /// for `std::sqrt` +#include /// for integral typedefs #include /// for IO operations #include /// for numeric_limits - /** * @brief This is the function that calculates the fast inverse square root. * The following code is the fast inverse square root implementation from diff --git a/math/largest_power.cpp b/math/largest_power.cpp index 8fffbbd078b..22f6da7380d 100644 --- a/math/largest_power.cpp +++ b/math/largest_power.cpp @@ -1,41 +1,42 @@ /** * @file - * @brief Algorithm to find largest x such that p^x divides n! (factorial) using Legendre's Formula. - * @details Given an integer n and a prime number p, the task is to find the largest x such that - * p^x (p raised to power x) divides n! (factorial). This will be done using Legendre's formula: - * x = [n/(p^1)] + [n/(p^2)] + [n/(p^3)] + \ldots + 1 - * @see more on https://math.stackexchange.com/questions/141196/highest-power-of-a-prime-p-dividing-n + * @brief Algorithm to find largest x such that p^x divides n! (factorial) using + * Legendre's Formula. + * @details Given an integer n and a prime number p, the task is to find the + * largest x such that p^x (p raised to power x) divides n! (factorial). This + * will be done using Legendre's formula: x = [n/(p^1)] + [n/(p^2)] + [n/(p^3)] + * + \ldots + 1 + * @see more on + * https://math.stackexchange.com/questions/141196/highest-power-of-a-prime-p-dividing-n * @author [uday6670](https://github.com/uday6670) */ -#include /// for std::cin and std::cout -#include /// for assert - +#include /// for assert +#include /// for integral typedefs +#include /// for std::cin and std::cout /** * @namespace math * @brief Mathematical algorithms */ namespace math { - /** - * @brief Function to calculate largest power - * @param n number - * @param p prime number - * @returns largest power - */ - uint64_t largestPower(uint32_t n, const uint16_t& p) - { - // Initialize result - int x = 0; - - // Calculate result - while (n) - { - n /= p; - x += n; - } - return x; +/** + * @brief Function to calculate largest power + * @param n number + * @param p prime number + * @returns largest power + */ +uint64_t largestPower(uint32_t n, const uint16_t& p) { + // Initialize result + int x = 0; + + // Calculate result + while (n) { + n /= p; + x += n; } + return x; +} } // namespace math @@ -43,36 +44,34 @@ namespace math { * @brief Function for testing largestPower function. * test cases and assert statement. * @returns `void` -*/ -static void test() -{ - uint8_t test_case_1 = math::largestPower(5,2); - assert(test_case_1==3); - std::cout<<"Test 1 Passed!"< /// for assert +#include /// for integral typedefs #include /// for std::cin and std::cout #include /// for std::vector diff --git a/math/linear_recurrence_matrix.cpp b/math/linear_recurrence_matrix.cpp index 98c90e5f8fa..d59ad6aa1c0 100644 --- a/math/linear_recurrence_matrix.cpp +++ b/math/linear_recurrence_matrix.cpp @@ -18,6 +18,7 @@ * @author [Ashish Daulatabad](https://github.com/AshishYUO) */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector STL diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 51232601b2b..7ba3ab0bcd1 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -17,6 +17,7 @@ * @author [Neha Hasija](https://github.com/neha-hasija17) */ #include /// for assert +#include /// for integral typedefs #include /// for io operations /** diff --git a/math/modular_division.cpp b/math/modular_division.cpp index 6fd984f2bf0..8208222f060 100644 --- a/math/modular_division.cpp +++ b/math/modular_division.cpp @@ -25,6 +25,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations /** diff --git a/math/modular_exponentiation.cpp b/math/modular_exponentiation.cpp index 01410860fda..a022939330a 100644 --- a/math/modular_exponentiation.cpp +++ b/math/modular_exponentiation.cpp @@ -17,8 +17,8 @@ * @author [Shri2206](https://github.com/Shri2206) */ #include /// for assert +#include /// for integral typedefs #include /// for io operations - /** * @namespace math * @brief Mathematical algorithms diff --git a/math/modular_inverse_simple.cpp b/math/modular_inverse_simple.cpp index 813f0e0b4a5..b2c79fe9a9b 100644 --- a/math/modular_inverse_simple.cpp +++ b/math/modular_inverse_simple.cpp @@ -8,6 +8,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations /** diff --git a/math/n_bonacci.cpp b/math/n_bonacci.cpp index c34dab7a19d..601b2edf0d7 100644 --- a/math/n_bonacci.cpp +++ b/math/n_bonacci.cpp @@ -16,9 +16,9 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for std::cout #include /// for std::vector - /** * @namespace math * @brief Mathematical algorithms diff --git a/math/n_choose_r.cpp b/math/n_choose_r.cpp index 8bb3bbcdc2d..d2aabc28a55 100644 --- a/math/n_choose_r.cpp +++ b/math/n_choose_r.cpp @@ -11,8 +11,8 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for io operations - /** * @namespace math * @brief Mathematical algorithms diff --git a/math/sieve_of_eratosthenes.cpp b/math/sieve_of_eratosthenes.cpp index e011b6c0018..7b77b347455 100644 --- a/math/sieve_of_eratosthenes.cpp +++ b/math/sieve_of_eratosthenes.cpp @@ -12,6 +12,7 @@ */ #include +#include /// for integral typedefs #include #include @@ -21,7 +22,8 @@ * a prime p starting from p * p since all of the lower multiples * have been already eliminated. * @param N number of primes to check - * @return is_prime a vector of `N + 1` booleans identifying if `i`^th number is a prime or not + * @return is_prime a vector of `N + 1` booleans identifying if `i`^th number is + * a prime or not */ std::vector sieve(uint32_t N) { std::vector is_prime(N + 1, true); @@ -39,7 +41,8 @@ std::vector sieve(uint32_t N) { /** * This function prints out the primes to STDOUT * @param N number of primes to check - * @param is_prime a vector of `N + 1` booleans identifying if `i`^th number is a prime or not + * @param is_prime a vector of `N + 1` booleans identifying if `i`^th number is + * a prime or not */ void print(uint32_t N, const std::vector &is_prime) { for (uint32_t i = 2; i <= N; i++) { @@ -54,9 +57,11 @@ void print(uint32_t N, const std::vector &is_prime) { * Test implementations */ void tests() { - // 0 1 2 3 4 5 6 7 8 9 10 - std::vector ans{false, false, true, true, false, true, false, true, false, false, false}; - assert(sieve(10) == ans); + // 0 1 2 3 4 5 6 7 8 + // 9 10 + std::vector ans{false, false, true, true, false, true, + false, true, false, false, false}; + assert(sieve(10) == ans); } /** diff --git a/math/string_fibonacci.cpp b/math/string_fibonacci.cpp index eb9b6d7e1a7..a7ff4c8bbad 100644 --- a/math/string_fibonacci.cpp +++ b/math/string_fibonacci.cpp @@ -8,6 +8,7 @@ * @see fibonacci_large.cpp, fibonacci_fast.cpp, fibonacci.cpp */ +#include /// for integral typedefs #include #ifdef _MSC_VER #include // use this for MS Visual C diff --git a/math/sum_of_binomial_coefficient.cpp b/math/sum_of_binomial_coefficient.cpp index 1942df527dd..38e02be21c7 100644 --- a/math/sum_of_binomial_coefficient.cpp +++ b/math/sum_of_binomial_coefficient.cpp @@ -10,6 +10,7 @@ * @author [muskan0719](https://github.com/muskan0719) */ #include /// for assert +#include /// for integral typedefs #include /// for std::cin and std::cout /** From 8740df031407ecb8b10351bad7ac193fc866535e Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:29:46 +0530 Subject: [PATCH 028/131] fix: add to numerical_methods/** --- numerical_methods/brent_method_extrema.cpp | 1 + numerical_methods/durand_kerner_roots.cpp | 1 + numerical_methods/fast_fourier_transform.cpp | 1 + numerical_methods/golden_search_extrema.cpp | 1 + numerical_methods/inverse_fast_fourier_transform.cpp | 1 + numerical_methods/newton_raphson_method.cpp | 1 + numerical_methods/rungekutta.cpp | 2 +- 7 files changed, 7 insertions(+), 1 deletion(-) diff --git a/numerical_methods/brent_method_extrema.cpp b/numerical_methods/brent_method_extrema.cpp index 654a694514a..bd4d2796d29 100644 --- a/numerical_methods/brent_method_extrema.cpp +++ b/numerical_methods/brent_method_extrema.cpp @@ -16,6 +16,7 @@ #define _USE_MATH_DEFINES ///< required for MS Visual C++ #include #include +#include /// for integral typedefs #include #include #include diff --git a/numerical_methods/durand_kerner_roots.cpp b/numerical_methods/durand_kerner_roots.cpp index 9bf0619b829..d8665a68aa4 100644 --- a/numerical_methods/durand_kerner_roots.cpp +++ b/numerical_methods/durand_kerner_roots.cpp @@ -33,6 +33,7 @@ #include #include #include +#include /// for integral typedefs #include #include #include diff --git a/numerical_methods/fast_fourier_transform.cpp b/numerical_methods/fast_fourier_transform.cpp index 23a6c8a1f54..23b52622b61 100644 --- a/numerical_methods/fast_fourier_transform.cpp +++ b/numerical_methods/fast_fourier_transform.cpp @@ -22,6 +22,7 @@ #include /// for assert #include /// for mathematical-related functions #include /// for storing points and coefficents +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector diff --git a/numerical_methods/golden_search_extrema.cpp b/numerical_methods/golden_search_extrema.cpp index 1ca47949fee..2d9dd507013 100644 --- a/numerical_methods/golden_search_extrema.cpp +++ b/numerical_methods/golden_search_extrema.cpp @@ -10,6 +10,7 @@ #define _USE_MATH_DEFINES //< required for MS Visual C++ #include #include +#include /// for integral typedefs #include #include #include diff --git a/numerical_methods/inverse_fast_fourier_transform.cpp b/numerical_methods/inverse_fast_fourier_transform.cpp index 3837c21f966..793588cb675 100644 --- a/numerical_methods/inverse_fast_fourier_transform.cpp +++ b/numerical_methods/inverse_fast_fourier_transform.cpp @@ -14,6 +14,7 @@ #include /// for assert #include /// for mathematical-related functions #include /// for storing points and coefficents +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector diff --git a/numerical_methods/newton_raphson_method.cpp b/numerical_methods/newton_raphson_method.cpp index 17147e0bedd..ce75088a39a 100644 --- a/numerical_methods/newton_raphson_method.cpp +++ b/numerical_methods/newton_raphson_method.cpp @@ -13,6 +13,7 @@ * \see bisection_method.cpp, false_position.cpp */ #include +#include /// for integral typedefs #include #include #include diff --git a/numerical_methods/rungekutta.cpp b/numerical_methods/rungekutta.cpp index 01ca3a0745a..2f446d4456a 100644 --- a/numerical_methods/rungekutta.cpp +++ b/numerical_methods/rungekutta.cpp @@ -19,9 +19,9 @@ * There can be many such equations */ #include /// asserting the test functions +#include /// for integral typedefs #include /// for io operations #include /// for using the vector container - /** * @brief The change() function is used * to return the updated iterative value corresponding From 63575484648207986a098ba4a0181a15cc0ba02c Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:30:00 +0530 Subject: [PATCH 029/131] fix: add to other/** --- others/easter.cpp | 1 + others/kadanes3.cpp | 2 +- others/lru_cache.cpp | 1 + others/recursive_tree_traversal.cpp | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/others/easter.cpp b/others/easter.cpp index 36ac48028fc..44b10335300 100644 --- a/others/easter.cpp +++ b/others/easter.cpp @@ -18,6 +18,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations /* diff --git a/others/kadanes3.cpp b/others/kadanes3.cpp index 9cc6604e9c5..22c1119c858 100644 --- a/others/kadanes3.cpp +++ b/others/kadanes3.cpp @@ -17,8 +17,8 @@ #include /// for std::array #include /// for assert #include /// for INT_MIN value +#include /// for integral typedefs #include /// for IO operations - /** * @brief Utility function to check the current maximum number * \param arr input array diff --git a/others/lru_cache.cpp b/others/lru_cache.cpp index f9cd3caec7d..5a07c3e4fa9 100644 --- a/others/lru_cache.cpp +++ b/others/lru_cache.cpp @@ -46,6 +46,7 @@ * */ #include /// for assert +#include /// for integral typedefs #include /// for IO Operations #include /// for std::list #include /// for std::unordered_map diff --git a/others/recursive_tree_traversal.cpp b/others/recursive_tree_traversal.cpp index ef2720101f4..6595d5ff524 100644 --- a/others/recursive_tree_traversal.cpp +++ b/others/recursive_tree_traversal.cpp @@ -52,6 +52,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for I/O operations #include /// for vector From 52ff5e8c9215705acedb21c181b3baaf14d6aaf2 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:30:18 +0530 Subject: [PATCH 030/131] fix: add to search/** --- search/binary_search.cpp | 1 + search/exponential_search.cpp | 3 +- search/floyd_cycle_detection_algo.cpp | 2 +- search/interpolation_search.cpp | 1 + search/saddleback_search.cpp | 51 ++++++++++++++++----------- search/sublist_search.cpp | 1 + 6 files changed, 36 insertions(+), 23 deletions(-) diff --git a/search/binary_search.cpp b/search/binary_search.cpp index 5e455dd17e3..20c8b1ab141 100644 --- a/search/binary_search.cpp +++ b/search/binary_search.cpp @@ -36,6 +36,7 @@ #include /// for std::sort function #include /// for std::assert +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector /****************************************************************************** diff --git a/search/exponential_search.cpp b/search/exponential_search.cpp index f57cbf96b51..c8370580af3 100644 --- a/search/exponential_search.cpp +++ b/search/exponential_search.cpp @@ -14,7 +14,8 @@ */ #include #include -#include +#include +#include /// for integral typedefs #ifdef _MSC_VER #include // use for MS Visual C++ #else diff --git a/search/floyd_cycle_detection_algo.cpp b/search/floyd_cycle_detection_algo.cpp index c7dd95aea8c..4b4a34c31e4 100644 --- a/search/floyd_cycle_detection_algo.cpp +++ b/search/floyd_cycle_detection_algo.cpp @@ -12,9 +12,9 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector - /** * @namespace search * @brief Search algorithms diff --git a/search/interpolation_search.cpp b/search/interpolation_search.cpp index 5ed75774959..f2b0205ea68 100644 --- a/search/interpolation_search.cpp +++ b/search/interpolation_search.cpp @@ -31,6 +31,7 @@ #include /// for std::sort function #include /// for std::assert +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector diff --git a/search/saddleback_search.cpp b/search/saddleback_search.cpp index dab5adcf059..4f2a5606d2f 100644 --- a/search/saddleback_search.cpp +++ b/search/saddleback_search.cpp @@ -1,28 +1,34 @@ /** * @file - * @brief Implementation of [Saddleback Algorithm](https://www.geeksforgeeks.org/saddleback-search-algorithm-in-a-2d-array) for 2D arrays. + * @brief Implementation of [Saddleback + * Algorithm](https://www.geeksforgeeks.org/saddleback-search-algorithm-in-a-2d-array) + * for 2D arrays. * * @details * Saddleback Algorithm is an algorithm that searches 2D array in linear time, - * i.e, O(m + n), where m is number of rows and n is number of columns of 2D array. Also, each row and - * column of the matrix should be sorted beforehand for this algorithm to work. + * i.e, O(m + n), where m is number of rows and n is number of columns of 2D + * array. Also, each row and column of the matrix should be sorted beforehand + * for this algorithm to work. * * @author [Hashir Niazi](https://github.com/HashirGJ8842) */ -#include /// for assert -#include /// for io operations, and std::pair -#include /// for std::vector +#include /// for assert +#include /// for integral typedefs +#include /// for io operations, and std::pair +#include /// for std::vector /** \namespace search * \brief Algorithms for searching */ namespace search { /** \namespace saddleback - * \brief Function for implementing [Saddleback Algorithm](https://www.geeksforgeeks.org/saddleback-search-algorithm-in-a-2d-array). + * \brief Function for implementing [Saddleback + * Algorithm](https://www.geeksforgeeks.org/saddleback-search-algorithm-in-a-2d-array). */ namespace saddleback { /** - * This function implements [Saddleback Algorithm](https://www.geeksforgeeks.org/saddleback-search-algorithm-in-a-2d-array), + * This function implements [Saddleback + * Algorithm](https://www.geeksforgeeks.org/saddleback-search-algorithm-in-a-2d-array), * on a sorted 2D array, and finds the location of the element needed to search * @param matrix 2D matrix which is sorted on the basis of rows and columns * @param element element to be searched @@ -30,16 +36,17 @@ namespace saddleback { * element is present. * @return An std::pair with (0, 0), if the element is not present. */ -std::pair saddleback(std::vector> matrix, - int32_t element) { +std::pair saddleback( + std::vector> matrix, int32_t element) { uint32_t left_index = 0; uint32_t right_index = matrix[0].size() - 1; // Start from top right corner - while (left_index < matrix.size()) { // Exit once the value of indexes get out of range. + while (left_index < + matrix.size()) { // Exit once the value of indexes get out of range. if (element == matrix[left_index] [right_index]) { // If value on this position of matrix is // equal to element, return (row, column). - return std::make_pair(left_index+1, right_index+1); + return std::make_pair(left_index + 1, right_index + 1); } else if (element > matrix[left_index] [right_index]) { // Else if value on this position of @@ -51,14 +58,15 @@ std::pair saddleback(std::vector> matri [right_index]) { // Else if value on this position of // matrix is greater than the // element, move down. - if(!right_index) + if (!right_index) break; - else --right_index; + else + --right_index; } } return std::make_pair( 0, 0); // If the program reaches here, that means one of the index - // went out of index, hence no element present. + // went out of index, hence no element present. } } // namespace saddleback } // namespace search @@ -69,15 +77,16 @@ std::pair saddleback(std::vector> matri */ static void test() { std::vector> matrix = {{1, 10, 100, 1000, 10000}, - {2, 20, 200, 2000, 20000}, - {3, 30, 300, 3000, 30000}, - {4, 40, 400, 4000, 40000}, - {5, 50, 500, 5000, 50000}}; + {2, 20, 200, 2000, 20000}, + {3, 30, 300, 3000, 30000}, + {4, 40, 400, 4000, 40000}, + {5, 50, 500, 5000, 50000}}; std::pair not_found = std::make_pair(0, 0); std::pair test_answer; // Test 1 - std::pair answer1 = search::saddleback::saddleback(matrix, 123); + std::pair answer1 = + search::saddleback::saddleback(matrix, 123); assert(not_found == answer1); // Test 2 answer1 = search::saddleback::saddleback(matrix, 0); @@ -101,6 +110,6 @@ static void test() { * @returns 0 on exit */ int main() { - test(); // execute the tests + test(); // execute the tests return 0; } diff --git a/search/sublist_search.cpp b/search/sublist_search.cpp index 0954173d20c..7b485f04184 100644 --- a/search/sublist_search.cpp +++ b/search/sublist_search.cpp @@ -26,6 +26,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector From 4707b729cc260c597c339d9799eea7f716f360e7 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:30:32 +0530 Subject: [PATCH 031/131] fix: add to sorting/** --- sorting/cycle_sort.cpp | 1 + sorting/dnf_sort.cpp | 1 + sorting/quick_sort.cpp | 1 + sorting/radix_sort2.cpp | 2 ++ sorting/recursive_bubble_sort.cpp | 51 ++++++++++++++++------------ sorting/selection_sort_iterative.cpp | 1 + sorting/selection_sort_recursive.cpp | 7 ++-- sorting/wiggle_sort.cpp | 3 +- 8 files changed, 42 insertions(+), 25 deletions(-) diff --git a/sorting/cycle_sort.cpp b/sorting/cycle_sort.cpp index 8acf462af78..1371fac94ea 100644 --- a/sorting/cycle_sort.cpp +++ b/sorting/cycle_sort.cpp @@ -13,6 +13,7 @@ #include /// for std::is_sorted, std::swap #include /// for assert +#include /// for integral typedefs #include /// for io operations #include /// for std::vector diff --git a/sorting/dnf_sort.cpp b/sorting/dnf_sort.cpp index 8b7c2279e0e..3cdb1c34e36 100644 --- a/sorting/dnf_sort.cpp +++ b/sorting/dnf_sort.cpp @@ -12,6 +12,7 @@ #include /// for std::is_sorted #include /// for assert +#include /// for integral typedefs #include /// for std::swap and io operations #include /// for std::vector diff --git a/sorting/quick_sort.cpp b/sorting/quick_sort.cpp index 514361444e4..88d01ea1409 100644 --- a/sorting/quick_sort.cpp +++ b/sorting/quick_sort.cpp @@ -26,6 +26,7 @@ #include /// for std::is_sorted #include /// for std::assert +#include /// for integral typedefs #include /// for std::time #include /// for IO operations #include /// for std::vector diff --git a/sorting/radix_sort2.cpp b/sorting/radix_sort2.cpp index 3d6916e1617..84dd6911f83 100644 --- a/sorting/radix_sort2.cpp +++ b/sorting/radix_sort2.cpp @@ -23,8 +23,10 @@ */ /// header files + #include /// for collection of functions #include /// for a macro called assert which can be used to verify assumptions +#include /// for integral typedefs #include /// for io operations #include /// for std::vector diff --git a/sorting/recursive_bubble_sort.cpp b/sorting/recursive_bubble_sort.cpp index d76a72d8633..5b860f83319 100644 --- a/sorting/recursive_bubble_sort.cpp +++ b/sorting/recursive_bubble_sort.cpp @@ -1,20 +1,23 @@ /** * @file * @author [Aditya Prakash](https://adityaprakash.tech) - * @brief This is an implementation of a recursive version of the [Bubble sort algorithm](https://www.geeksforgeeks.org/recursive-bubble-sort/) + * @brief This is an implementation of a recursive version of the [Bubble sort + algorithm](https://www.geeksforgeeks.org/recursive-bubble-sort/) * * @details * The working principle of the Bubble sort algorithm. - * Bubble sort is a simple sorting algorithm used to rearrange a set of ascending or descending order elements. - * Bubble sort gets its name from the fact that data "bubbles" to the top of the dataset. - + * Bubble sort is a simple sorting algorithm used to rearrange a set of + ascending or descending order elements. + * Bubble sort gets its name from the fact that data "bubbles" to the top of the + dataset. + * ### Algorithm * What is Swap? * Swapping two numbers means that we interchange their values. - * Often, an additional variable is required for this operation. + * Often, an additional variable is required for this operation. * This is further illustrated in the following: * void swap(int x, int y){ @@ -26,15 +29,19 @@ * The above process is a typical displacement process. * When we assign a value to x, the old value of x is lost. * That's why we create a temporary variable z to store the initial value of x. - * z is further used to assign the initial value of x to y, to complete swapping. + * z is further used to assign the initial value of x to y, to complete + swapping. * Recursion - * While the recursive method does not necessarily have advantages over iterative + * While the recursive method does not necessarily have advantages over + iterative * versions, but it is useful to enhance the understanding of the algorithm and * recursion itself. In Recursive Bubble sort algorithm, we firstly call the - * function on the entire array, and for every subsequent function call, we exclude - * the last element. This fixes the last element for that sub-array.Formally, for + * function on the entire array, and for every subsequent function call, we + exclude + * the last element. This fixes the last element for that sub-array.Formally, + for * `ith` iteration, we consider elements up to n-i, where n is the number of * elements in the array. Exit condition: n==1; i.e. the sub-array contains only * one element. @@ -43,16 +50,19 @@ * Time complexity: O(n) best case; O(n²) average case; O(n²) worst case * Space complexity: O(n) - * We need to traverse the array `n * (n-1)` times. However, if the entire array is - * already sorted, then we need to traverse it only once. Hence, O(n) is the best case + * We need to traverse the array `n * (n-1)` times. However, if the entire array + is + * already sorted, then we need to traverse it only once. Hence, O(n) is the + best case * complexity */ -#include /// for assert -#include /// for IO operations -#include /// for std::vector -#include /// for std::array -#include /// for std::is_sorted +#include /// for std::is_sorted +#include /// for std::array +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations +#include /// for std::vector /** * @namespace sorting @@ -61,11 +71,11 @@ namespace sorting { /** - * @brief This is an implementation of the recursive_bubble_sort. A vector is passed - * to the function which is then dereferenced, so that the changes are + * @brief This is an implementation of the recursive_bubble_sort. A vector is + * passed to the function which is then dereferenced, so that the changes are * reflected in the original vector. It also accepts a second parameter of * type `int` and name `n`, which is the size of the array. - * + * * @tparam T type of data variables in the array * @param nums our array of elements. * @param n size of the array @@ -136,14 +146,13 @@ static void test() { std::cout << double_arr[i] << ", "; } std::cout << std::endl; - } /** * @brief Main function * @returns 0 on exit */ -int main() { +int main() { test(); // run self-test implementations return 0; } diff --git a/sorting/selection_sort_iterative.cpp b/sorting/selection_sort_iterative.cpp index a9adac0891b..c25dac9814f 100644 --- a/sorting/selection_sort_iterative.cpp +++ b/sorting/selection_sort_iterative.cpp @@ -29,6 +29,7 @@ *******************************************************************************/ #include /// for std::is_sorted #include /// for std::assert +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector diff --git a/sorting/selection_sort_recursive.cpp b/sorting/selection_sort_recursive.cpp index 57eadfbd0fe..80f9ac7193b 100644 --- a/sorting/selection_sort_recursive.cpp +++ b/sorting/selection_sort_recursive.cpp @@ -28,9 +28,10 @@ */ #include /// for std::is_sorted -#include /// for assert -#include /// for std::swap and io operations -#include /// for std::vector +#include /// for assert#include /// for integral typedefs +#include /// for integral typedefs +#include /// for std::swap and io operations +#include /// for std::vector /** * @namespace sorting diff --git a/sorting/wiggle_sort.cpp b/sorting/wiggle_sort.cpp index bf8574c98c5..fe5009bb428 100644 --- a/sorting/wiggle_sort.cpp +++ b/sorting/wiggle_sort.cpp @@ -19,6 +19,7 @@ #include #include +#include /// for integral typedefs #include #include /// for io operations #include @@ -50,7 +51,7 @@ namespace wiggle_sort { */ template // this allows to have vectors of ints, double, float, // etc - std::vector wiggleSort(const std::vector &arr) { +std::vector wiggleSort(const std::vector &arr) { uint32_t size = arr.size(); std::vector out( From ba64b3c9fc12b815b559b979148ddaeaabcf6bdc Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:30:47 +0530 Subject: [PATCH 032/131] fix: add to string/** --- strings/manacher_algorithm.cpp | 1 + strings/z_function.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/strings/manacher_algorithm.cpp b/strings/manacher_algorithm.cpp index 94314c3b466..1c1581a3374 100644 --- a/strings/manacher_algorithm.cpp +++ b/strings/manacher_algorithm.cpp @@ -11,6 +11,7 @@ */ #include /// for assert +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector STL #ifdef _MSC_VER diff --git a/strings/z_function.cpp b/strings/z_function.cpp index 6ce98c491d1..25a5755a7f7 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -11,6 +11,7 @@ * @author [Ritika Gupta](https://github.com/RitikaGupta8734) */ +#include /// for integral typedefs #include /// for IO operations #ifdef _MSC_VER #include /// for string (use this for MS Visual C++) From 52b2afeb866e713271e50513d20ac8ac19700d69 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:36:30 +0530 Subject: [PATCH 033/131] doc: remove include statement from comment --- sorting/selection_sort_recursive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/selection_sort_recursive.cpp b/sorting/selection_sort_recursive.cpp index 80f9ac7193b..765b9709891 100644 --- a/sorting/selection_sort_recursive.cpp +++ b/sorting/selection_sort_recursive.cpp @@ -28,7 +28,7 @@ */ #include /// for std::is_sorted -#include /// for assert#include /// for integral typedefs +#include /// for assert #include /// for integral typedefs #include /// for std::swap and io operations #include /// for std::vector From fad74e89dc696245e635c9af2cbfa748a1af136b Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Thu, 5 Sep 2024 05:13:01 +0530 Subject: [PATCH 034/131] fix: make tests static Co-authored-by: David Leal --- math/fibonacci_matrix_exponentiation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/fibonacci_matrix_exponentiation.cpp b/math/fibonacci_matrix_exponentiation.cpp index 3dd4c721337..347d3800c80 100644 --- a/math/fibonacci_matrix_exponentiation.cpp +++ b/math/fibonacci_matrix_exponentiation.cpp @@ -88,7 +88,7 @@ uint64_t fibo(uint64_t n, uint64_t mod) { /** * Function to test above algorithm */ -void test() { +static void test() { assert(fibo(6, 1000000007) == 8); std::cout << "test case:1 passed\n"; assert(fibo(5, 1000000007) == 5); From f063687892c12cc362fb85f8adf6bbd2d700a926 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Thu, 5 Sep 2024 05:13:16 +0530 Subject: [PATCH 035/131] fix: make tests static Co-authored-by: David Leal --- math/sieve_of_eratosthenes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/sieve_of_eratosthenes.cpp b/math/sieve_of_eratosthenes.cpp index 7b77b347455..e252e1955cb 100644 --- a/math/sieve_of_eratosthenes.cpp +++ b/math/sieve_of_eratosthenes.cpp @@ -56,7 +56,7 @@ void print(uint32_t N, const std::vector &is_prime) { /** * Test implementations */ -void tests() { +static void tests() { // 0 1 2 3 4 5 6 7 8 // 9 10 std::vector ans{false, false, true, true, false, true, From f0a30d7cdbc0b06330b02d9ff0387feb3d9b380b Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:36:54 +0530 Subject: [PATCH 036/131] chore: use iwyu on backtracking/**.cpp --- backtracking/generate_parentheses.cpp | 7 ++++--- backtracking/graph_coloring.cpp | 6 +++--- backtracking/knight_tour.cpp | 5 +++-- backtracking/minimax.cpp | 9 +++++---- backtracking/n_queens.cpp | 5 +++-- backtracking/n_queens_all_solution_optimised.cpp | 5 +++-- backtracking/nqueen_print_all_solutions.cpp | 6 ++++-- backtracking/rat_maze.cpp | 7 ++++--- backtracking/sudoku_solver.cpp | 6 ++++-- backtracking/wildcard_matching.cpp | 9 +++++---- 10 files changed, 38 insertions(+), 27 deletions(-) diff --git a/backtracking/generate_parentheses.cpp b/backtracking/generate_parentheses.cpp index 8a9e3b3301d..83cce0d89de 100644 --- a/backtracking/generate_parentheses.cpp +++ b/backtracking/generate_parentheses.cpp @@ -11,9 +11,10 @@ */ -#include /// for assert -#include /// for I/O operation -#include /// for vector container +#include // for assert +#include // for char_traits, operator<<, basic_ostream, cout +#include // for allocator, vector, operator== +#include // for basic_string, string, operator+, operator== /** * @brief Backtracking algorithms diff --git a/backtracking/graph_coloring.cpp b/backtracking/graph_coloring.cpp index 8fb328a1a80..b6b4e06a592 100644 --- a/backtracking/graph_coloring.cpp +++ b/backtracking/graph_coloring.cpp @@ -18,9 +18,9 @@ * @author [David Leal](https://github.com/Panquesito7) */ -#include /// for std::array -#include /// for IO operations -#include /// for std::vector +#include // for array +#include // for size_t +#include // for operator<<, cout, basic_ostream, basic_ostream::... /** * @namespace backtracking diff --git a/backtracking/knight_tour.cpp b/backtracking/knight_tour.cpp index 0223462db7b..b97d876dfc6 100644 --- a/backtracking/knight_tour.cpp +++ b/backtracking/knight_tour.cpp @@ -13,8 +13,9 @@ * @author [Nikhil Arora](https://github.com/nikhilarora068) * @author [David Leal](https://github.com/Panquesito7) */ -#include /// for std::array -#include /// for IO operations +#include // for array +#include // for size_t +#include // for char_traits, operator<<, basic_ostream, cout /** * @namespace backtracking diff --git a/backtracking/minimax.cpp b/backtracking/minimax.cpp index b27c85e1047..99d8009d031 100644 --- a/backtracking/minimax.cpp +++ b/backtracking/minimax.cpp @@ -16,10 +16,11 @@ * @author [Gleison Batista](https://github.com/gleisonbs) * @author [David Leal](https://github.com/Panquesito7) */ -#include /// for std::max, std::min -#include /// for std::array -#include /// for log2 -#include /// for IO operations +#include // for max, min +#include // for array +#include // for log2 +#include // for size_t +#include // for char_traits, basic_ostream, basic_ostream::oper... /** * @namespace backtracking diff --git a/backtracking/n_queens.cpp b/backtracking/n_queens.cpp index f9742eb7a53..1f10f6e2f4d 100644 --- a/backtracking/n_queens.cpp +++ b/backtracking/n_queens.cpp @@ -15,8 +15,9 @@ * @author [David Leal](https://github.com/Panquesito7) * */ -#include -#include +#include // for array +#include // for size_t +#include // for operator<<, basic_ostream, cout, basic_ostream::... /** * @namespace backtracking diff --git a/backtracking/n_queens_all_solution_optimised.cpp b/backtracking/n_queens_all_solution_optimised.cpp index 525d4c2db18..b661c49c0a0 100644 --- a/backtracking/n_queens_all_solution_optimised.cpp +++ b/backtracking/n_queens_all_solution_optimised.cpp @@ -7,8 +7,9 @@ * @author [David Leal](https://github.com/Panquesito7) */ -#include -#include +#include // for array +#include // for size_t +#include // for cout, basic_ostream, endl, basic_ostream::operat... /** * @namespace backtracking diff --git a/backtracking/nqueen_print_all_solutions.cpp b/backtracking/nqueen_print_all_solutions.cpp index 8824cf0a828..a0d41f009d6 100644 --- a/backtracking/nqueen_print_all_solutions.cpp +++ b/backtracking/nqueen_print_all_solutions.cpp @@ -7,8 +7,10 @@ * @author [David Leal](https://github.com/Panquesito7) * */ -#include /// for std::array -#include /// for IO operations +#include // for array +#include // for size_t +#include // for cout, basic_ostream, endl, basic_ostream::operat... + /** * @namespace backtracking diff --git a/backtracking/rat_maze.cpp b/backtracking/rat_maze.cpp index 60bc521c88f..c18bc8f0dd9 100644 --- a/backtracking/rat_maze.cpp +++ b/backtracking/rat_maze.cpp @@ -16,9 +16,10 @@ * @author [David Leal](https://github.com/Panquesito7) */ -#include /// for std::array -#include /// for assert -#include /// for IO operations +#include // for array +#include // for assert +#include // for size_t +#include // for cout, basic_ostream, basic_ostream::operator<< /** * @namespace backtracking diff --git a/backtracking/sudoku_solver.cpp b/backtracking/sudoku_solver.cpp index 38ccfa0b4dc..bc359a91eb3 100644 --- a/backtracking/sudoku_solver.cpp +++ b/backtracking/sudoku_solver.cpp @@ -15,8 +15,10 @@ * @author [DarthCoder3200](https://github.com/DarthCoder3200) * @author [David Leal](https://github.com/Panquesito7) */ -#include /// for assert -#include /// for IO operations +#include // for array +#include // for size_t +#include // for basic_ostream, char_traits, cout, operator<< + /** * @namespace backtracking diff --git a/backtracking/wildcard_matching.cpp b/backtracking/wildcard_matching.cpp index b637f9f2d03..e1b83a6bbe6 100644 --- a/backtracking/wildcard_matching.cpp +++ b/backtracking/wildcard_matching.cpp @@ -11,10 +11,11 @@ * @author [Swastika Gupta](https://github.com/Swastyy) */ -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations -#include /// for std::vector +#include // for assert +#include // for uint32_t, int64_t +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for vector +#include // for basic_string, string /** * @namespace backtracking From 7edcb6e458fecd7ed05a7d4e87418680f443ec23 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:37:06 +0530 Subject: [PATCH 037/131] chore: use iwyu on bit_manip/**.cpp --- bit_manipulation/find_non_repeating_number.cpp | 7 ++++--- bit_manipulation/hamming_distance.cpp | 8 +++++--- .../travelling_salesman_using_bit_manipulation.cpp | 11 +++++------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/bit_manipulation/find_non_repeating_number.cpp b/bit_manipulation/find_non_repeating_number.cpp index cc63d29cc70..e5ea483d2d9 100644 --- a/bit_manipulation/find_non_repeating_number.cpp +++ b/bit_manipulation/find_non_repeating_number.cpp @@ -15,9 +15,10 @@ * @author [Ravidev Pandey](https://github.com/literalEval) */ -#include /// for assert -#include /// for IO operations -#include /// storing the numbers +#include // for int64_t +#include // for assert +#include // for char_traits, basic_ostream, operator<<, cout, endl +#include // for vector /** * @namespace bit_manipulation diff --git a/bit_manipulation/hamming_distance.cpp b/bit_manipulation/hamming_distance.cpp index 1f6685ffca8..935ac5a58d6 100644 --- a/bit_manipulation/hamming_distance.cpp +++ b/bit_manipulation/hamming_distance.cpp @@ -12,9 +12,11 @@ * @author [Ravishankar Joshi](https://github.com/ravibitsgoa) */ -#include /// for assert -#include /// for integral typedefs -#include /// for io operations +#include // for assert +#include // for size_t +#include // for uint64_t +#include // for char_traits, basic_ostream, operator<<, cout, endl +#include // for basic_string, string /** * @namespace bit_manipulation diff --git a/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp b/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp index 5eac30bc776..7b234dbccf6 100644 --- a/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp +++ b/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp @@ -20,12 +20,11 @@ * Space complexity: O(n) * @author [Utkarsh Yadav](https://github.com/Rytnix) */ -#include /// for std::min -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations -#include /// for limits of integral types -#include /// for std::vector +#include // for min +#include // for assert +#include // for uint64_t, uint32_t +#include // for operator<<, char_traits, basic_ostream, cout +#include // for vector /** * @namespace bit_manipulation From 3d80295883d15a6753f1e0e746c19a0c3ea35abe Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:37:16 +0530 Subject: [PATCH 038/131] chore: use iwyu on ciphers/**.cpp --- ciphers/a1z26_cipher.cpp | 18 ++- ciphers/atbash_cipher.cpp | 9 +- ciphers/base64_encoding.cpp | 7 +- ciphers/elliptic_curve_key_exchange.cpp | 8 +- ciphers/morse_code.cpp | 9 +- ciphers/vigenere_cipher.cpp | 197 +++++++++++++----------- 6 files changed, 135 insertions(+), 113 deletions(-) diff --git a/ciphers/a1z26_cipher.cpp b/ciphers/a1z26_cipher.cpp index 82a3d3bb4e0..7aa28a02e2a 100644 --- a/ciphers/a1z26_cipher.cpp +++ b/ciphers/a1z26_cipher.cpp @@ -9,14 +9,16 @@ * @author [Focusucof](https://github.com/Focusucof) */ -#include /// for std::transform and std::replace -#include /// for assert -#include /// for uint8_t -#include /// for IO operations -#include /// for std::map -#include /// for std::stringstream -#include /// for std::string -#include /// for std::vector +#include // for tolower, toupper +#include // for replace, transform +#include // for assert +#include // for uint8_t +#include // for basic_ostream, operator<<, basic_istream, cout +#include // for map +#include // for basic_stringstream +#include // for basic_string, char_traits, operator<<, string +#include // for vector +#include // for pair /** * @namespace ciphers diff --git a/ciphers/atbash_cipher.cpp b/ciphers/atbash_cipher.cpp index 4f0d793f237..11b2f3dc2e6 100644 --- a/ciphers/atbash_cipher.cpp +++ b/ciphers/atbash_cipher.cpp @@ -12,10 +12,11 @@ * * @author [Focusucof](https://github.com/Focusucof) */ -#include /// for assert -#include /// for IO operations -#include /// for std::map -#include /// for std::string +#include // for assert +#include // for basic_ostream, operator<<, cout, endl +#include // for map +#include // for basic_string, char_traits, allocator, operator<< +#include // for pair /** \namespace ciphers * \brief Algorithms for encryption and decryption diff --git a/ciphers/base64_encoding.cpp b/ciphers/base64_encoding.cpp index 52bce90ff9a..d4090a59646 100644 --- a/ciphers/base64_encoding.cpp +++ b/ciphers/base64_encoding.cpp @@ -11,10 +11,9 @@ * digits. * @author [Ashish Daulatabad](https://github.com/AshishYUO) */ -#include /// for `std::array` -#include /// for `assert` operations -#include /// for integral typedefs -#include /// for IO operations +#include // for assert +#include // for uint32_t, uint8_t +#include // for basic_string, allocator, string, char_traits, ope... /** * @namespace ciphers diff --git a/ciphers/elliptic_curve_key_exchange.cpp b/ciphers/elliptic_curve_key_exchange.cpp index 0a9ce3cd0e3..7955466ae5b 100644 --- a/ciphers/elliptic_curve_key_exchange.cpp +++ b/ciphers/elliptic_curve_key_exchange.cpp @@ -21,10 +21,12 @@ * alicePubKey * bobPrivKey = bobPubKey * alicePrivKey = secret * @author [Ashish Daulatabad](https://github.com/AshishYUO) */ -#include /// for assert -#include /// for IO operations +#include // for assert +#include // for basic_ostream, operator<<, char_traits, cout +#include // for basic_string -#include "uint256_t.hpp" /// for 256-bit integer +#include "uint256_t.hpp" // for uint256_t, operator<< +#include "uint128_t.hpp" // for uint128_t /** * @namespace ciphers diff --git a/ciphers/morse_code.cpp b/ciphers/morse_code.cpp index f8ff51c5c1d..f446a8ec5e3 100644 --- a/ciphers/morse_code.cpp +++ b/ciphers/morse_code.cpp @@ -11,10 +11,11 @@ * and dashes or dits and dahs. Morse code is named after Samuel Morse, an * inventor of the telegraph. */ -#include -#include -#include -#include +#include // for assert +#include // for basic_ostream, operator<<, endl, cout, cerr +#include // for basic_string, operator==, char_traits, string +#include // for vector +#include // for exit, size_t /** \namespace ciphers * \brief Algorithms for encryption and decryption diff --git a/ciphers/vigenere_cipher.cpp b/ciphers/vigenere_cipher.cpp index 4efd56c0013..17e1e3c552b 100644 --- a/ciphers/vigenere_cipher.cpp +++ b/ciphers/vigenere_cipher.cpp @@ -1,109 +1,126 @@ /** * @file vigenere_cipher.cpp - * @brief Implementation of [Vigenère cipher](https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher) algorithm. + * @brief Implementation of [Vigenère + * cipher](https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher) algorithm. * * @details - * The Vigenère cipher is a method of encrypting alphabetic text by using a series of interwoven vigenere - * ciphers, based on the letters of a keyword. It employs a form of polyalphabetic substitution. + * The Vigenère cipher is a method of encrypting alphabetic text by using a + * series of interwoven vigenere ciphers, based on the letters of a keyword. It + * employs a form of polyalphabetic substitution. * * ### Algorithm - * The encryption can also be represented using modular arithmetic by first transforming - * the letters into numbers, according to the scheme, A → 0, B → 1, ..., Z → 25. - * Encryption of \f$i^{th}\f$ character in Message M by key K can be described mathematically as, - * + * The encryption can also be represented using modular arithmetic by first + * transforming the letters into numbers, according to the scheme, A → 0, B → 1, + * ..., Z → 25. Encryption of \f$i^{th}\f$ character in Message M by key K can + * be described mathematically as, + * * \f[ E_{K}(M_{i}) = (M_{i} + K_{i})\;\mbox{mod}\; 26\f] - * - * while decryption of \f$i^{th}\f$ character in Cipher C by key K can be described mathematically as, + * + * while decryption of \f$i^{th}\f$ character in Cipher C by key K can be + * described mathematically as, * * \f[ D_{k}(C_{i}) = (C_{i} - K_{i} + 26)\;\mbox{mod}\; 26\f] - * - * Where \f$K_{i}\f$ denotes corresponding character in key. If \f$|key| < |text|\f$ than - * same key is repeated untill their lengths are equal. - * + * + * Where \f$K_{i}\f$ denotes corresponding character in key. If \f$|key| < + * |text|\f$ than same key is repeated untill their lengths are equal. + * * For Example, * If M = "ATTACKATDAWN" and K = "LEMON" than K becomes "LEMONLEMONLE". - * - * \note Rather than creating new key of equal length this program does this by using modular index for key - * (i.e. \f$(j + 1) \;\mbox{mod}\; |\mbox{key}|\f$) - * - * \note This program implements Vigenère cipher for only uppercase English alphabet characters (i.e. A-Z). - * + * + * \note Rather than creating new key of equal length this program does this by + * using modular index for key (i.e. \f$(j + 1) \;\mbox{mod}\; |\mbox{key}|\f$) + * + * \note This program implements Vigenère cipher for only uppercase English + * alphabet characters (i.e. A-Z). + * * @author [Deep Raval](https://github.com/imdeep2905) */ -#include -#include -#include +#include // for assert +#include // for size_t +#include // for basic_ostream, operator<<, cout, endl +#include // for basic_string, char_traits, string, operator<< /** \namespace ciphers * \brief Algorithms for encryption and decryption */ namespace ciphers { - /** \namespace vigenere - * \brief Functions for [vigenère cipher](https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher) algorithm. - */ - namespace vigenere { - namespace { - /** - * This function finds character for given value (i.e.A-Z) - * @param x value for which we want character - * @return corresponding character for perticular value - */ - inline char get_char(const int x) { - // By adding 65 we are scaling 0-25 to 65-90. - // Which are in fact ASCII values of A-Z. - return char(x + 65); - } - /** - * This function finds value for given character (i.e.0-25) - * @param c character for which we want value - * @return returns corresponding value for perticular character - */ - inline int get_value(const char c) { - // A-Z have ASCII values in range 65-90. - // Hence subtracting 65 will scale them to 0-25. - return int(c - 65); - } - } // Unnamed namespace - /** - * Encrypt given text using vigenere cipher. - * @param text text to be encrypted - * @param key to be used for encryption - * @return new encrypted text - */ - std::string encrypt (const std::string &text, const std::string &key) { - std::string encrypted_text = ""; // Empty string to store encrypted text - // Going through each character of text and key - // Note that key is visited in circular way hence j = (j + 1) % |key| - for(size_t i = 0, j = 0; i < text.length(); i++, j = (j + 1) % key.length()) { - int place_value_text = get_value(text[i]); // Getting value of character in text - int place_value_key = get_value(key[j]); // Getting value of character in key - place_value_text = (place_value_text + place_value_key) % 26; // Applying encryption - char encrypted_char = get_char(place_value_text); // Getting new character from encrypted value - encrypted_text += encrypted_char; // Appending encrypted character - } - return encrypted_text; // Returning encrypted text - } - /** - * Decrypt given text using vigenere cipher. - * @param text text to be decrypted - * @param key key to be used for decryption - * @return new decrypted text - */ - std::string decrypt (const std::string &text, const std::string &key) { - // Going through each character of text and key - // Note that key is visited in circular way hence j = (j + 1) % |key| - std::string decrypted_text = ""; // Empty string to store decrypted text - for(size_t i = 0, j = 0; i < text.length(); i++, j = (j + 1) % key.length()) { - int place_value_text = get_value(text[i]); // Getting value of character in text - int place_value_key = get_value(key[j]); // Getting value of character in key - place_value_text = (place_value_text - place_value_key + 26) % 26; // Applying decryption - char decrypted_char = get_char(place_value_text); // Getting new character from decrypted value - decrypted_text += decrypted_char; // Appending decrypted character - } - return decrypted_text; // Returning decrypted text - } - } // namespace vigenere -} // namespace ciphers +/** \namespace vigenere + * \brief Functions for [vigenère + * cipher](https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher) algorithm. + */ +namespace vigenere { +namespace { +/** + * This function finds character for given value (i.e.A-Z) + * @param x value for which we want character + * @return corresponding character for perticular value + */ +inline char get_char(const int x) { + // By adding 65 we are scaling 0-25 to 65-90. + // Which are in fact ASCII values of A-Z. + return char(x + 65); +} +/** + * This function finds value for given character (i.e.0-25) + * @param c character for which we want value + * @return returns corresponding value for perticular character + */ +inline int get_value(const char c) { + // A-Z have ASCII values in range 65-90. + // Hence subtracting 65 will scale them to 0-25. + return int(c - 65); +} +} // Unnamed namespace +/** + * Encrypt given text using vigenere cipher. + * @param text text to be encrypted + * @param key to be used for encryption + * @return new encrypted text + */ +std::string encrypt(const std::string &text, const std::string &key) { + std::string encrypted_text = ""; // Empty string to store encrypted text + // Going through each character of text and key + // Note that key is visited in circular way hence j = (j + 1) % |key| + for (size_t i = 0, j = 0; i < text.length(); + i++, j = (j + 1) % key.length()) { + int place_value_text = + get_value(text[i]); // Getting value of character in text + int place_value_key = + get_value(key[j]); // Getting value of character in key + place_value_text = + (place_value_text + place_value_key) % 26; // Applying encryption + char encrypted_char = get_char( + place_value_text); // Getting new character from encrypted value + encrypted_text += encrypted_char; // Appending encrypted character + } + return encrypted_text; // Returning encrypted text +} +/** + * Decrypt given text using vigenere cipher. + * @param text text to be decrypted + * @param key key to be used for decryption + * @return new decrypted text + */ +std::string decrypt(const std::string &text, const std::string &key) { + // Going through each character of text and key + // Note that key is visited in circular way hence j = (j + 1) % |key| + std::string decrypted_text = ""; // Empty string to store decrypted text + for (size_t i = 0, j = 0; i < text.length(); + i++, j = (j + 1) % key.length()) { + int place_value_text = + get_value(text[i]); // Getting value of character in text + int place_value_key = + get_value(key[j]); // Getting value of character in key + place_value_text = (place_value_text - place_value_key + 26) % + 26; // Applying decryption + char decrypted_char = get_char( + place_value_text); // Getting new character from decrypted value + decrypted_text += decrypted_char; // Appending decrypted character + } + return decrypted_text; // Returning decrypted text +} +} // namespace vigenere +} // namespace ciphers /** * Function to test above algorithm @@ -116,7 +133,7 @@ void test() { assert(text1 == decrypted1); std::cout << "Original text : " << text1; std::cout << " , Encrypted text (with key = TESLA) : " << encrypted1; - std::cout << " , Decrypted text : "<< decrypted1 << std::endl; + std::cout << " , Decrypted text : " << decrypted1 << std::endl; // Test 2 std::string text2 = "GOOGLEIT"; std::string encrypted2 = ciphers::vigenere::encrypt(text2, "REALLY"); @@ -124,7 +141,7 @@ void test() { assert(text2 == decrypted2); std::cout << "Original text : " << text2; std::cout << " , Encrypted text (with key = REALLY) : " << encrypted2; - std::cout << " , Decrypted text : "<< decrypted2 << std::endl; + std::cout << " , Decrypted text : " << decrypted2 << std::endl; } /** Driver Code */ From 24e597f7e249c7fd6998b2db39eba7a91d484455 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:37:34 +0530 Subject: [PATCH 039/131] chore: use iwyu on cpu_scheduling_algorithms/**.cpp --- cpu_scheduling_algorithms/fcfs_scheduling.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cpu_scheduling_algorithms/fcfs_scheduling.cpp b/cpu_scheduling_algorithms/fcfs_scheduling.cpp index 6eab989e4f2..4e899e5df32 100644 --- a/cpu_scheduling_algorithms/fcfs_scheduling.cpp +++ b/cpu_scheduling_algorithms/fcfs_scheduling.cpp @@ -9,16 +9,17 @@ * @author [Pratyush Vatsa](https://github.com/Pratyush219) */ -#include /// for sorting -#include /// for assert -#include /// for integral typedefs -#include /// random number generation -#include /// for time -#include /// for formatting the output -#include /// for IO operations -#include /// for std::priority_queue -#include /// for std::unordered_set -#include /// for std::vector +#include // for sort +#include // for assert +#include // for uint32_t +#include // for rand, srand, size_t +#include // for time +#include // for setw, operator<<, _Setw, setprecision, _Set... +#include // for basic_ostream, char_traits, operator<<, left +#include // for priority_queue +#include // for unordered_set, operator== +#include // for vector, operator==, allocator +#include // for tuple, get, make_tuple, operator==, swap using std::cin; using std::cout; From a3b719e3684d32d966ed64f31d3c20bdfd3b5ea3 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:37:49 +0530 Subject: [PATCH 040/131] chore: use iwyu on data_structures/**.cpp --- data_structures/binary_search_tree.cpp | 47 +- data_structures/binary_search_tree2.cpp | 12 +- data_structures/bloom_filter.cpp | 13 +- data_structures/cll/cll.cpp | 4 + data_structures/cll/main_cll.cpp | 5 +- data_structures/doubly_linked_list.cpp | 5 +- data_structures/dsu_path_compression.cpp | 10 +- data_structures/dsu_union_rank.cpp | 9 +- data_structures/linked_list.cpp | 7 +- data_structures/list_array.cpp | 9 +- data_structures/morrisinorder.cpp | 5 +- data_structures/queue_using_array.cpp | 7 +- data_structures/queue_using_linked_list.cpp | 4 +- data_structures/queue_using_linkedlist.cpp | 3 +- data_structures/queue_using_two_stacks.cpp | 7 +- data_structures/rb_tree.cpp | 892 +++++++++----------- data_structures/reverse_a_linked_list.cpp | 9 +- data_structures/skip_list.cpp | 12 +- data_structures/sparse_table.cpp | 11 +- data_structures/stack_using_array.cpp | 9 +- data_structures/stack_using_queue.cpp | 7 +- data_structures/test_queue.cpp | 9 +- data_structures/test_stack.cpp | 11 +- data_structures/test_stack_students.cpp | 15 +- data_structures/treap.cpp | 9 +- data_structures/tree.cpp | 54 +- data_structures/tree_234.cpp | 15 +- data_structures/trie_modern.cpp | 9 +- data_structures/trie_tree.cpp | 13 +- data_structures/trie_using_hashmap.cpp | 14 +- 30 files changed, 602 insertions(+), 634 deletions(-) diff --git a/data_structures/binary_search_tree.cpp b/data_structures/binary_search_tree.cpp index 86057c6c507..637a587781a 100644 --- a/data_structures/binary_search_tree.cpp +++ b/data_structures/binary_search_tree.cpp @@ -6,7 +6,8 @@ * \warning This program is a poor implementation - C style - and does not * utilize any of the C++ STL features. */ -#include +#include // for NULL +#include // for operator<<, basic_ostream, char_traits, cout struct node { int val; @@ -145,28 +146,28 @@ int main() { std::cin >> ch; int x; switch (ch) { - case 1: - std::cout << "\nEnter the value to be Inserted : "; - std::cin >> x; - Insert(root, x); - break; - case 2: - std::cout << "\nEnter the value to be Deleted : "; - std::cin >> x; - Remove(root, root, x); - break; - case 3: - BFT(root); - break; - case 4: - Pre(root); - break; - case 5: - In(root); - break; - case 6: - Post(root); - break; + case 1: + std::cout << "\nEnter the value to be Inserted : "; + std::cin >> x; + Insert(root, x); + break; + case 2: + std::cout << "\nEnter the value to be Deleted : "; + std::cin >> x; + Remove(root, root, x); + break; + case 3: + BFT(root); + break; + case 4: + Pre(root); + break; + case 5: + In(root); + break; + case 6: + Post(root); + break; } } while (ch != 0); diff --git a/data_structures/binary_search_tree2.cpp b/data_structures/binary_search_tree2.cpp index 55ae3a43877..b1fbac9a91f 100644 --- a/data_structures/binary_search_tree2.cpp +++ b/data_structures/binary_search_tree2.cpp @@ -5,11 +5,13 @@ * @see binary_search_tree.cpp */ -#include -#include -#include -#include -#include +#include // for assert +#include // for function +#include // for basic_ostream, operator<<, cout, char_traits +#include // for operator==, unique_ptr, allocator +#include // for vector, operator== +#include // for size_t +#include // for move /** * @brief The Binary Search Tree class. diff --git a/data_structures/bloom_filter.cpp b/data_structures/bloom_filter.cpp index e2f7372e0c4..75a7d71a2fa 100644 --- a/data_structures/bloom_filter.cpp +++ b/data_structures/bloom_filter.cpp @@ -22,12 +22,13 @@ * @author [DanArmor](https://github.com/DanArmor) */ -#include /// for assert -#include /// for list of hash functions for bloom filter constructor -#include /// for initializer_list for bloom filter constructor -#include /// for testing on strings -#include /// for std::vector -#include /// for IO operations +#include // for assert +#include // for function +#include // for initializer_list +#include // for basic_string, string +#include // for vector +#include // for operator<<, basic_ostream, cout +#include // for size_t /** * @namespace data_structures diff --git a/data_structures/cll/cll.cpp b/data_structures/cll/cll.cpp index 42bc9067e20..68f2e93d878 100644 --- a/data_structures/cll/cll.cpp +++ b/data_structures/cll/cll.cpp @@ -2,6 +2,10 @@ A simple class for Cicular Linear Linked List */ #include "cll.h" + +#include // for NULL +#include // for basic_ostream, char_traits, operator<<, cout + using namespace std; /* Constructor */ diff --git a/data_structures/cll/main_cll.cpp b/data_structures/cll/main_cll.cpp index 0b6bfd3edef..3f67b628b9e 100644 --- a/data_structures/cll/main_cll.cpp +++ b/data_structures/cll/main_cll.cpp @@ -1,4 +1,7 @@ -#include "cll.h" +#include // for basic_ostream, operator<<, char_traits, cout, endl + +#include "cll.h" // for cll + using namespace std; int main() { diff --git a/data_structures/doubly_linked_list.cpp b/data_structures/doubly_linked_list.cpp index 30cc257d84f..ea09a1d7a29 100644 --- a/data_structures/doubly_linked_list.cpp +++ b/data_structures/doubly_linked_list.cpp @@ -1,6 +1,5 @@ -#include -#include -#include +#include // for NULL +#include // for operator<<, basic_ostream, cout, char_traits struct node { int val; diff --git a/data_structures/dsu_path_compression.cpp b/data_structures/dsu_path_compression.cpp index 9dff7b40bb0..8bcaf7cbfb9 100644 --- a/data_structures/dsu_path_compression.cpp +++ b/data_structures/dsu_path_compression.cpp @@ -18,10 +18,12 @@ * @see dsu_union_rank.cpp */ -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations -#include /// for std::vector +#include // for assert +#include // for uint64_t +#include // for char_traits, basic_ostream, operator<<, cout, endl +#include // for vector +#include // for max, min +#include // for swap using std::cout; using std::endl; diff --git a/data_structures/dsu_union_rank.cpp b/data_structures/dsu_union_rank.cpp index 4ca53bb76f6..3a491254a46 100644 --- a/data_structures/dsu_union_rank.cpp +++ b/data_structures/dsu_union_rank.cpp @@ -19,10 +19,11 @@ * @see dsu_path_compression.cpp */ -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations -#include /// for std::vector +#include // for assert +#include // for uint64_t +#include // for char_traits, basic_ostream, operator<<, cout, endl +#include // for vector +#include // for swap using std::cout; using std::endl; diff --git a/data_structures/linked_list.cpp b/data_structures/linked_list.cpp index 08bfe68b1e9..c10b76c98ad 100644 --- a/data_structures/linked_list.cpp +++ b/data_structures/linked_list.cpp @@ -14,9 +14,10 @@ * to point to the node that the current node is pointing to, and then returning * the current node to heap store. */ -#include -#include -#include +#include // for isdigit +#include // for operator<<, basic_ostream, cout, basic_istream, cin +#include // for shared_ptr, __shared_ptr_access, make_shared +#include // for char_traits, basic_string, operator>>, stoi, string /** * @namespace data_structures diff --git a/data_structures/list_array.cpp b/data_structures/list_array.cpp index 8995b6ce2e1..0660d4b08c8 100644 --- a/data_structures/list_array.cpp +++ b/data_structures/list_array.cpp @@ -14,10 +14,11 @@ * and print the list. */ -#include /// for std::array -#include /// for assert -#include /// for integral typedefs -#include /// for io operations +#include // for array +#include // for assert +#include // for uint64_t +#include // for operator<<, basic_ostream::operator<<, basic_ost... +#include // for swap /** * @namespace data_structures diff --git a/data_structures/morrisinorder.cpp b/data_structures/morrisinorder.cpp index f1f9e068c9f..ae70bc1e74f 100644 --- a/data_structures/morrisinorder.cpp +++ b/data_structures/morrisinorder.cpp @@ -1,5 +1,6 @@ -#include -#include +#include // for NULL +#include // for char_traits, operator<<, basic_ostream, basic_os... +#include // for queue /************************** @author shrutisheoran diff --git a/data_structures/queue_using_array.cpp b/data_structures/queue_using_array.cpp index cbd84a62397..5afd4701171 100644 --- a/data_structures/queue_using_array.cpp +++ b/data_structures/queue_using_array.cpp @@ -17,9 +17,10 @@ * @author [Pooja](https://github.com/pooja-git11) * @author [Farbod Ahmadian](https://github.com/farbodahm) */ -#include /// for std::array -#include /// for integral typedefs -#include /// for io operations +#include // for exit +#include // for array +#include // for int16_t, int8_t, uint16_t +#include // for operator<<, basic_ostream, cout, char_traits constexpr uint16_t max_size{10}; ///< Maximum size of the queue diff --git a/data_structures/queue_using_linked_list.cpp b/data_structures/queue_using_linked_list.cpp index 7b44d240c74..39eae2895c7 100644 --- a/data_structures/queue_using_linked_list.cpp +++ b/data_structures/queue_using_linked_list.cpp @@ -1,4 +1,6 @@ -#include +#include // for NULL +#include // for operator<<, basic_ostream, char_traits, cout + using namespace std; struct node { diff --git a/data_structures/queue_using_linkedlist.cpp b/data_structures/queue_using_linkedlist.cpp index f1bf18123f9..d487cf7d342 100644 --- a/data_structures/queue_using_linkedlist.cpp +++ b/data_structures/queue_using_linkedlist.cpp @@ -1,7 +1,8 @@ /* Write a program to implement Queue using linkedlist. */ -#include +#include // for NULL, exit +#include // for operator<<, basic_ostream, cout, char_traits struct linkedlist { int data; diff --git a/data_structures/queue_using_two_stacks.cpp b/data_structures/queue_using_two_stacks.cpp index a096446865a..117f5b2c416 100644 --- a/data_structures/queue_using_two_stacks.cpp +++ b/data_structures/queue_using_two_stacks.cpp @@ -5,9 +5,10 @@ * Implementation of a Queue using two Stacks. */ -#include -#include -#include +#include // for exit +#include // for assert +#include // for operator<<, basic_ostream, char_traits, cout, cerr +#include // for stack namespace { /** diff --git a/data_structures/rb_tree.cpp b/data_structures/rb_tree.cpp index f2a51a30c20..cda06d63939 100644 --- a/data_structures/rb_tree.cpp +++ b/data_structures/rb_tree.cpp @@ -1,505 +1,431 @@ -#include +#include // for NULL +#include using namespace std; -struct node -{ - int key; - node *parent; - char color; - node *left; - node *right; +struct node { + int key; + node *parent; + char color; + node *left; + node *right; }; -class RBtree -{ - node *root; - node *q; -public: - RBtree() - { - q = NULL; - root = NULL; - } - void insert(); - void insertfix(node *); - void leftrotate(node *); - void rightrotate(node *); - void del(); - node* successor(node *); - void delfix(node *); - void disp(); - void display(node *); - void search(); +class RBtree { + node *root; + node *q; + + public: + RBtree() { + q = NULL; + root = NULL; + } + void insert(); + void insertfix(node *); + void leftrotate(node *); + void rightrotate(node *); + void del(); + node *successor(node *); + void delfix(node *); + void disp(); + void display(node *); + void search(); }; -void RBtree::insert() -{ - int z, i = 0; - cout << "\nEnter key of the node to be inserted: "; - cin >> z; - node *p, *q; - node *t = new node; - t->key = z; - t->left = NULL; - t->right = NULL; - t->color = 'r'; - p = root; - q = NULL; - if (root == NULL) - { - root = t; - t->parent = NULL; - } - else - { - while (p != NULL) - { - q = p; - if (p->key < t->key) - p = p->right; - else - p = p->left; - } - t->parent = q; - if (q->key < t->key) - q->right = t; - else - q->left = t; - } - insertfix(t); +void RBtree::insert() { + int z, i = 0; + cout << "\nEnter key of the node to be inserted: "; + cin >> z; + node *p, *q; + node *t = new node; + t->key = z; + t->left = NULL; + t->right = NULL; + t->color = 'r'; + p = root; + q = NULL; + if (root == NULL) { + root = t; + t->parent = NULL; + } else { + while (p != NULL) { + q = p; + if (p->key < t->key) + p = p->right; + else + p = p->left; + } + t->parent = q; + if (q->key < t->key) + q->right = t; + else + q->left = t; + } + insertfix(t); } -void RBtree::insertfix(node *t) -{ - node *u; - if (root == t) - { - t->color = 'b'; - return; - } - while (t->parent != NULL && t->parent->color == 'r') - { - node *g = t->parent->parent; - if (g->left == t->parent) - { - if (g->right != NULL) - { - u = g->right; - if (u->color == 'r') - { - t->parent->color = 'b'; - u->color = 'b'; - g->color = 'r'; - t = g; - } - } - else - { - if (t->parent->right == t) - { - t = t->parent; - leftrotate(t); - } - t->parent->color = 'b'; - g->color = 'r'; - rightrotate(g); - } - } - else - { - if (g->left != NULL) - { - u = g->left; - if (u->color == 'r') - { - t->parent->color = 'b'; - u->color = 'b'; - g->color = 'r'; - t = g; - } - } - else - { - if (t->parent->left == t) - { - t = t->parent; - rightrotate(t); - } - t->parent->color = 'b'; - g->color = 'r'; - leftrotate(g); - } - } - root->color = 'b'; - } +void RBtree::insertfix(node *t) { + node *u; + if (root == t) { + t->color = 'b'; + return; + } + while (t->parent != NULL && t->parent->color == 'r') { + node *g = t->parent->parent; + if (g->left == t->parent) { + if (g->right != NULL) { + u = g->right; + if (u->color == 'r') { + t->parent->color = 'b'; + u->color = 'b'; + g->color = 'r'; + t = g; + } + } else { + if (t->parent->right == t) { + t = t->parent; + leftrotate(t); + } + t->parent->color = 'b'; + g->color = 'r'; + rightrotate(g); + } + } else { + if (g->left != NULL) { + u = g->left; + if (u->color == 'r') { + t->parent->color = 'b'; + u->color = 'b'; + g->color = 'r'; + t = g; + } + } else { + if (t->parent->left == t) { + t = t->parent; + rightrotate(t); + } + t->parent->color = 'b'; + g->color = 'r'; + leftrotate(g); + } + } + root->color = 'b'; + } } -void RBtree::del() -{ - if (root == NULL) - { - cout << "\nEmpty Tree."; - return; - } - int x; - cout << "\nEnter the key of the node to be deleted: "; - cin >> x; - node *p; - p = root; - node *y = NULL; - node *q = NULL; - int found = 0; - while (p != NULL && found == 0) - { - if (p->key == x) - found = 1; - if (found == 0) - { - if (p->key < x) - p = p->right; - else - p = p->left; - } - } - if (found == 0) - { - cout << "\nElement Not Found."; - return; - } - else - { - cout << "\nDeleted Element: " << p->key; - cout << "\nColour: "; - if (p->color == 'b') - cout << "Black\n"; - else - cout << "Red\n"; +void RBtree::del() { + if (root == NULL) { + cout << "\nEmpty Tree."; + return; + } + int x; + cout << "\nEnter the key of the node to be deleted: "; + cin >> x; + node *p; + p = root; + node *y = NULL; + node *q = NULL; + int found = 0; + while (p != NULL && found == 0) { + if (p->key == x) + found = 1; + if (found == 0) { + if (p->key < x) + p = p->right; + else + p = p->left; + } + } + if (found == 0) { + cout << "\nElement Not Found."; + return; + } else { + cout << "\nDeleted Element: " << p->key; + cout << "\nColour: "; + if (p->color == 'b') + cout << "Black\n"; + else + cout << "Red\n"; - if (p->parent != NULL) - cout << "\nParent: " << p->parent->key; - else - cout << "\nThere is no parent of the node. "; - if (p->right != NULL) - cout << "\nRight Child: " << p->right->key; - else - cout << "\nThere is no right child of the node. "; - if (p->left != NULL) - cout << "\nLeft Child: " << p->left->key; - else - cout << "\nThere is no left child of the node. "; - cout << "\nNode Deleted."; - if (p->left == NULL || p->right == NULL) - y = p; - else - y = successor(p); - if (y->left != NULL) - q = y->left; - else - { - if (y->right != NULL) - q = y->right; - else - q = NULL; - } - if (q != NULL) - q->parent = y->parent; - if (y->parent == NULL) - root = q; - else - { - if (y == y->parent->left) - y->parent->left = q; - else - y->parent->right = q; - } - if (y != p) - { - p->color = y->color; - p->key = y->key; - } - if (y->color == 'b') - delfix(q); - } + if (p->parent != NULL) + cout << "\nParent: " << p->parent->key; + else + cout << "\nThere is no parent of the node. "; + if (p->right != NULL) + cout << "\nRight Child: " << p->right->key; + else + cout << "\nThere is no right child of the node. "; + if (p->left != NULL) + cout << "\nLeft Child: " << p->left->key; + else + cout << "\nThere is no left child of the node. "; + cout << "\nNode Deleted."; + if (p->left == NULL || p->right == NULL) + y = p; + else + y = successor(p); + if (y->left != NULL) + q = y->left; + else { + if (y->right != NULL) + q = y->right; + else + q = NULL; + } + if (q != NULL) + q->parent = y->parent; + if (y->parent == NULL) + root = q; + else { + if (y == y->parent->left) + y->parent->left = q; + else + y->parent->right = q; + } + if (y != p) { + p->color = y->color; + p->key = y->key; + } + if (y->color == 'b') + delfix(q); + } } -void RBtree::delfix(node *p) -{ - node *s; - while (p != root && p->color == 'b') - { - if (p->parent->left == p) - { - s = p->parent->right; - if (s->color == 'r') - { - s->color = 'b'; - p->parent->color = 'r'; - leftrotate(p->parent); - s = p->parent->right; - } - if (s->right->color == 'b'&&s->left->color == 'b') - { - s->color = 'r'; - p = p->parent; - } - else - { - if (s->right->color == 'b') - { - s->left->color = 'b'; - s->color = 'r'; - rightrotate(s); - s = p->parent->right; - } - s->color = p->parent->color; - p->parent->color = 'b'; - s->right->color = 'b'; - leftrotate(p->parent); - p = root; - } - } - else - { - s = p->parent->left; - if (s->color == 'r') - { - s->color = 'b'; - p->parent->color = 'r'; - rightrotate(p->parent); - s = p->parent->left; - } - if (s->left->color == 'b'&&s->right->color == 'b') - { - s->color = 'r'; - p = p->parent; - } - else - { - if (s->left->color == 'b') - { - s->right->color = 'b'; - s->color = 'r'; - leftrotate(s); - s = p->parent->left; - } - s->color = p->parent->color; - p->parent->color = 'b'; - s->left->color = 'b'; - rightrotate(p->parent); - p = root; - } - } - p->color = 'b'; - root->color = 'b'; - } +void RBtree::delfix(node *p) { + node *s; + while (p != root && p->color == 'b') { + if (p->parent->left == p) { + s = p->parent->right; + if (s->color == 'r') { + s->color = 'b'; + p->parent->color = 'r'; + leftrotate(p->parent); + s = p->parent->right; + } + if (s->right->color == 'b' && s->left->color == 'b') { + s->color = 'r'; + p = p->parent; + } else { + if (s->right->color == 'b') { + s->left->color = 'b'; + s->color = 'r'; + rightrotate(s); + s = p->parent->right; + } + s->color = p->parent->color; + p->parent->color = 'b'; + s->right->color = 'b'; + leftrotate(p->parent); + p = root; + } + } else { + s = p->parent->left; + if (s->color == 'r') { + s->color = 'b'; + p->parent->color = 'r'; + rightrotate(p->parent); + s = p->parent->left; + } + if (s->left->color == 'b' && s->right->color == 'b') { + s->color = 'r'; + p = p->parent; + } else { + if (s->left->color == 'b') { + s->right->color = 'b'; + s->color = 'r'; + leftrotate(s); + s = p->parent->left; + } + s->color = p->parent->color; + p->parent->color = 'b'; + s->left->color = 'b'; + rightrotate(p->parent); + p = root; + } + } + p->color = 'b'; + root->color = 'b'; + } } -void RBtree::leftrotate(node *p) -{ - if (p->right == NULL) - return; - else - { - node *y = p->right; - if (y->left != NULL) - { - p->right = y->left; - y->left->parent = p; - } - else - p->right = NULL; - if (p->parent != NULL) - y->parent = p->parent; - if (p->parent == NULL) - root = y; - else - { - if (p == p->parent->left) - p->parent->left = y; - else - p->parent->right = y; - } - y->left = p; - p->parent = y; - } +void RBtree::leftrotate(node *p) { + if (p->right == NULL) + return; + else { + node *y = p->right; + if (y->left != NULL) { + p->right = y->left; + y->left->parent = p; + } else + p->right = NULL; + if (p->parent != NULL) + y->parent = p->parent; + if (p->parent == NULL) + root = y; + else { + if (p == p->parent->left) + p->parent->left = y; + else + p->parent->right = y; + } + y->left = p; + p->parent = y; + } } -void RBtree::rightrotate(node *p) -{ - if (p->left == NULL) - return; - else - { - node *y = p->left; - if (y->right != NULL) - { - p->left = y->right; - y->right->parent = p; - } - else - p->left = NULL; - if (p->parent != NULL) - y->parent = p->parent; - if (p->parent == NULL) - root = y; - else - { - if (p == p->parent->left) - p->parent->left = y; - else - p->parent->right = y; - } - y->right = p; - p->parent = y; - } +void RBtree::rightrotate(node *p) { + if (p->left == NULL) + return; + else { + node *y = p->left; + if (y->right != NULL) { + p->left = y->right; + y->right->parent = p; + } else + p->left = NULL; + if (p->parent != NULL) + y->parent = p->parent; + if (p->parent == NULL) + root = y; + else { + if (p == p->parent->left) + p->parent->left = y; + else + p->parent->right = y; + } + y->right = p; + p->parent = y; + } } -node* RBtree::successor(node *p) -{ - node *y = NULL; - if (p->left != NULL) - { - y = p->left; - while (y->right != NULL) - y = y->right; - } - else - { - y = p->right; - while (y->left != NULL) - y = y->left; - } - return y; +node *RBtree::successor(node *p) { + node *y = NULL; + if (p->left != NULL) { + y = p->left; + while (y->right != NULL) y = y->right; + } else { + y = p->right; + while (y->left != NULL) y = y->left; + } + return y; } -void RBtree::disp() -{ - display(root); -} -void RBtree::display(node *p) -{ - if (root == NULL) - { - cout << "\nEmpty Tree."; - return; - } - if (p != NULL) - { - cout << "\n\t NODE: "; - cout << "\n Key: " << p->key; - cout << "\n Colour: "; - if (p->color == 'b') - cout << "Black"; - else - cout << "Red"; - if (p->parent != NULL) - cout << "\n Parent: " << p->parent->key; - else - cout << "\n There is no parent of the node. "; - if (p->right != NULL) - cout << "\n Right Child: " << p->right->key; - else - cout << "\n There is no right child of the node. "; - if (p->left != NULL) - cout << "\n Left Child: " << p->left->key; - else - cout << "\n There is no left child of the node. "; - cout << endl; - if (p->left) - { - cout << "\n\nLeft:\n"; - display(p->left); - } - /*else - cout<<"\nNo Left Child.\n";*/ - if (p->right) - { - cout << "\n\nRight:\n"; - display(p->right); - } - /*else - cout<<"\nNo Right Child.\n"*/ - } +void RBtree::disp() { display(root); } +void RBtree::display(node *p) { + if (root == NULL) { + cout << "\nEmpty Tree."; + return; + } + if (p != NULL) { + cout << "\n\t NODE: "; + cout << "\n Key: " << p->key; + cout << "\n Colour: "; + if (p->color == 'b') + cout << "Black"; + else + cout << "Red"; + if (p->parent != NULL) + cout << "\n Parent: " << p->parent->key; + else + cout << "\n There is no parent of the node. "; + if (p->right != NULL) + cout << "\n Right Child: " << p->right->key; + else + cout << "\n There is no right child of the node. "; + if (p->left != NULL) + cout << "\n Left Child: " << p->left->key; + else + cout << "\n There is no left child of the node. "; + cout << endl; + if (p->left) { + cout << "\n\nLeft:\n"; + display(p->left); + } + /*else + cout<<"\nNo Left Child.\n";*/ + if (p->right) { + cout << "\n\nRight:\n"; + display(p->right); + } + /*else + cout<<"\nNo Right Child.\n"*/ + } } -void RBtree::search() -{ - if (root == NULL) - { - cout << "\nEmpty Tree\n"; - return; - } - int x; - cout << "\n Enter key of the node to be searched: "; - cin >> x; - node *p = root; - int found = 0; - while (p != NULL && found == 0) - { - if (p->key == x) - found = 1; - if (found == 0) - { - if (p->key < x) - p = p->right; - else - p = p->left; - } - } - if (found == 0) - cout << "\nElement Not Found."; - else - { - cout << "\n\t FOUND NODE: "; - cout << "\n Key: " << p->key; - cout << "\n Colour: "; - if (p->color == 'b') - cout << "Black"; - else - cout << "Red"; - if (p->parent != NULL) - cout << "\n Parent: " << p->parent->key; - else - cout << "\n There is no parent of the node. "; - if (p->right != NULL) - cout << "\n Right Child: " << p->right->key; - else - cout << "\n There is no right child of the node. "; - if (p->left != NULL) - cout << "\n Left Child: " << p->left->key; - else - cout << "\n There is no left child of the node. "; - cout << endl; - - } +void RBtree::search() { + if (root == NULL) { + cout << "\nEmpty Tree\n"; + return; + } + int x; + cout << "\n Enter key of the node to be searched: "; + cin >> x; + node *p = root; + int found = 0; + while (p != NULL && found == 0) { + if (p->key == x) + found = 1; + if (found == 0) { + if (p->key < x) + p = p->right; + else + p = p->left; + } + } + if (found == 0) + cout << "\nElement Not Found."; + else { + cout << "\n\t FOUND NODE: "; + cout << "\n Key: " << p->key; + cout << "\n Colour: "; + if (p->color == 'b') + cout << "Black"; + else + cout << "Red"; + if (p->parent != NULL) + cout << "\n Parent: " << p->parent->key; + else + cout << "\n There is no parent of the node. "; + if (p->right != NULL) + cout << "\n Right Child: " << p->right->key; + else + cout << "\n There is no right child of the node. "; + if (p->left != NULL) + cout << "\n Left Child: " << p->left->key; + else + cout << "\n There is no left child of the node. "; + cout << endl; + } } -int main() -{ - int ch, y = 0; - RBtree obj; - do - { - cout << "\n\t RED BLACK TREE "; - cout << "\n 1. Insert in the tree "; - cout << "\n 2. Delete a node from the tree"; - cout << "\n 3. Search for an element in the tree"; - cout << "\n 4. Display the tree "; - cout << "\n 5. Exit "; - cout << "\nEnter Your Choice: "; - cin >> ch; - switch (ch) - { - case 1: obj.insert(); - cout << "\nNode Inserted.\n"; - break; - case 2: obj.del(); - break; - case 3: obj.search(); - break; - case 4: obj.disp(); - break; - case 5: y = 1; - break; - default: cout << "\nEnter a Valid Choice."; - } - cout << endl; +int main() { + int ch, y = 0; + RBtree obj; + do { + cout << "\n\t RED BLACK TREE "; + cout << "\n 1. Insert in the tree "; + cout << "\n 2. Delete a node from the tree"; + cout << "\n 3. Search for an element in the tree"; + cout << "\n 4. Display the tree "; + cout << "\n 5. Exit "; + cout << "\nEnter Your Choice: "; + cin >> ch; + switch (ch) { + case 1: + obj.insert(); + cout << "\nNode Inserted.\n"; + break; + case 2: + obj.del(); + break; + case 3: + obj.search(); + break; + case 4: + obj.disp(); + break; + case 5: + y = 1; + break; + default: + cout << "\nEnter a Valid Choice."; + } + cout << endl; - } while (y != 1); - return 1; + } while (y != 1); + return 1; } diff --git a/data_structures/reverse_a_linked_list.cpp b/data_structures/reverse_a_linked_list.cpp index d8315b4bb47..d776c83bfc2 100644 --- a/data_structures/reverse_a_linked_list.cpp +++ b/data_structures/reverse_a_linked_list.cpp @@ -22,9 +22,12 @@ *scenes](https://drive.google.com/file/d/1pM5COF0wx-wermnNy_svtyZquaCUP2xS/view?usp=sharing) */ -#include /// for assert -#include /// for I/O operations -#include /// for managing dynamic storage +#include // for int32_t +#include // for exit +#include // for assert +#include // for char_traits, basic_ostream, operator<<, cerr, cout +#include // for bad_alloc +#include // for logic_error /** * @namespace data_structures diff --git a/data_structures/skip_list.cpp b/data_structures/skip_list.cpp index 9cf8c430f4a..bac77da2c9b 100644 --- a/data_structures/skip_list.cpp +++ b/data_structures/skip_list.cpp @@ -13,12 +13,12 @@ * @author [Krishna Vedala](https://github.com/kvedala) */ -#include -#include -#include -#include -#include -#include +#include // for array +#include // for time +#include // for basic_ostream, operator<<, char_traits, cout +#include // for shared_ptr, __shared_ptr_access, operator!=, ope... +#include // for vector +#include // for rand, srand, RAND_MAX /** \namespace data_structures * \brief Data-structure algorithms diff --git a/data_structures/sparse_table.cpp b/data_structures/sparse_table.cpp index 507dd39449d..654c81d6ede 100644 --- a/data_structures/sparse_table.cpp +++ b/data_structures/sparse_table.cpp @@ -22,10 +22,13 @@ * `gcd()`, `lcm()`, and `max()` by changing a few lines of code. */ -#include /// for std::array -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations +#include // for copy +#include // for array +#include // for assert +#include // for size_t +#include // for int64_t, uint32_t, uint8_t +#include // for char_traits, basic_ostream, operator<<, cout, endl +#include // for begin, end /** * @namespace data_structures diff --git a/data_structures/stack_using_array.cpp b/data_structures/stack_using_array.cpp index 73feaf445cc..bda5ff0f267 100644 --- a/data_structures/stack_using_array.cpp +++ b/data_structures/stack_using_array.cpp @@ -1,7 +1,8 @@ -#include /// For std::assert -#include /// For std::cout -#include /// For std::unique_ptr -#include /// For std::out_of_range +#include // for assert +#include // for char_traits, basic_ostream, cout, operator<<, endl +#include // for unique_ptr +#include // for out_of_range +#include // for basic_string, operator==, string /** * @namespace diff --git a/data_structures/stack_using_queue.cpp b/data_structures/stack_using_queue.cpp index 7867d55caa0..0bf69170dee 100644 --- a/data_structures/stack_using_queue.cpp +++ b/data_structures/stack_using_queue.cpp @@ -8,10 +8,9 @@ * [StudyTonight](https://www.studytonight.com/data-structures/stack-using-queue) * @author [tushar2407](https://github.com/tushar2407) */ -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations -#include /// for queue data structure +#include // for assert +#include // for int64_t, uint32_t +#include // for queue, swap /** * @namespace data_structures diff --git a/data_structures/test_queue.cpp b/data_structures/test_queue.cpp index d0fa3502ece..3463f490beb 100644 --- a/data_structures/test_queue.cpp +++ b/data_structures/test_queue.cpp @@ -1,7 +1,10 @@ -#include /// for assert -#include /// for std::cout +#include // for assert +#include // for operator<<, basic_ostream, cout +#include // for operator== +#include // for invalid_argument +#include // for vector, operator== -#include "./queue.hpp" +#include "./queue.hpp" // for queue template void testConstructedQueueIsEmpty() { diff --git a/data_structures/test_stack.cpp b/data_structures/test_stack.cpp index 81039e7962c..551261ac8cf 100644 --- a/data_structures/test_stack.cpp +++ b/data_structures/test_stack.cpp @@ -1,9 +1,10 @@ -#include /// for assert -#include /// for std::cout -#include /// std::invalid_argument -#include /// for std::vector +#include // for assert +#include // for operator<<, basic_ostream, cout +#include // for invalid_argument +#include // for vector, operator== +#include // for operator== -#include "./stack.hpp" +#include "./stack.hpp" // for stack template void testConstructedStackIsEmpty() { diff --git a/data_structures/test_stack_students.cpp b/data_structures/test_stack_students.cpp index dc3514bcb1b..2b2b275bc9b 100644 --- a/data_structures/test_stack_students.cpp +++ b/data_structures/test_stack_students.cpp @@ -8,14 +8,15 @@ * ./main student.txt ************************************************************ * */ -#include -#include -#include -#include -#include -#include +#include // for assert +#include // for NAN +#include // for basic_ostream, basic_ifstream, basic_istream +#include // for operator<<, setprecision, _Setprecision +#include // for cout +#include // for char_traits, operator>>, basic_string, operat... +#include // for operator== -#include "./stack.hpp" +#include "./stack.hpp" // for stack int main(int argc, char* argv[]) { double GPA = NAN; diff --git a/data_structures/treap.cpp b/data_structures/treap.cpp index 5be3b241643..8170fa6c1de 100644 --- a/data_structures/treap.cpp +++ b/data_structures/treap.cpp @@ -17,10 +17,11 @@ * @author [Kairao ZHENG](https://github.com/fgmn) */ -#include /// For array -#include /// For assert -#include /// for integral typedefs -#include /// For IO operations +#include // for rand +#include // for array +#include // for assert +#include // for INT32_MAX +#include // for operator<<, basic_ostream, cout /** * @namespace diff --git a/data_structures/tree.cpp b/data_structures/tree.cpp index f46c31ff22a..980709bab98 100644 --- a/data_structures/tree.cpp +++ b/data_structures/tree.cpp @@ -1,5 +1,7 @@ -#include -#include +#include // for NULL +#include // for operator<<, basic_ostream, char_traits, cout +#include // for list + using namespace std; struct node { @@ -90,30 +92,30 @@ int main() { cout << "\nEnter Your Choice : "; cin >> ch; switch (ch) { - case 1: - int x; - char pos; - cout << "\nEnter the value to be Inserted : "; - cin >> x; - cout << "\nLeft or Right of Root : "; - cin >> pos; - if (pos == 'l') - CreateTree(root, root->left, x, pos); - else if (pos == 'r') - CreateTree(root, root->right, x, pos); - break; - case 2: - BFT(root); - break; - case 3: - Pre(root); - break; - case 4: - In(root); - break; - case 5: - Post(root); - break; + case 1: + int x; + char pos; + cout << "\nEnter the value to be Inserted : "; + cin >> x; + cout << "\nLeft or Right of Root : "; + cin >> pos; + if (pos == 'l') + CreateTree(root, root->left, x, pos); + else if (pos == 'r') + CreateTree(root, root->right, x, pos); + break; + case 2: + BFT(root); + break; + case 3: + Pre(root); + break; + case 4: + In(root); + break; + case 5: + Post(root); + break; } } while (ch != 0); } diff --git a/data_structures/tree_234.cpp b/data_structures/tree_234.cpp index 46de03bfaef..e87b42191b6 100644 --- a/data_structures/tree_234.cpp +++ b/data_structures/tree_234.cpp @@ -13,13 +13,14 @@ Introduction](https://www.educative.io/page/5689413791121408/80001) * Other operations should be easy to be added. * @author [liuhuan](https://github.com/fedom) */ -#include /// for std::array -#include /// for assert -#include /// for std::ofstream -#include /// for std::cout -#include /// for std::unique_ptr -#include /// for std::queue -#include /// for std::to_string +#include // for int64_t, int8_t, int16_t +#include // for array +#include // for assert +#include // for basic_ostream, operator<<, basic_ofstream, ofstream +#include // for cout +#include // for allocator, unique_ptr +#include // for queue +#include // for char_traits, basic_string, operator+, stoi, to_s... /** * @namespace data_structures diff --git a/data_structures/trie_modern.cpp b/data_structures/trie_modern.cpp index 470af07a456..b0da638e8d8 100644 --- a/data_structures/trie_modern.cpp +++ b/data_structures/trie_modern.cpp @@ -4,9 +4,12 @@ * @author Anmol3299 * \brief A basic implementation of trie class to store only lower-case strings. */ -#include // for io operations -#include // for std::shared_ptr<> -#include // for std::string class +#include // for size_t +#include // for basic_ostream, operator<<, cout +#include // for shared_ptr, __shared_ptr_access, make_shared +#include // for runtime_error +#include // for basic_string, char_traits, string +#include // for move /** * A basic implementation of trie class to store only lower-case strings. diff --git a/data_structures/trie_tree.cpp b/data_structures/trie_tree.cpp index e966b2dfde2..1c852f21060 100644 --- a/data_structures/trie_tree.cpp +++ b/data_structures/trie_tree.cpp @@ -7,12 +7,13 @@ * @note the function ::data_structure::trie::deleteString might be erroneous * @see trie_modern.cpp */ -#include -#include -#include -#include -#include -#include +#include // for uint8_t +#include // for array +#include // for assert +#include // for operator<<, basic_ostream, cout, basic_ostream::... +#include // for shared_ptr, __shared_ptr_access +#include // for char_traits, basic_string, string +#include // for exit, EXIT_FAILURE /** \namespace data_structures * \brief Data-structure algorithms diff --git a/data_structures/trie_using_hashmap.cpp b/data_structures/trie_using_hashmap.cpp index 5fb9602a9bb..b043720fd01 100644 --- a/data_structures/trie_using_hashmap.cpp +++ b/data_structures/trie_using_hashmap.cpp @@ -10,12 +10,14 @@ * in trie. * @see trie_modern.cpp for difference */ -#include /// for assert -#include /// for IO operations -#include /// for std::shared_ptr -#include /// for std::stack -#include /// for std::unordered_map -#include /// for std::vector +#include // for assert +#include // for basic_ostream, operator<<, char_traits, cout +#include // for shared_ptr, __shared_ptr_access, make_shared +#include // for stack +#include // for unordered_map, operator==, _Node_iterator_base +#include // for vector +#include // for basic_string, string, operator<< +#include // for pair /** * @namespace data_structures From 16ee49e0868d28d7c5fbefaf86d8e5a2b1c7cd7d Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:38:00 +0530 Subject: [PATCH 041/131] chore: use iwyu on divide_and_conquer/**.cpp --- .../karatsuba_algorithm_for_fast_multiplication.cpp | 9 +++++---- .../strassen_matrix_multiplication.cpp | 13 ++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/divide_and_conquer/karatsuba_algorithm_for_fast_multiplication.cpp b/divide_and_conquer/karatsuba_algorithm_for_fast_multiplication.cpp index 1d9bd86cdda..7cbab23f565 100644 --- a/divide_and_conquer/karatsuba_algorithm_for_fast_multiplication.cpp +++ b/divide_and_conquer/karatsuba_algorithm_for_fast_multiplication.cpp @@ -12,10 +12,11 @@ * @author [Ameer Carlo Lubang](https://github.com/poypoyan) */ -#include /// for assert -#include /// for string -#include /// for IO operations -#include /// for std::vector +#include // for int64_t +#include // for assert +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for max +#include // for basic_string, string /** * @namespace divide_and_conquer diff --git a/divide_and_conquer/strassen_matrix_multiplication.cpp b/divide_and_conquer/strassen_matrix_multiplication.cpp index 47498c966b1..75b727d7293 100644 --- a/divide_and_conquer/strassen_matrix_multiplication.cpp +++ b/divide_and_conquer/strassen_matrix_multiplication.cpp @@ -10,11 +10,14 @@ * * @author [AshishYUO](https://github.com/AshishYUO) */ -#include /// For assert operation -#include /// For std::chrono; time measurement -#include /// For I/O operations -#include /// For std::tuple -#include /// For creating dynamic arrays +#include // for duration, operator-, system_clock, time_point + +#include // for assert +#include // for size_t +#include // for char_traits, basic_ostream, operator<<, cout +#include // for enable_if, is_integral, is_floating_point +#include // for operator==, pair +#include // for vector /** * @namespace divide_and_conquer From 740bd65932f7db3e94b2f541b7eb3b9859be61c9 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:38:11 +0530 Subject: [PATCH 042/131] chore: use iwyu on geometry/**.cpp --- geometry/line_segment_intersection.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/geometry/line_segment_intersection.cpp b/geometry/line_segment_intersection.cpp index d523ae0a413..c6a6bdacc07 100644 --- a/geometry/line_segment_intersection.cpp +++ b/geometry/line_segment_intersection.cpp @@ -3,8 +3,9 @@ * @brief check whether two line segments intersect each other * or not. */ -#include -#include +#include // for printf +#include // for max, min +#include // for basic_istream::operator>>, char_traits, basic_i... /** * Define a Point. From dabd6d2591d2feeefec2aa512fdcfd335e600606 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:38:23 +0530 Subject: [PATCH 043/131] chore: use iwyu on graph/**.cpp --- graph/bidirectional_dijkstra.cpp | 15 +- graph/breadth_first_search.cpp | 16 +- graph/connected_components.cpp | 7 +- graph/connected_components_with_dsu.cpp | 9 +- graph/cycle_check_directed_graph.cpp | 17 +- graph/depth_first_search.cpp | 6 +- graph/depth_first_search_with_stack.cpp | 169 +++++++++--------- graph/dijkstra.cpp | 15 +- graph/hamiltons_cycle.cpp | 7 +- graph/hopcroft_karp.cpp | 13 +- graph/kruskal.cpp | 11 +- graph/lowest_common_ancestor.cpp | 10 +- ...th_ford_fulkerson_and_edmond_karp_algo.cpp | 17 +- graph/prim.cpp | 8 +- graph/topological_sort_by_kahns_algo.cpp | 8 +- graph/travelling_salesman_problem.cpp | 11 +- 16 files changed, 176 insertions(+), 163 deletions(-) diff --git a/graph/bidirectional_dijkstra.cpp b/graph/bidirectional_dijkstra.cpp index 5f6d369287c..b524e9371aa 100644 --- a/graph/bidirectional_dijkstra.cpp +++ b/graph/bidirectional_dijkstra.cpp @@ -13,13 +13,14 @@ * https://www.youtube.com/watch?v=DINCL5cd_w0&t=24s */ -#include /// for assert -#include /// for integral typedefs -#include /// for io operations -#include /// for variable INF -#include /// for the priority_queue of distances -#include /// for make_pair function -#include /// for store the graph, the distances, and the path +#include // for assert +#include // for uint64_t, int64_t +#include // for basic_ostream, operator<<, char_traits, cout +#include // for numeric_limits +#include // for priority_queue +#include // for pair, make_pair +#include // for vector +#include // for greater constexpr int64_t INF = std::numeric_limits::max(); diff --git a/graph/breadth_first_search.cpp b/graph/breadth_first_search.cpp index 4bc58f34212..d9f25f5b2b0 100644 --- a/graph/breadth_first_search.cpp +++ b/graph/breadth_first_search.cpp @@ -45,14 +45,14 @@ * push that element into the queue and mark this as visited * */ -#include -#include -#include -#include -#include -#include -#include -#include +#include // for assert +#include // for size_t +#include // for less +#include // for basic_ostream, operator<<, cout, basic_istream... +#include // for list +#include // for map, operator== +#include // for queue +#include // for basic_string, operator<, char_traits, allocator /** * \namespace graph diff --git a/graph/connected_components.cpp b/graph/connected_components.cpp index 06bb1ee505e..0a80a95b9d1 100644 --- a/graph/connected_components.cpp +++ b/graph/connected_components.cpp @@ -25,10 +25,9 @@ * */ -#include -#include -#include -#include +#include // for assert +#include // for basic_ostream, char_traits, operator<<, basic_is... +#include // for vector /** * @namespace graph diff --git a/graph/connected_components_with_dsu.cpp b/graph/connected_components_with_dsu.cpp index 72c4f34fe2b..38452f1c502 100644 --- a/graph/connected_components_with_dsu.cpp +++ b/graph/connected_components_with_dsu.cpp @@ -17,10 +17,11 @@ * @author Unknown author * @author [Sagar Pandya](https://github.com/sagarpandyansit) */ -#include /// for integer typedefs -#include /// for IO operations -#include /// for std::set -#include /// for std::vector +#include // for int64_t, uint32_t +#include // for char_traits, basic_istream, cin, basic_ostream +#include // for set +#include // for vector +#include // for swap /** * @namespace graph diff --git a/graph/cycle_check_directed_graph.cpp b/graph/cycle_check_directed_graph.cpp index fbe6063ca96..161e768433f 100644 --- a/graph/cycle_check_directed_graph.cpp +++ b/graph/cycle_check_directed_graph.cpp @@ -7,14 +7,15 @@ * */ -#include /// for integral typedefs -#include // for std::cout -#include // for std::map -#include // for std::queue -#include // for throwing errors -#include // for std::remove_reference -#include // for std::move -#include // for std::vector +#include // for uint8_t +#include // for char_traits, basic_ostream, operator<< +#include // for map, operator!=, _Rb_tree_iterator +#include // for queue +#include // for range_error +#include // for remove_reference +#include // for move, pair +#include // for vector +#include // for initializer_list /** * Implementation of non-weighted directed edge of a graph. diff --git a/graph/depth_first_search.cpp b/graph/depth_first_search.cpp index e99d44fc914..aa6630493a1 100644 --- a/graph/depth_first_search.cpp +++ b/graph/depth_first_search.cpp @@ -32,9 +32,9 @@ * */ -#include -#include -#include +#include // for size_t +#include // for char_traits, basic_ostream, operator<<, cout +#include // for vector /** * diff --git a/graph/depth_first_search_with_stack.cpp b/graph/depth_first_search_with_stack.cpp index 5376ea4c419..e1c9d805fd5 100644 --- a/graph/depth_first_search_with_stack.cpp +++ b/graph/depth_first_search_with_stack.cpp @@ -2,7 +2,8 @@ * * @file * @brief [Depth First Search Algorithm using Stack - * (Depth First Search Algorithm)](https://en.wikipedia.org/wiki/Depth-first_search) + * (Depth First Search + * Algorithm)](https://en.wikipedia.org/wiki/Depth-first_search) * * @author [Ayaan Khan](http://github.com/ayaankhan98) * @author [Saurav Uppoor](https://github.com/sauravUppoor) @@ -24,22 +25,25 @@ *

Working

* 1. Mark all vertices as unvisited (colour it WHITE). * 2. Push starting vertex into the stack and colour it GREY. - * 3. Once a node is popped out of the stack and is coloured GREY, we colour it BLACK. + * 3. Once a node is popped out of the stack and is coloured GREY, we colour it + * BLACK. * 4. Push all its neighbours which are not coloured BLACK. * 5. Repeat steps 4 and 5 until the stack is empty. */ -#include /// for IO operations -#include /// header for std::stack -#include /// header for std::vector -#include /// header for preprocessor macro assert() -#include /// header for limits of integral types +#include // for int16_t, int64_t -constexpr int WHITE = 0; /// indicates the node hasn't been explored -constexpr int GREY = 1; /// indicates node is in stack waiting to be explored -constexpr int BLACK = 2; /// indicates node has already been explored -constexpr int64_t INF = std::numeric_limits::max(); +#include // for assert +#include // for size_t +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for numeric_limits +#include // for stack +#include // for vector, operator== +constexpr int WHITE = 0; /// indicates the node hasn't been explored +constexpr int GREY = 1; /// indicates node is in stack waiting to be explored +constexpr int BLACK = 2; /// indicates node has already been explored +constexpr int64_t INF = std::numeric_limits::max(); /** * @namespace graph @@ -48,7 +52,8 @@ constexpr int64_t INF = std::numeric_limits::max(); namespace graph { /** * @namespace depth_first_search - * @brief Functions for [Depth First Search](https://en.wikipedia.org/wiki/Depth-first_search) algorithm + * @brief Functions for [Depth First + * Search](https://en.wikipedia.org/wiki/Depth-first_search) algorithm */ namespace depth_first_search { /** @@ -62,14 +67,14 @@ namespace depth_first_search { * */ void addEdge(std::vector> *adj, size_t u, size_t v) { - /* - * - * Here we are considering undirected graph that's the - * reason we are adding v to the adjacency list representation of u - * and also adding u to the adjacency list representation of v - * - */ - (*adj)[u - 1].push_back(v - 1); + /* + * + * Here we are considering undirected graph that's the + * reason we are adding v to the adjacency list representation of u + * and also adding u to the adjacency list representation of v + * + */ + (*adj)[u - 1].push_back(v - 1); } /** @@ -84,7 +89,8 @@ void addEdge(std::vector> *adj, size_t u, size_t v) { * @return vector with nodes stored in the order of DFS traversal * */ -std::vector dfs(const std::vector > &graph, size_t start) { +std::vector dfs(const std::vector> &graph, + size_t start) { /// checked[i] stores the status of each node std::vector checked(graph.size(), WHITE), traversed_path; @@ -121,49 +127,51 @@ std::vector dfs(const std::vector > &graph, size_t s * @returns none */ static void tests() { - size_t start_pos; - - /// Test 1 - std::cout << "Case 1: " << std::endl; - start_pos = 1; - std::vector > g1(3, std::vector()); - - graph::depth_first_search::addEdge(&g1, 1, 2); - graph::depth_first_search::addEdge(&g1, 2, 3); - graph::depth_first_search::addEdge(&g1, 3, 1); - - std::vector expected1 {1, 2, 3}; /// for the above sample data, this is the expected output - assert(graph::depth_first_search::dfs(g1, start_pos - 1) == expected1); - std::cout << "Passed" << std::endl; - - /// Test 2 - std::cout << "Case 2: " << std::endl; - start_pos = 1; - std::vector > g2(4, std::vector()); - - graph::depth_first_search::addEdge(&g2, 1, 2); - graph::depth_first_search::addEdge(&g2, 1, 3); - graph::depth_first_search::addEdge(&g2, 2, 4); - graph::depth_first_search::addEdge(&g2, 4, 1); - - std::vector expected2 {1, 3, 2, 4}; /// for the above sample data, this is the expected output - assert(graph::depth_first_search::dfs(g2, start_pos - 1) == expected2); - std::cout << "Passed" << std::endl; - - /// Test 3 - std::cout << "Case 3: " << std::endl; - start_pos = 2; - std::vector > g3(4, std::vector()); - - graph::depth_first_search::addEdge(&g3, 1, 2); - graph::depth_first_search::addEdge(&g3, 1, 3); - graph::depth_first_search::addEdge(&g3, 2, 4); - graph::depth_first_search::addEdge(&g3, 4, 1); - - std::vector expected3 {2, 4, 1, 3}; /// for the above sample data, this is the expected output - assert(graph::depth_first_search::dfs(g3, start_pos - 1) == expected3); - std::cout << "Passed" << std::endl; - + size_t start_pos; + + /// Test 1 + std::cout << "Case 1: " << std::endl; + start_pos = 1; + std::vector> g1(3, std::vector()); + + graph::depth_first_search::addEdge(&g1, 1, 2); + graph::depth_first_search::addEdge(&g1, 2, 3); + graph::depth_first_search::addEdge(&g1, 3, 1); + + std::vector expected1{ + 1, 2, 3}; /// for the above sample data, this is the expected output + assert(graph::depth_first_search::dfs(g1, start_pos - 1) == expected1); + std::cout << "Passed" << std::endl; + + /// Test 2 + std::cout << "Case 2: " << std::endl; + start_pos = 1; + std::vector> g2(4, std::vector()); + + graph::depth_first_search::addEdge(&g2, 1, 2); + graph::depth_first_search::addEdge(&g2, 1, 3); + graph::depth_first_search::addEdge(&g2, 2, 4); + graph::depth_first_search::addEdge(&g2, 4, 1); + + std::vector expected2{ + 1, 3, 2, 4}; /// for the above sample data, this is the expected output + assert(graph::depth_first_search::dfs(g2, start_pos - 1) == expected2); + std::cout << "Passed" << std::endl; + + /// Test 3 + std::cout << "Case 3: " << std::endl; + start_pos = 2; + std::vector> g3(4, std::vector()); + + graph::depth_first_search::addEdge(&g3, 1, 2); + graph::depth_first_search::addEdge(&g3, 1, 3); + graph::depth_first_search::addEdge(&g3, 2, 4); + graph::depth_first_search::addEdge(&g3, 4, 1); + + std::vector expected3{ + 2, 4, 1, 3}; /// for the above sample data, this is the expected output + assert(graph::depth_first_search::dfs(g3, start_pos - 1) == expected3); + std::cout << "Passed" << std::endl; } /** @@ -174,34 +182,35 @@ int main() { tests(); // execute the tests size_t vertices = 0, edges = 0, start_pos = 1; - std::vector traversal; + std::vector traversal; std::cout << "Enter the Vertices : "; - std::cin >> vertices; - std::cout << "Enter the Edges : "; - std::cin >> edges; + std::cin >> vertices; + std::cout << "Enter the Edges : "; + std::cin >> edges; /// creating a graph - std::vector > adj(vertices, std::vector()); + std::vector> adj(vertices, std::vector()); /// taking input for the edges - std::cout << "Enter the vertices which have edges between them : " << std::endl; - while (edges--) { - size_t u = 0, v = 0; - std::cin >> u >> v; - graph::depth_first_search::addEdge(&adj, u, v); - } + std::cout << "Enter the vertices which have edges between them : " + << std::endl; + while (edges--) { + size_t u = 0, v = 0; + std::cin >> u >> v; + graph::depth_first_search::addEdge(&adj, u, v); + } /// taking input for the starting position std::cout << "Enter the starting vertex [1,n]: " << std::endl; - std::cin >> start_pos; - start_pos -= 1; - traversal = graph::depth_first_search::dfs(adj, start_pos); + std::cin >> start_pos; + start_pos -= 1; + traversal = graph::depth_first_search::dfs(adj, start_pos); /// Printing the order of traversal for (auto x : traversal) { - std::cout << x << ' '; - } + std::cout << x << ' '; + } return 0; } diff --git a/graph/dijkstra.cpp b/graph/dijkstra.cpp index a7621456009..a4b7c705adb 100644 --- a/graph/dijkstra.cpp +++ b/graph/dijkstra.cpp @@ -23,13 +23,14 @@ * at the code below to understand in better way. * */ -#include -#include -#include -#include -#include -#include -#include +#include // for int64_t +#include // for assert +#include // for basic_ostream, char_traits, operator<<, basic_... +#include // for numeric_limits +#include // for priority_queue +#include // for pair, make_pair +#include // for vector +#include // for greater constexpr int64_t INF = std::numeric_limits::max(); diff --git a/graph/hamiltons_cycle.cpp b/graph/hamiltons_cycle.cpp index 1506b78d2fc..a646321a60e 100644 --- a/graph/hamiltons_cycle.cpp +++ b/graph/hamiltons_cycle.cpp @@ -15,9 +15,10 @@ * @author [vakhokoto](https://github.com/vakhokoto) * @author [Krishna Vedala](https://github.com/kvedala) */ -#include -#include -#include +#include // for assert +#include // for size_t +#include // for operator<<, basic_ostream, cout +#include // for vector /** * The function determines if there is a hamilton's cycle in the graph diff --git a/graph/hopcroft_karp.cpp b/graph/hopcroft_karp.cpp index d4e002948a7..c5ba5e1b875 100644 --- a/graph/hopcroft_karp.cpp +++ b/graph/hopcroft_karp.cpp @@ -45,13 +45,12 @@ */ -#include -#include -#include -#include -#include -#include -#include +#include // for char_traits, basic_istream::operator>>, basic_is... +#include // for queue +#include // for list, operator!=, _List_iterator +#include // for INT_MAX +#include // for assert +#include // for vector /** * @namespace graph diff --git a/graph/kruskal.cpp b/graph/kruskal.cpp index 39f695cb04d..9cf83d52d42 100644 --- a/graph/kruskal.cpp +++ b/graph/kruskal.cpp @@ -1,7 +1,10 @@ -#include -#include -#include -#include +#include // for int64_t +#include // for sort +#include // for array +#include // for char_traits, basic_istream::operator>>, basic_i... +#include // for vector +#include // for pair, make_pair + //#include // using namespace boost::multiprecision; const int mx = 1e6 + 5; diff --git a/graph/lowest_common_ancestor.cpp b/graph/lowest_common_ancestor.cpp index 7d5ab42b49f..cfb8efbdf99 100644 --- a/graph/lowest_common_ancestor.cpp +++ b/graph/lowest_common_ancestor.cpp @@ -35,11 +35,11 @@ * lowest_common_ancestor(x, y) = lowest_common_ancestor(y, x) */ -#include -#include -#include -#include -#include +#include // for assert +#include // for size_t +#include // for queue +#include // for pair, swap +#include // for vector /** * \namespace graph diff --git a/graph/max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp b/graph/max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp index 20571cdc518..6708c303c24 100644 --- a/graph/max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp +++ b/graph/max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp @@ -4,15 +4,14 @@ * Copyright: 2020, Open-Source * Last Modified: May 25, 2020 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include // for min +#include // for bitset +#include // for char_traits, basic_ostream, operator<<, basic_i... +#include // for numeric_limits +#include // for queue +#include // for tuple, make_tuple, tie +#include // for vector + // std::max capacity of node in graph const int MAXN = 505; class Graph { diff --git a/graph/prim.cpp b/graph/prim.cpp index f1def6161d9..9e56dba65f0 100644 --- a/graph/prim.cpp +++ b/graph/prim.cpp @@ -1,7 +1,9 @@ // C++ program to implement Prim's Algorithm -#include -#include -#include +#include // for char_traits, basic_istream::operator>>, basic_... +#include // for priority_queue +#include // for vector +#include // for greater +#include // for make_pair, pair using PII = std::pair; diff --git a/graph/topological_sort_by_kahns_algo.cpp b/graph/topological_sort_by_kahns_algo.cpp index d491fa80fa5..612186d8f61 100644 --- a/graph/topological_sort_by_kahns_algo.cpp +++ b/graph/topological_sort_by_kahns_algo.cpp @@ -1,8 +1,6 @@ -#include -#include -#include -#include -#include +#include // for char_traits, basic_istream::operator>>, basic_is... +#include // for queue +#include // for vector std::vector topoSortKahn(int N, const std::vector > &adj); diff --git a/graph/travelling_salesman_problem.cpp b/graph/travelling_salesman_problem.cpp index 8b46080093f..72a02b82c7e 100644 --- a/graph/travelling_salesman_problem.cpp +++ b/graph/travelling_salesman_problem.cpp @@ -17,12 +17,11 @@ * This is the naive implementation of the problem. */ -#include /// for std::min -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations -#include /// for limits of integral types -#include /// for std::vector +#include // for min, next_permutation +#include // for assert +#include // for uint32_t, int32_t +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for vector /** * @namespace graph From 0c6611a835d75718ae060b8b634ce47c85d7690b Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:38:33 +0530 Subject: [PATCH 044/131] chore: use iwyu on hashing/**.cpp --- hashing/chaining.cpp | 9 +++++---- hashing/double_hash_hash_table.cpp | 7 ++++--- hashing/linear_probing_hash_table.cpp | 6 ++++-- hashing/quadratic_probing_hash_table.cpp | 8 +++++--- hashing/sha256.cpp | 19 +++++++++++-------- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/hashing/chaining.cpp b/hashing/chaining.cpp index 9c5a2a0766a..cf7a4dced0e 100644 --- a/hashing/chaining.cpp +++ b/hashing/chaining.cpp @@ -5,10 +5,11 @@ * @brief Implementation of [hash * chains](https://en.wikipedia.org/wiki/Hash_chain). */ -#include -#include -#include -#include +#include // for abs +#include // for abs +#include // for basic_ostream, operator<<, char_traits, cout +#include // for shared_ptr, __shared_ptr_access +#include // for vector /** * @brief Chain class with a given modulus diff --git a/hashing/double_hash_hash_table.cpp b/hashing/double_hash_hash_table.cpp index f5d803ba22f..221b9fcdb35 100644 --- a/hashing/double_hash_hash_table.cpp +++ b/hashing/double_hash_hash_table.cpp @@ -6,9 +6,10 @@ * keys](https://en.wikipedia.org/wiki/Double_hashing). * @note The implementation can be optimized by using OOP style. */ -#include -#include -#include +#include // for size_t +#include // for hash +#include // for basic_ostream, operator<<, char_traits, cout +#include // for vector /** * @addtogroup open_addressing Open Addressing diff --git a/hashing/linear_probing_hash_table.cpp b/hashing/linear_probing_hash_table.cpp index d87cb9cf727..01c732bb614 100644 --- a/hashing/linear_probing_hash_table.cpp +++ b/hashing/linear_probing_hash_table.cpp @@ -6,8 +6,10 @@ * hash](https://en.wikipedia.org/wiki/Linear_probing) keys. * @note The implementation can be optimized by using OOP style. */ -#include -#include +#include // for size_t +#include // for hash +#include // for basic_ostream, operator<<, char_traits, cout +#include // for vector /** * @addtogroup open_addressing Open Addressing diff --git a/hashing/quadratic_probing_hash_table.cpp b/hashing/quadratic_probing_hash_table.cpp index 258c009d0f7..add1d38faee 100644 --- a/hashing/quadratic_probing_hash_table.cpp +++ b/hashing/quadratic_probing_hash_table.cpp @@ -6,9 +6,11 @@ * hash](https://en.wikipedia.org/wiki/Quadratic_probing) keys. * @note The implementation can be optimized by using OOP style. */ -#include -#include -#include +#include // for round, pow +#include // for size_t +#include // for hash +#include // for basic_ostream, operator<<, char_traits, cout +#include // for vector /** * @addtogroup open_addressing Open Addressing diff --git a/hashing/sha256.cpp b/hashing/sha256.cpp index 0eae0bd361e..202e58275d1 100644 --- a/hashing/sha256.cpp +++ b/hashing/sha256.cpp @@ -12,14 +12,17 @@ * used for authenticating software packages and secure password hashing. */ -#include /// For std::array -#include /// For assert -#include /// For uint8_t, uint32_t and uint64_t data types -#include /// For std::setfill and std::setw -#include /// For IO operations -#include /// For std::stringstream -#include /// For std::move -#include /// For std::vector +#include // for array +#include // for assert +#include // for uint32_t, uint8_t +#include // for operator<<, setfill, setw, _Setfill, _Setw +#include // for char_traits, basic_ostream, operator<<, cout, hex +#include // for basic_stringstream +#include // for move +#include // for allocator, vector +#include // for size_t +#include // for out_of_range +#include // for basic_string, string, operator== /** * @namespace hashing From c3897d3763c5f0fb0077d761f824e754b7b181da Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:38:42 +0530 Subject: [PATCH 045/131] chore: use iwyu on machine_learning/**.cpp --- machine_learning/a_star_search.cpp | 24 ++++++++++------- machine_learning/adaline_learning.cpp | 17 ++++++------ machine_learning/k_nearest_neighbors.cpp | 19 ++++++++------ machine_learning/neural_network.cpp | 26 ++++++++++--------- .../ordinary_least_squares_regressor.cpp | 12 +++++---- 5 files changed, 55 insertions(+), 43 deletions(-) diff --git a/machine_learning/a_star_search.cpp b/machine_learning/a_star_search.cpp index 9f713883a1d..f805d09efc8 100644 --- a/machine_learning/a_star_search.cpp +++ b/machine_learning/a_star_search.cpp @@ -19,15 +19,21 @@ * values having minimum F(state). * @author [Ashish Daulatabad](https://github.com/AshishYUO) */ -#include /// for `std::reverse` function -#include /// for `std::array`, representing `EightPuzzle` board -#include /// for `assert` -#include /// for `std::function` STL -#include /// for IO operations -#include /// for `std::map` STL -#include /// for `std::shared_ptr` -#include /// for `std::set` STL -#include /// for `std::vector` STL +#include // for uint32_t, int8_t + +#include // for max, min +#include // for array, operator== +#include // for assert +#include // for size_t +#include // for function +#include // for operator<<, basic_ostream, char_traits, cout +#include // for operator!=, map, operator== +#include // for shared_ptr, make_shared, operator!= +#include // for set +#include // for tie, tuple +#include // for pair, move, make_pair, swap +#include // for vector + /** * @namespace machine_learning * @brief Machine learning algorithms diff --git a/machine_learning/adaline_learning.cpp b/machine_learning/adaline_learning.cpp index 6da839a9d04..55385d130d8 100644 --- a/machine_learning/adaline_learning.cpp +++ b/machine_learning/adaline_learning.cpp @@ -26,15 +26,14 @@ * computed using stochastic gradient descent method. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include // for abs +#include // for array +#include // for assert +#include // for rand, exit, srand, strtof, EXIT_FAILURE +#include // for time +#include // for basic_ostream, operator<<, char_traits, cout +#include // for inner_product +#include // for vector /** Maximum number of iterations to learn */ constexpr int MAX_ITER = 500; // INT_MAX diff --git a/machine_learning/k_nearest_neighbors.cpp b/machine_learning/k_nearest_neighbors.cpp index 92621862ccf..2ff1818fe41 100644 --- a/machine_learning/k_nearest_neighbors.cpp +++ b/machine_learning/k_nearest_neighbors.cpp @@ -9,13 +9,16 @@ * the K-nearest neighbors. */ -#include /// for std::transform and std::sort -#include /// for assert -#include /// for std::pow and std::sqrt -#include /// for std::cout -#include /// for std::accumulate -#include /// for std::unordered_map -#include /// for std::vector +#include // for sort, transform +#include // for assert +#include // for sqrt, pow +#include // for size_t +#include // for basic_ostream, operator<<, char_traits, cout +#include // for back_inserter +#include // for accumulate +#include // for unordered_map, _Node_iterator +#include // for pair +#include // for vector /** * @namespace machine_learning @@ -65,7 +68,7 @@ class Knn { * @param Y labels vector */ explicit Knn(std::vector>& X, std::vector& Y) - : X_(X), Y_(Y){}; + : X_(X), Y_(Y) {}; /** * Copy Constructor for class Knn. diff --git a/machine_learning/neural_network.cpp b/machine_learning/neural_network.cpp index 7e20f7a4022..e3c43884915 100644 --- a/machine_learning/neural_network.cpp +++ b/machine_learning/neural_network.cpp @@ -27,18 +27,20 @@ * MSE as loss function. Bias is also not included. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "vector_ops.hpp" // Custom header file for vector operations +#include // for duration, duration_cast, high_resolution_c... +#include // for max, min +#include // for assert +#include // for exp +#include // for basic_ostream, operator<<, endl, basic_ist... +#include // for cerr, cout +#include // for basic_stringstream +#include // for char_traits, basic_string, operator<<, ope... +#include // for valarray +#include // for vector +#include // for exit, size_t, EXIT_FAILURE +#include // for pair, make_pair + +#include "vector_ops.hpp" // for argmax, apply_function, get_shape, multiply /** \namespace machine_learning * \brief Machine learning algorithms diff --git a/machine_learning/ordinary_least_squares_regressor.cpp b/machine_learning/ordinary_least_squares_regressor.cpp index 0c865761bee..e9475ea4438 100644 --- a/machine_learning/ordinary_least_squares_regressor.cpp +++ b/machine_learning/ordinary_least_squares_regressor.cpp @@ -9,11 +9,13 @@ * * \author [Krishna Vedala](https://github.com/kvedala) */ -#include -#include // for std::abs -#include // for print formatting -#include -#include +#include // for abs + +#include // for assert +#include // for size_t +#include // for operator<<, setfill, setw, _Setfill, _Setw +#include // for basic_ostream, operator<<, char_traits, cout +#include // for vector /** * operator to print a matrix From c47117ca3f02aee4ba054b861bf7ab44e2ae6348 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:38:50 +0530 Subject: [PATCH 046/131] chore: use iwyu on math/**.cpp --- math/area.cpp | 9 ++++----- math/check_prime.cpp | 5 +++-- math/complex_numbers.cpp | 13 +++++++------ math/eratosthenes.cpp | 12 +++++++----- math/extended_euclid_algorithm.cpp | 6 +++--- math/factorial.cpp | 8 +++++--- math/fibonacci_fast.cpp | 5 ++--- math/fibonacci_large.cpp | 9 +++++---- math/gcd_recursive_euclidean.cpp | 3 ++- math/integral_approximation2.cpp | 15 ++++++++------- math/inv_sqrt.cpp | 11 ++++++----- math/iterative_factorial.cpp | 8 ++++---- math/large_factorial.cpp | 9 +++++---- math/linear_recurrence_matrix.cpp | 7 +++---- math/modular_inverse_fermat_little_theorem.cpp | 4 ++-- math/n_bonacci.cpp | 10 ++++++---- math/ncr_modulo_p.cpp | 7 ++++--- math/prime_factorization.cpp | 8 ++++---- math/prime_numbers.cpp | 5 +++-- math/primes_up_to_billion.cpp | 5 +++-- math/quadratic_equations_complex_numbers.cpp | 16 ++++++++-------- math/realtime_stats.cpp | 7 ++++--- math/string_fibonacci.cpp | 8 ++++---- 23 files changed, 102 insertions(+), 88 deletions(-) diff --git a/math/area.cpp b/math/area.cpp index 691fe91f0fc..f6ac5f4a8b8 100644 --- a/math/area.cpp +++ b/math/area.cpp @@ -9,11 +9,10 @@ * @author [Focusucof](https://github.com/Focusucof) */ #define _USE_MATH_DEFINES -#include /// for assert -#include /// for M_PI definition and pow() -#include -#include /// for uint16_t datatype -#include /// for IO operations +#include // for assert +#include // for NAN, M_PI, pow +#include // for uint16_t +#include // for basic_ostream, operator<<, char_traits, endl, cout /** * @namespace math diff --git a/math/check_prime.cpp b/math/check_prime.cpp index ebd48cab5aa..add436236eb 100644 --- a/math/check_prime.cpp +++ b/math/check_prime.cpp @@ -14,8 +14,9 @@ * @author [ewd00010](https://github.com/ewd00010) */ -#include /// for assert -#include /// for IO operations +#include // for int64_t +#include // for assert +#include // for char_traits, basic_ostream, operator<<, cout, endl /** * @brief Mathematical algorithms diff --git a/math/complex_numbers.cpp b/math/complex_numbers.cpp index f8923864961..0482a088d23 100644 --- a/math/complex_numbers.cpp +++ b/math/complex_numbers.cpp @@ -7,12 +7,13 @@ * operators overloaded to accommodate (mathematical) field operations. */ -#include -#include -#include -#include -#include -#include +#include // for assert +#include // for atan2, cos, sin, sqrt +#include // for complex, abs, arg, conj, operator*, operator+ +#include // for time +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for invalid_argument +#include // for rand, srand /** * \brief Class Complex to represent complex numbers as a field. diff --git a/math/eratosthenes.cpp b/math/eratosthenes.cpp index 224e9f51b31..875fce20bfc 100644 --- a/math/eratosthenes.cpp +++ b/math/eratosthenes.cpp @@ -13,11 +13,13 @@ * @author [Keval Kapdee](https://github.com/thechubbypanda) */ -#include /// For assert -#include /// For timing the sieve -#include /// For IO operations -#include /// For string handling -#include /// For std::vector +#include // for duration, duration_cast, high_resolution_clock +#include // for uint64_t +#include // for assert +#include // for basic_ostream, operator<<, cout, endl +#include // for char_traits, basic_string, operator==, string +#include // for vector +#include // for ratio /** * @namespace math diff --git a/math/extended_euclid_algorithm.cpp b/math/extended_euclid_algorithm.cpp index cc2eacac8e3..5fead27b1a7 100644 --- a/math/extended_euclid_algorithm.cpp +++ b/math/extended_euclid_algorithm.cpp @@ -9,9 +9,9 @@ * multiplicative inverse of a number. (A * B)%M == 1 Here B is the MMI of A for * given M, so extendedEuclid (A, M) gives B. */ -#include // for swap function -#include -#include +#include // for char_traits, basic_ostream, basic_ostream::opera... +#include // for uint32_t, int32_t +#include // for swap /** * function to update the coefficients per iteration diff --git a/math/factorial.cpp b/math/factorial.cpp index a6b039da45b..f4dffc1383b 100644 --- a/math/factorial.cpp +++ b/math/factorial.cpp @@ -11,9 +11,11 @@ * @author [Akshay Gupta](https://github.com/Akshay1910) */ -#include /// for assert -#include /// for integral typedefs -#include /// for I/O operations +#include // for assert +#include // for uint64_t, uint8_t +#include // for operator<<, basic_ostream, cout +#include // for invalid_argument + /** * @namespace * @brief Mathematical algorithms diff --git a/math/fibonacci_fast.cpp b/math/fibonacci_fast.cpp index 0948276a08a..ed33af4ebd5 100644 --- a/math/fibonacci_fast.cpp +++ b/math/fibonacci_fast.cpp @@ -15,9 +15,8 @@ * @see fibonacci_large.cpp, fibonacci.cpp, string_fibonacci.cpp */ -#include -#include -#include +#include // for uint64_t +#include // for char_traits, basic_ostream, operator<<, cerr, cout /** * maximum number that can be computed - The result after 93 cannot be stored diff --git a/math/fibonacci_large.cpp b/math/fibonacci_large.cpp index e4f4e5eaf1b..73e696bddd3 100644 --- a/math/fibonacci_large.cpp +++ b/math/fibonacci_large.cpp @@ -11,11 +11,12 @@ * @see fibonacci.cpp, fibonacci_fast.cpp, string_fibonacci.cpp */ -#include -#include -#include +#include // for strtoull +#include // for uint64_t +#include // for clock, clock_t, CLOCKS_PER_SEC, NULL +#include // for basic_ostream, char_traits, operator<< -#include "./large_number.h" +#include "./large_number.h" // for large_number, operator<<, operator== /** Compute fibonacci numbers using the relation * \f[f(n)=f(n-1)+f(n-2)\f] diff --git a/math/gcd_recursive_euclidean.cpp b/math/gcd_recursive_euclidean.cpp index 2a3d2183c4e..368f67cde0d 100644 --- a/math/gcd_recursive_euclidean.cpp +++ b/math/gcd_recursive_euclidean.cpp @@ -6,7 +6,8 @@ * * @see gcd_iterative_euclidean.cpp, gcd_of_n_numbers.cpp */ -#include +#include // for basic_ostream, char_traits, operator<<, basic_o... +#include // for domain_error /** * algorithm diff --git a/math/integral_approximation2.cpp b/math/integral_approximation2.cpp index eed605e035f..b858fedba6d 100644 --- a/math/integral_approximation2.cpp +++ b/math/integral_approximation2.cpp @@ -22,13 +22,14 @@ */ #define _USE_MATH_DEFINES /// for M_PI on windows -#include /// for math functions -#include /// for fixed size data types -#include /// for time to initialize rng -#include /// for function pointers -#include /// for std::cout -#include /// for random number generation -#include /// for std::vector +#include // for exp, M_PI, sin, sqrt +#include // for uint32_t +#include // for time +#include // for function +#include // for basic_ostream, char_traits, operator<<, endl +#include // for normal_distribution, uniform_real_distribution +#include // for vector +#include // for min /** * @namespace math diff --git a/math/inv_sqrt.cpp b/math/inv_sqrt.cpp index 1f625e1cf8a..55088b0c0eb 100644 --- a/math/inv_sqrt.cpp +++ b/math/inv_sqrt.cpp @@ -8,11 +8,12 @@ * This algorithm is used to calculate shadows in Quake III Arena. */ -#include /// for assert -#include /// for `std::sqrt` -#include /// for integral typedefs -#include /// for IO operations -#include /// for numeric_limits +#include // for assert +#include // for fabs, sqrt +#include // for int32_t, int64_t +#include // for basic_ostream, char_traits, operator<<, cout +#include // for conditional + /** * @brief This is the function that calculates the fast inverse square root. * The following code is the fast inverse square root implementation from diff --git a/math/iterative_factorial.cpp b/math/iterative_factorial.cpp index 12f6afe06a0..5a3454b281d 100644 --- a/math/iterative_factorial.cpp +++ b/math/iterative_factorial.cpp @@ -25,10 +25,10 @@ * */ -#include /// for assert -#include /// for integral types -#include /// for std::invalid_argument -#include /// for std::cout +#include // for assert +#include // for uint64_t, uint8_t +#include // for operator<<, basic_ostream, cout +#include // for invalid_argument /** * @namespace diff --git a/math/large_factorial.cpp b/math/large_factorial.cpp index 20c677cdcc4..5f5b5562d90 100644 --- a/math/large_factorial.cpp +++ b/math/large_factorial.cpp @@ -5,11 +5,12 @@ * \author [Krishna Vedala](https://github.com/kvedala) * @see factorial.cpp */ -#include -#include -#include +#include // for atoi +#include // for strlen, size_t +#include // for clock, clock_t, CLOCKS_PER_SEC +#include // for basic_ostream, char_traits, operator<< -#include "./large_number.h" +#include "./large_number.h" // for large_number, operator<< /** Test implementation for 10! Result must be 3628800. * @returns True if test pass else False diff --git a/math/linear_recurrence_matrix.cpp b/math/linear_recurrence_matrix.cpp index d59ad6aa1c0..ab5c928d30b 100644 --- a/math/linear_recurrence_matrix.cpp +++ b/math/linear_recurrence_matrix.cpp @@ -17,10 +17,9 @@ * here](https://en.wikipedia.org/wiki/Exponentiation_by_squaring). * @author [Ashish Daulatabad](https://github.com/AshishYUO) */ -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations -#include /// for std::vector STL +#include // for assert +#include // for int64_t, uint32_t, uint64_t +#include // for vector /** * @namespace math diff --git a/math/modular_inverse_fermat_little_theorem.cpp b/math/modular_inverse_fermat_little_theorem.cpp index 7550e14bf23..bfbd2b419dc 100644 --- a/math/modular_inverse_fermat_little_theorem.cpp +++ b/math/modular_inverse_fermat_little_theorem.cpp @@ -43,8 +43,8 @@ * (as \f$a\times a^{-1} = 1\f$) */ -#include -#include +#include // for int64_t +#include // for char_traits, basic_ostream, operator<<, cout, endl /** Recursive function to calculate exponent in \f$O(\log n)\f$ using binary * exponent. diff --git a/math/n_bonacci.cpp b/math/n_bonacci.cpp index 601b2edf0d7..0660703353e 100644 --- a/math/n_bonacci.cpp +++ b/math/n_bonacci.cpp @@ -15,10 +15,12 @@ * @author [Swastika Gupta](https://github.com/Swastyy) */ -#include /// for assert -#include /// for integral typedefs -#include /// for std::cout -#include /// for std::vector +#include // for assert +#include // for uint64_t +#include // for char_traits, basic_ostream, operator<< +#include // for vector, operator== +#include // for initializer_list + /** * @namespace math * @brief Mathematical algorithms diff --git a/math/ncr_modulo_p.cpp b/math/ncr_modulo_p.cpp index cbf5e9e1a00..f154821c4bd 100644 --- a/math/ncr_modulo_p.cpp +++ b/math/ncr_modulo_p.cpp @@ -9,9 +9,10 @@ * @author [Kaustubh Damania](https://github.com/KaustubhDamania) */ -#include /// for assert -#include /// for std::cout -#include /// for std::vector +#include // for int64_t +#include // for assert +#include // for char_traits, basic_ostream, operator<<, basic_os... +#include // for vector /** * @namespace math diff --git a/math/prime_factorization.cpp b/math/prime_factorization.cpp index 001c2c3c360..3617ea35c09 100644 --- a/math/prime_factorization.cpp +++ b/math/prime_factorization.cpp @@ -2,10 +2,10 @@ * @file * @brief Prime factorization of positive integers */ -#include -#include -#include -#include +#include // for memset +#include // for char_traits, basic_ostream, operator<<, basic_os... +#include // for vector +#include // for pair, make_pair /** Declaring variables for maintaing prime numbers and to check whether a * number is prime or not diff --git a/math/prime_numbers.cpp b/math/prime_numbers.cpp index cd6aca0ca9c..50723d9bc15 100644 --- a/math/prime_numbers.cpp +++ b/math/prime_numbers.cpp @@ -3,8 +3,9 @@ * @brief Get list of prime numbers * @see primes_up_to_billion.cpp sieve_of_eratosthenes.cpp */ -#include -#include +#include // for size_t +#include // for char_traits, basic_ostream, operator<<, cout +#include // for vector /** Generate an increasingly large number of primes * and store in a list diff --git a/math/primes_up_to_billion.cpp b/math/primes_up_to_billion.cpp index b7377cea584..d1dc00abfc0 100644 --- a/math/primes_up_to_billion.cpp +++ b/math/primes_up_to_billion.cpp @@ -3,8 +3,9 @@ * @brief Compute prime numbers upto 1 billion * @see prime_numbers.cpp sieve_of_eratosthenes.cpp */ -#include -#include +#include // for int64_t +#include // for memset +#include // for operator<<, basic_ostream, cout, basic_istream, cin /** array to store the primes */ char prime[100000000]; diff --git a/math/quadratic_equations_complex_numbers.cpp b/math/quadratic_equations_complex_numbers.cpp index 3a50719e5dc..1140e7760a6 100644 --- a/math/quadratic_equations_complex_numbers.cpp +++ b/math/quadratic_equations_complex_numbers.cpp @@ -28,13 +28,13 @@ * (-0.5,0.866025) (-0.5,0.866025) */ -#include /// std::array -#include /// assert -#include /// std::sqrt, std::trunc, std::pow -#include /// std::complex -#include /// std::invalid_argument -#include /// std::setprecision -#include /// std::cout +#include // for array, operator== +#include // for assert +#include // for round, sqrt, pow +#include // for complex, operator== +#include // for size_t +#include // for operator<<, basic_ostream, cout +#include // for invalid_argument /** * @namespace @@ -65,7 +65,7 @@ std::array, 2> quadraticEquation(long double a, solutions[1] = -b * 0.5 / a; return solutions; } - + // Complex root (discriminant < 0) // Note that the left term (-b / 2a) is always real. The imaginary part // appears when b^2 - 4ac < 0, so sqrt(b^2 - 4ac) has no real roots. So, diff --git a/math/realtime_stats.cpp b/math/realtime_stats.cpp index 672acfa03b9..6a455115d35 100644 --- a/math/realtime_stats.cpp +++ b/math/realtime_stats.cpp @@ -7,9 +7,10 @@ * simple enough to be easily implemented in an embedded system. * \author [Krishna Vedala](https://github.com/kvedala) */ -#include -#include -#include +#include // for abs +#include // for assert +#include // for sqrt +#include // for basic_ostream, char_traits, operator<<, cout /** * \namespace statistics diff --git a/math/string_fibonacci.cpp b/math/string_fibonacci.cpp index a7ff4c8bbad..34db60e7e2b 100644 --- a/math/string_fibonacci.cpp +++ b/math/string_fibonacci.cpp @@ -8,12 +8,12 @@ * @see fibonacci_large.cpp, fibonacci_fast.cpp, fibonacci.cpp */ -#include /// for integral typedefs -#include +#include // for uint64_t +#include // for char_traits, basic_ostream, operator<<, cout +#include // for allocator, basic_string, operator+, string, oper... #ifdef _MSC_VER -#include // use this for MS Visual C +#include // for allocator, basic_string, operator+, string, oper... #else -#include // otherwise #endif /** From eff2f44a502aa437903938c6a9ebbc0f8ac7d278 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:39:02 +0530 Subject: [PATCH 047/131] chore: use iwyu on numerical_methods/**.cpp --- numerical_methods/babylonian_method.cpp | 7 ++++--- numerical_methods/bisection_method.cpp | 6 +++--- numerical_methods/brent_method_extrema.cpp | 14 ++++++++------ numerical_methods/composite_simpson_rule.cpp | 16 ++++++++-------- numerical_methods/false_position.cpp | 4 ++-- numerical_methods/golden_search_extrema.cpp | 14 ++++++++------ numerical_methods/gram_schmidt.cpp | 10 ++++------ numerical_methods/midpoint_integral_method.cpp | 15 ++++++++------- numerical_methods/newton_raphson_method.cpp | 11 ++++++----- numerical_methods/ode_forward_euler.cpp | 12 +++++++----- numerical_methods/ode_midpoint_euler.cpp | 12 +++++++----- numerical_methods/ode_semi_implicit_euler.cpp | 12 +++++++----- 12 files changed, 72 insertions(+), 61 deletions(-) diff --git a/numerical_methods/babylonian_method.cpp b/numerical_methods/babylonian_method.cpp index a70fa993e01..b08c0d235df 100644 --- a/numerical_methods/babylonian_method.cpp +++ b/numerical_methods/babylonian_method.cpp @@ -9,9 +9,10 @@ * @author [Ameya Chawla](https://github.com/ameyachawlaggsipu) */ -#include /// for assert -#include -#include /// for IO operations +#include // for assert +#include // for NAN +#include // for operator<<, basic_ostream, cout +#include // for max, min /** * @namespace numerical_methods diff --git a/numerical_methods/bisection_method.cpp b/numerical_methods/bisection_method.cpp index c93c529d248..c2ef6bfb92b 100644 --- a/numerical_methods/bisection_method.cpp +++ b/numerical_methods/bisection_method.cpp @@ -13,9 +13,9 @@ * * \see newton_raphson_method.cpp, false_position.cpp, secant_method.cpp */ -#include -#include -#include +#include // for abs +#include // for pow +#include // for basic_ostream, char_traits, operator<<, cout #define EPSILON \ 1e-6 // std::numeric_limits::epsilon() ///< system accuracy limit diff --git a/numerical_methods/brent_method_extrema.cpp b/numerical_methods/brent_method_extrema.cpp index bd4d2796d29..5077f0bd022 100644 --- a/numerical_methods/brent_method_extrema.cpp +++ b/numerical_methods/brent_method_extrema.cpp @@ -14,12 +14,14 @@ * \author [Krishna Vedala](https://github.com/kvedala) */ #define _USE_MATH_DEFINES ///< required for MS Visual C++ -#include -#include -#include /// for integral typedefs -#include -#include -#include +#include // for abs +#include // for assert +#include // for sqrt, cos, pow, M_E, M_PI +#include // for uint32_t +#include // for function +#include // for operator<<, basic_ostream, char_traits, cout +#include // for numeric_limits +#include // for swap #define EPSILON \ std::sqrt( \ diff --git a/numerical_methods/composite_simpson_rule.cpp b/numerical_methods/composite_simpson_rule.cpp index 2ca58cbe4c0..14f64bfefff 100644 --- a/numerical_methods/composite_simpson_rule.cpp +++ b/numerical_methods/composite_simpson_rule.cpp @@ -35,14 +35,14 @@ * */ -#include /// for assert -#include /// for math functions -#include -#include /// for integer allocation -#include /// for std::atof -#include /// for std::function -#include /// for IO operations -#include /// for std::map container +#include // for assert +#include // for log, sqrt, pow, exp, NAN, isnan +#include // for int32_t +#include // for atof, atoi +#include // for function +#include // for basic_ostream, char_traits, operator<<, cout +#include // for map +#include // for pair /** * @namespace numerical_methods diff --git a/numerical_methods/false_position.cpp b/numerical_methods/false_position.cpp index ad23d2677bf..5d83ead3407 100644 --- a/numerical_methods/false_position.cpp +++ b/numerical_methods/false_position.cpp @@ -22,8 +22,8 @@ * \author Unknown author * \author [Samruddha Patil](https://github.com/sampatil578) */ -#include /// for math operations -#include /// for io operations +#include // for int16_t +#include // for basic_ostream, char_traits, operator<<, cout, endl /** * @namespace numerical_methods diff --git a/numerical_methods/golden_search_extrema.cpp b/numerical_methods/golden_search_extrema.cpp index 2d9dd507013..048679a0d4c 100644 --- a/numerical_methods/golden_search_extrema.cpp +++ b/numerical_methods/golden_search_extrema.cpp @@ -8,12 +8,14 @@ * \author [Krishna Vedala](https://github.com/kvedala) */ #define _USE_MATH_DEFINES //< required for MS Visual C++ -#include -#include -#include /// for integral typedefs -#include -#include -#include +#include // for abs +#include // for assert +#include // for cos, pow, M_E, M_PI, sqrt +#include // for uint32_t +#include // for function +#include // for operator<<, basic_ostream, char_traits, cout +#include // for numeric_limits +#include // for swap #define EPSILON 1e-7 ///< solution accuracy limit diff --git a/numerical_methods/gram_schmidt.cpp b/numerical_methods/gram_schmidt.cpp index c72f8553b2e..be256cf3761 100644 --- a/numerical_methods/gram_schmidt.cpp +++ b/numerical_methods/gram_schmidt.cpp @@ -28,12 +28,10 @@ * @author [Akanksha Gupta](https://github.com/Akanksha-Gupta920) */ -#include /// for std::array -#include /// for assert -#include /// for fabs -#include /// for io operations - -#include "math.h" +#include // for array +#include // for assert +#include // for fabs, NAN +#include // for operator<<, basic_ostream, char_traits, cout /** * @namespace numerical_methods diff --git a/numerical_methods/midpoint_integral_method.cpp b/numerical_methods/midpoint_integral_method.cpp index 3eab8fd1e2d..7a857615dfd 100644 --- a/numerical_methods/midpoint_integral_method.cpp +++ b/numerical_methods/midpoint_integral_method.cpp @@ -18,13 +18,14 @@ * * @author [ggkogkou](https://github.com/ggkogkou) */ -#include /// for assert -#include /// for math functions -#include /// for integer allocation -#include /// for std::atof -#include /// for std::function -#include /// for IO operations -#include /// for std::map container +#include // for assert +#include // for log, sqrt, pow, exp, NAN, isnan +#include // for int32_t +#include // for atof, atoi +#include // for function +#include // for basic_ostream, char_traits, operator<<, cout +#include // for map +#include // for pair /** * @namespace numerical_methods diff --git a/numerical_methods/newton_raphson_method.cpp b/numerical_methods/newton_raphson_method.cpp index ce75088a39a..7f90cef9ec5 100644 --- a/numerical_methods/newton_raphson_method.cpp +++ b/numerical_methods/newton_raphson_method.cpp @@ -12,11 +12,12 @@ * \author [Krishna Vedala](https://github.com/kvedala) * \see bisection_method.cpp, false_position.cpp */ -#include -#include /// for integral typedefs -#include -#include -#include +#include // for abs +#include // for pow, NAN +#include // for INT16_MAX, int16_t +#include // for time +#include // for char_traits, basic_ostream, operator<< +#include // for rand, srand constexpr double EPSILON = 1e-10; ///< system accuracy limit constexpr int16_t MAX_ITERATIONS = INT16_MAX; ///< Maximum number of iterations diff --git a/numerical_methods/ode_forward_euler.cpp b/numerical_methods/ode_forward_euler.cpp index 5e4dda31ba7..cc675c5d094 100644 --- a/numerical_methods/ode_forward_euler.cpp +++ b/numerical_methods/ode_forward_euler.cpp @@ -36,11 +36,13 @@ * \see ode_midpoint_euler.cpp, ode_semi_implicit_euler.cpp */ -#include -#include -#include -#include -#include +#include // for cos, sin, NAN +#include // for clock, clock_t, CLOCKS_PER_SEC, size_t +#include // for operator<<, basic_ostream, char_traits, basic_of... +#include // for cout, cin +#include // for valarray, __multiplies, operator*, _BinClos +#include // for perror +#include // for atof /** * @brief Problem statement for a system with first-order differential diff --git a/numerical_methods/ode_midpoint_euler.cpp b/numerical_methods/ode_midpoint_euler.cpp index 50cf4e4c6c4..1b14a585369 100644 --- a/numerical_methods/ode_midpoint_euler.cpp +++ b/numerical_methods/ode_midpoint_euler.cpp @@ -35,11 +35,13 @@ * \see ode_forward_euler.cpp, ode_semi_implicit_euler.cpp */ -#include -#include -#include -#include -#include +#include // for cos, sin +#include // for clock, clock_t, CLOCKS_PER_SEC, size_t +#include // for operator<<, basic_ostream, char_traits, basic_of... +#include // for cout, cin +#include // for valarray, _BinClos, __multiplies, __plus, operator* +#include // for perror +#include // for atof /** * @brief Problem statement for a system with first-order differential diff --git a/numerical_methods/ode_semi_implicit_euler.cpp b/numerical_methods/ode_semi_implicit_euler.cpp index 01904ac1684..b23a81f9f58 100644 --- a/numerical_methods/ode_semi_implicit_euler.cpp +++ b/numerical_methods/ode_semi_implicit_euler.cpp @@ -35,11 +35,13 @@ * \see ode_midpoint_euler.cpp, ode_forward_euler.cpp */ -#include -#include -#include -#include -#include +#include // for cos, sin +#include // for clock, clock_t, CLOCKS_PER_SEC, size_t +#include // for operator<<, basic_ostream, char_traits, basic_of... +#include // for cout, cin +#include // for valarray, __multiplies, operator*, _BinClos +#include // for perror +#include // for atof /** * @brief Problem statement for a system with first-order differential From 8a8fd42383207c24bee7dbf8f502ceb339b0e63d Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:39:10 +0530 Subject: [PATCH 048/131] chore: use iwyu on others/**.cpp --- others/decimal_to_roman_numeral.cpp | 6 ++---- others/easter.cpp | 5 ++--- others/fast_integer_input.cpp | 3 ++- others/iterative_tree_traversals.cpp | 11 ++++++----- others/kadanes3.cpp | 12 +++++++----- others/kelvin_to_celsius.cpp | 7 ++++--- others/matrix_exponentiation.cpp | 5 +++-- others/palindrome_of_number.cpp | 8 ++++---- others/paranthesis_matching.cpp | 6 +++--- others/postfix_evaluation.cpp | 8 +++++--- others/smallest_circle.cpp | 7 ++++--- 11 files changed, 42 insertions(+), 36 deletions(-) diff --git a/others/decimal_to_roman_numeral.cpp b/others/decimal_to_roman_numeral.cpp index ad4aa32c5ad..c44f0af7ae7 100644 --- a/others/decimal_to_roman_numeral.cpp +++ b/others/decimal_to_roman_numeral.cpp @@ -4,10 +4,8 @@ * to both Lower case and Upper case Roman Numeral */ -#include -#include -#include -#include +#include // for char_traits, basic_ostream, operator<<, basic_os... +#include // for basic_string, operator+, allocator, string, oper... /** This functions fills a string with character c, n times and returns it * @note This can probably be replace by `memcpy` function. diff --git a/others/easter.cpp b/others/easter.cpp index 44b10335300..639ee18d365 100644 --- a/others/easter.cpp +++ b/others/easter.cpp @@ -17,9 +17,8 @@ * @author [AlternateWalls](https://github.com/AlternateWalls) */ -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations +#include // for assert +#include // for uint64_t /* * @brief Contains information for Easter date diff --git a/others/fast_integer_input.cpp b/others/fast_integer_input.cpp index 87963c9ad88..a3fd4e87cf2 100644 --- a/others/fast_integer_input.cpp +++ b/others/fast_integer_input.cpp @@ -3,7 +3,8 @@ * @brief Read integers from stdin continuously as they are entered without * waiting for the `\n` character */ -#include +#include // for char_traits, basic_ostream, basic_ostream::opera... +#include // for getchar /** Function to read the number from stdin. The function reads input until a non * numeric character is entered. diff --git a/others/iterative_tree_traversals.cpp b/others/iterative_tree_traversals.cpp index 11fa1814688..2a97fbf3862 100644 --- a/others/iterative_tree_traversals.cpp +++ b/others/iterative_tree_traversals.cpp @@ -35,11 +35,12 @@ * set of steps until the Stack becomes empty or the current becomes NULL. And * return the result array as the inorder traversal of a tree. */ -#include /// for `reverse` -#include /// for `assert` -#include /// for I/O operations -#include /// for `stack` -#include /// for `vector` +#include // for int64_t +#include // for reverse +#include // for assert +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for stack +#include // for vector /** * @namespace others diff --git a/others/kadanes3.cpp b/others/kadanes3.cpp index 22c1119c858..b22cb96233b 100644 --- a/others/kadanes3.cpp +++ b/others/kadanes3.cpp @@ -14,11 +14,13 @@ * @author [Abhijeet Tiwari](https://github.com/thisabhijeet) */ -#include /// for std::array -#include /// for assert -#include /// for INT_MIN value -#include /// for integral typedefs -#include /// for IO operations +#include // for array +#include // for assert +#include // for INT_MIN +#include // for int64_t, uint64_t +#include // for operator<<, basic_ostream, cout +#include // for size_t + /** * @brief Utility function to check the current maximum number * \param arr input array diff --git a/others/kelvin_to_celsius.cpp b/others/kelvin_to_celsius.cpp index b5efdeddf78..149c19d48f7 100644 --- a/others/kelvin_to_celsius.cpp +++ b/others/kelvin_to_celsius.cpp @@ -17,9 +17,10 @@ * @author [David Leal](https://github.com/Panquesito7) */ -#include /// for assert -#include /// for std::abs -#include /// for IO operations +#include // for abs +#include // for assert +#include // for operator<<, basic_ostream, cout +#include // for invalid_argument /** * @namespace diff --git a/others/matrix_exponentiation.cpp b/others/matrix_exponentiation.cpp index bde7f521bbc..eec75fdfb90 100644 --- a/others/matrix_exponentiation.cpp +++ b/others/matrix_exponentiation.cpp @@ -22,8 +22,9 @@ Steps for Matrix Expo The first element of this matrix is the required result. */ -#include -#include +#include // for int64_t +#include // for basic_istream, char_traits, cin, basic_ostream +#include // for vector using std::cin; using std::cout; diff --git a/others/palindrome_of_number.cpp b/others/palindrome_of_number.cpp index 66401ff966a..241dcacf946 100644 --- a/others/palindrome_of_number.cpp +++ b/others/palindrome_of_number.cpp @@ -5,14 +5,14 @@ * * This program cheats by using the STL library's std::reverse function. */ -#include -#include +#include // for reverse +#include // for operator<<, basic_ostream, cout, basic_istream:... +#include // for basic_string, allocator, operator==, string #ifdef _MSC_VER // Required to compile std::toString function using MSVC -#include +#include // for basic_string, allocator, operator==, string #else -#include #endif /** Main function */ diff --git a/others/paranthesis_matching.cpp b/others/paranthesis_matching.cpp index d9c52c813a0..6456d9d522e 100644 --- a/others/paranthesis_matching.cpp +++ b/others/paranthesis_matching.cpp @@ -5,11 +5,11 @@ * @note Implementation is C-type and does not utilize the C++ constructs * @todo implement as a C++ class */ -#include +#include // for operator<<, basic_ostream, cout, basic_istream, cin +#include // for basic_string, operator>>, string #ifdef _MSC_VER -#include // Visual Studio C requires this include +#include // for basic_string, operator>>, string #else -#include #endif /** check number */ diff --git a/others/postfix_evaluation.cpp b/others/postfix_evaluation.cpp index 1ea77c6f8a5..1b45288db0e 100644 --- a/others/postfix_evaluation.cpp +++ b/others/postfix_evaluation.cpp @@ -10,11 +10,13 @@ * Evaluate the operator and push the result back to the stack * When the expression is ended, the number in the stack is the final answer */ +#include // for isdigit #include // for all_of -#include // for std::array +#include // for array #include // for assert -#include // for io operations -#include // for stof +#include // for operator<<, basic_ostream, cout +#include // for basic_string, char_traits, string, stof +#include // for size_t /** * @namespace others diff --git a/others/smallest_circle.cpp b/others/smallest_circle.cpp index 9ee4353eb4e..0c5879d63b4 100644 --- a/others/smallest_circle.cpp +++ b/others/smallest_circle.cpp @@ -7,9 +7,10 @@ * @see [other * implementation](https://www.nayuki.io/page/smallest-enclosing-circle) */ -#include -#include -#include +#include // for sqrt, INFINITY +#include // for size_t +#include // for basic_ostream, char_traits, cout, endl, operator<< +#include // for vector /** Define a point */ struct Point { From 5dd7f82a34501dc48b985c9fe4822cfa2ef125c2 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:39:18 +0530 Subject: [PATCH 049/131] chore: use iwyu on probablity/**.cpp --- probability/geometric_dist.cpp | 17 +++++++++-------- probability/windowed_median.cpp | 13 +++++++------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/probability/geometric_dist.cpp b/probability/geometric_dist.cpp index a9bc7aeb6ed..16a8edfb2f1 100644 --- a/probability/geometric_dist.cpp +++ b/probability/geometric_dist.cpp @@ -19,14 +19,15 @@ * @author [Domenic Zingsheim](https://github.com/DerAndereDomenic) */ -#include /// for assert -#include /// for math functions -#include /// for fixed size data types -#include /// for time to initialize rng -#include /// for std::cout -#include /// for std::numeric_limits -#include /// for random numbers -#include /// for std::vector +#include // for abs +#include // for rand, srand, RAND_MAX +#include // for assert +#include // for log, pow, sqrt +#include // for uint32_t +#include // for time +#include // for basic_ostream, char_traits, operator<<, cout +#include // for numeric_limits +#include // for vector /** * @namespace probability diff --git a/probability/windowed_median.cpp b/probability/windowed_median.cpp index 52c70ae2487..5998d90f445 100644 --- a/probability/windowed_median.cpp +++ b/probability/windowed_median.cpp @@ -28,12 +28,13 @@ * Time complexity: O(logN). Space complexity: O(N). N - size of window * @author [Yaniv Hollander](https://github.com/YanivHollander) */ -#include /// for assert -#include /// for std::rand - needed in testing -#include /// for std::time - needed in testing -#include /// for std::list - used to manage sliding window -#include /// for std::multiset - used to manage multi-value sorted sliding window values -#include /// for std::vector - needed in testing +#include // for assert +#include // for rand, RAND_MAX, srand +#include // for time +#include // for _List_iterator, list +#include // for _Rb_tree_const_iterator, multiset +#include // for vector +#include // for next /** * @namespace probability From 19d136ae0fe13798b58b74a7932ce4c7a3950453 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:39:30 +0530 Subject: [PATCH 050/131] chore: use iwyu on search/**.cpp --- search/exponential_search.cpp | 9 ++++----- search/fibonacci_search.cpp | 9 ++++----- search/hash_search.cpp | 8 ++------ search/saddleback_search.cpp | 8 ++++---- search/sublist_search.cpp | 9 +++++---- search/text_search.cpp | 10 +++++----- 6 files changed, 24 insertions(+), 29 deletions(-) diff --git a/search/exponential_search.cpp b/search/exponential_search.cpp index c8370580af3..bd3671eda64 100644 --- a/search/exponential_search.cpp +++ b/search/exponential_search.cpp @@ -12,14 +12,13 @@ * algorithm return null ponter, every other cases the algoritm return fom the * loop. */ -#include -#include -#include -#include /// for integral typedefs +#include // for assert +#include // for floor +#include // for int32_t, uint32_t #ifdef _MSC_VER #include // use for MS Visual C++ #else -#include // for all other compilers +#include // for size_t #endif /** Binary Search Algorithm (used by ::struzik_search)\n diff --git a/search/fibonacci_search.cpp b/search/fibonacci_search.cpp index be181a47d0e..d01fdbc031e 100644 --- a/search/fibonacci_search.cpp +++ b/search/fibonacci_search.cpp @@ -5,11 +5,10 @@ * algorithm](https://en.wikipedia.org/wiki/Fibonacci_search_technique) */ -#include -#include // for std::vector class -#include // for assert -#include // for random numbers -#include // for sorting +#include // for vector +#include // for assert +#include // for rand +#include // for find, sort, min, remove diff --git a/search/hash_search.cpp b/search/hash_search.cpp index 6e4caffc30e..905c7281523 100644 --- a/search/hash_search.cpp +++ b/search/hash_search.cpp @@ -15,18 +15,14 @@ * @todo fix the program for memory leaks and better structure in C++ and not C * fashion */ -#include -#include +#include // for NULL, malloc +#include // for basic_ostream, operator<<, char_traits, basic_os... #define MAX 6 ///< Determines how much data #define HASHMAX 5 ///< Determines the length of the hash table int data[MAX] = {1, 10, 15, 5, 8, 7}; //!< test data -/** - * a one-way linked list - */ -typedef struct list { int key; //!< key value for node struct list* next; //!< pointer to next link in the chain } node, /**< define node as one item list */ diff --git a/search/saddleback_search.cpp b/search/saddleback_search.cpp index 4f2a5606d2f..12ce9c307d5 100644 --- a/search/saddleback_search.cpp +++ b/search/saddleback_search.cpp @@ -12,10 +12,10 @@ * * @author [Hashir Niazi](https://github.com/HashirGJ8842) */ -#include /// for assert -#include /// for integral typedefs -#include /// for io operations, and std::pair -#include /// for std::vector +#include // for assert +#include // for uint32_t, int32_t +#include // for vector +#include // for pair, make_pair, operator== /** \namespace search * \brief Algorithms for searching diff --git a/search/sublist_search.cpp b/search/sublist_search.cpp index 7b485f04184..6058e643eaf 100644 --- a/search/sublist_search.cpp +++ b/search/sublist_search.cpp @@ -25,10 +25,11 @@ * @author [Nitin Sharma](https://github.com/foo290) */ -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations -#include /// for std::vector +#include // for assert +#include // for NULL +#include // for uint64_t, uint32_t +#include // for basic_ostream, operator<<, cout, char_traits, endl +#include // for vector /** * @namespace search diff --git a/search/text_search.cpp b/search/text_search.cpp index 291b1df85dc..3e1140487e9 100644 --- a/search/text_search.cpp +++ b/search/text_search.cpp @@ -2,13 +2,13 @@ * \file * \brief Search for words in a long textual paragraph. */ -#include -#include -#include +#include // for tolower +#include // for assert +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for basic_string, operator<<, string, getline #ifdef _MSC_VER -#include // required for MS Visual C++ +#include // for basic_string, operator<<, string, getline #else -#include #endif /** From a290ae7ee2bc73c32348aa74ef622794d02d4938 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:39:40 +0530 Subject: [PATCH 051/131] chore: use iwyu on sorting/**.cpp --- sorting/binary_insertion_sort.cpp | 10 +++-- sorting/bitonic_sort.cpp | 4 +- sorting/bogo_sort.cpp | 11 +++--- sorting/bubble_sort.cpp | 5 ++- sorting/cocktail_selection_sort.cpp | 6 +-- sorting/comb_sort.cpp | 7 ++-- sorting/counting_sort_string.cpp | 3 +- sorting/cycle_sort.cpp | 13 ++++--- sorting/dnf_sort.cpp | 12 +++--- sorting/gnome_sort.cpp | 11 ++++-- sorting/heap_sort.cpp | 7 ++-- sorting/insertion_sort.cpp | 11 ++++-- sorting/library_sort.cpp | 5 ++- sorting/merge_insertion_sort.cpp | 13 ++++--- sorting/non_recursive_merge_sort.cpp | 7 ++-- sorting/odd_even_sort.cpp | 5 ++- sorting/pigeonhole_sort.cpp | 10 +++-- sorting/quick_sort.cpp | 15 +++++--- sorting/quick_sort_3.cpp | 14 ++++--- sorting/quick_sort_iterative.cpp | 12 +++--- sorting/radix_sort.cpp | 7 ++-- sorting/random_pivot_quick_sort.cpp | 15 +++++--- sorting/recursive_bubble_sort.cpp | 13 ++++--- sorting/selection_sort_recursive.cpp | 12 +++--- sorting/shell_sort2.cpp | 11 +++--- sorting/stooge_sort.cpp | 57 +++++++++++++++------------- sorting/tim_sort.cpp | 9 +++-- sorting/wave_sort.cpp | 10 +++-- sorting/wiggle_sort.cpp | 13 ++++--- 29 files changed, 186 insertions(+), 142 deletions(-) diff --git a/sorting/binary_insertion_sort.cpp b/sorting/binary_insertion_sort.cpp index f0404c6b45a..fbba2ec1e41 100644 --- a/sorting/binary_insertion_sort.cpp +++ b/sorting/binary_insertion_sort.cpp @@ -39,10 +39,12 @@ * \f{bmatrix}{10 &20 &30 &40 &50\f} */ -#include /// for algorithm functions -#include /// for assert -#include /// for IO operations -#include /// for working with vectors +#include // for int64_t +#include // for is_sorted +#include // for assert +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for vector +#include // for begin, end /** * \namespace sorting diff --git a/sorting/bitonic_sort.cpp b/sorting/bitonic_sort.cpp index 0fbb995acfd..a3eb37f2c6e 100644 --- a/sorting/bitonic_sort.cpp +++ b/sorting/bitonic_sort.cpp @@ -3,8 +3,8 @@ /* C++ Program for Bitonic Sort. Note that this program works only when size of input is a power of 2. */ -#include -#include +#include // for char_traits, operator<<, basic_ostream, basic_os... +#include // for swap /*The parameter dir indicates the sorting direction, ASCENDING or DESCENDING; if (a[i] > a[j]) agrees with the direction, diff --git a/sorting/bogo_sort.cpp b/sorting/bogo_sort.cpp index 749eaddd065..b13939286ad 100644 --- a/sorting/bogo_sort.cpp +++ b/sorting/bogo_sort.cpp @@ -14,11 +14,12 @@ * * @author [Deep Raval](https://github.com/imdeep2905) */ -#include -#include -#include -#include -#include +#include // for operator<<, basic_ostream, cout, char_traits +#include // for is_sorted, shuffle +#include // for array +#include // for assert +#include // for random_device, mt19937 +#include // for rand, size_t /** diff --git a/sorting/bubble_sort.cpp b/sorting/bubble_sort.cpp index c43e425fcd9..71e6b528a58 100644 --- a/sorting/bubble_sort.cpp +++ b/sorting/bubble_sort.cpp @@ -37,8 +37,9 @@ can't get the best status in the code we shared above. This happens on the optimized bubble sort algorithm. It's right down there. */ -#include -#include +#include // for char_traits, basic_ostream, operator<<, basic_os... +#include // for vector +#include // for swap int main() { int n; diff --git a/sorting/cocktail_selection_sort.cpp b/sorting/cocktail_selection_sort.cpp index 157acafcecb..6c912cef040 100644 --- a/sorting/cocktail_selection_sort.cpp +++ b/sorting/cocktail_selection_sort.cpp @@ -3,9 +3,9 @@ // array simultaneously, and swaps it with the lowest and highest available // position iteratively or recursively -#include -#include -#include +#include // for operator<<, basic_ostream, char_traits, basic_is... +#include // for vector +#include // for swap // Iterative Version diff --git a/sorting/comb_sort.cpp b/sorting/comb_sort.cpp index 3fee36d6ad0..43125a6dfcb 100644 --- a/sorting/comb_sort.cpp +++ b/sorting/comb_sort.cpp @@ -15,9 +15,10 @@ * */ -#include -#include -#include +#include // for is_sorted, max +#include // for assert +#include // for char_traits, operator<<, basic_istream::operator>> +#include // for swap /** * diff --git a/sorting/counting_sort_string.cpp b/sorting/counting_sort_string.cpp index 69d80c18a32..92f693f08bf 100644 --- a/sorting/counting_sort_string.cpp +++ b/sorting/counting_sort_string.cpp @@ -1,5 +1,6 @@ // C++ Program for counting sort -#include +#include // for char_traits, basic_ostream, operator<<, basic_is... +#include // for basic_string, string, operator<<, operator>> using namespace std; diff --git a/sorting/cycle_sort.cpp b/sorting/cycle_sort.cpp index 1371fac94ea..964419743d6 100644 --- a/sorting/cycle_sort.cpp +++ b/sorting/cycle_sort.cpp @@ -11,11 +11,14 @@ * @author [TsungHan Ho](https://github.com/dalaoqi) */ -#include /// for std::is_sorted, std::swap -#include /// for assert -#include /// for integral typedefs -#include /// for io operations -#include /// for std::vector +#include // for is_sorted +#include // for assert +#include // for size_t +#include // for uint32_t +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for begin, end +#include // for swap +#include // for vector /** * @namespace sorting diff --git a/sorting/dnf_sort.cpp b/sorting/dnf_sort.cpp index 3cdb1c34e36..4e52367d1d4 100644 --- a/sorting/dnf_sort.cpp +++ b/sorting/dnf_sort.cpp @@ -10,11 +10,13 @@ * @author [Sujal Gupta](https://github.com/heysujal) */ -#include /// for std::is_sorted -#include /// for assert -#include /// for integral typedefs -#include /// for std::swap and io operations -#include /// for std::vector +#include // for is_sorted +#include // for assert +#include // for uint64_t +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for vector +#include // for begin, end +#include // for swap /** * @namespace sorting diff --git a/sorting/gnome_sort.cpp b/sorting/gnome_sort.cpp index d56662479f4..5decd52fd54 100644 --- a/sorting/gnome_sort.cpp +++ b/sorting/gnome_sort.cpp @@ -15,10 +15,13 @@ * can be \f$O(n)\f$. */ -#include // for std::swap -#include // for std::array -#include // for assertions -#include // for io operations +#include // for is_sorted +#include // for array +#include // for assert +#include // for operator<<, basic_ostream, cout, char_traits, endl +#include // for rand, size_t +#include // for begin, end +#include // for swap /** * @namespace sorting diff --git a/sorting/heap_sort.cpp b/sorting/heap_sort.cpp index d91cdb14f0c..150f710d03b 100644 --- a/sorting/heap_sort.cpp +++ b/sorting/heap_sort.cpp @@ -20,9 +20,10 @@ * Time Complexity - \f$O(n \log(n))\f$ * */ -#include -#include -#include +#include // for is_sorted +#include // for assert +#include // for operator<<, cout, basic_ostream, basic_ostream:... +#include // for swap /** * diff --git a/sorting/insertion_sort.cpp b/sorting/insertion_sort.cpp index c9bac4bf704..94f4ff58c57 100644 --- a/sorting/insertion_sort.cpp +++ b/sorting/insertion_sort.cpp @@ -39,10 +39,13 @@ * \f{bmatrix}{1 &2 &3 &4 &5\f} */ -#include -#include -#include -#include +#include // for int32_t +#include // for is_sorted +#include // for assert +#include // for operator<<, basic_ostream, cout, char_traits, endl +#include // for vector +#include // for rand, size_t +#include // for begin, end /** \namespace sorting * \brief Sorting algorithms diff --git a/sorting/library_sort.cpp b/sorting/library_sort.cpp index 33f151b296d..c2f5c96ef65 100644 --- a/sorting/library_sort.cpp +++ b/sorting/library_sort.cpp @@ -1,5 +1,6 @@ -#include -#include +#include // for lower_bound +#include // for char_traits, basic_ostream, operator<<, cout +#include // for distance void librarySort(int *index, int n) { int lib_size, index_pos, diff --git a/sorting/merge_insertion_sort.cpp b/sorting/merge_insertion_sort.cpp index 07b2ed19dbd..441989c25d6 100644 --- a/sorting/merge_insertion_sort.cpp +++ b/sorting/merge_insertion_sort.cpp @@ -7,12 +7,13 @@ * * @see Individual algorithms: insertion_sort.cpp and merge_sort.cpp */ -#include -#include -#include -#include -#include -#include +#include // for is_sorted +#include // for array +#include // for assert +#include // for size_t, time +#include // for char_traits, basic_ostream, operator<<, cout +#include // for rand, srand +#include // for begin, end /** \namespace sorting * \brief Sorting algorithms diff --git a/sorting/non_recursive_merge_sort.cpp b/sorting/non_recursive_merge_sort.cpp index b99b931080b..9ab1c744f68 100644 --- a/sorting/non_recursive_merge_sort.cpp +++ b/sorting/non_recursive_merge_sort.cpp @@ -4,9 +4,10 @@ * * A generic implementation of non-recursive merge sort. */ -#include // for size_t -#include -#include // for std::move & std::remove_reference_t +#include // for size_t +#include // for operator<<, basic_ostream, char_traits, basic... +#include // for move +#include // for remove_reference_t namespace sorting { template diff --git a/sorting/odd_even_sort.cpp b/sorting/odd_even_sort.cpp index 25f2a371228..38ce8d0f1ad 100644 --- a/sorting/odd_even_sort.cpp +++ b/sorting/odd_even_sort.cpp @@ -1,6 +1,7 @@ /* C++ implementation Odd Even Sort */ -#include -#include +#include // for operator<<, char_traits, basic_ostream, basic_is... +#include // for vector +#include // for swap using namespace std; diff --git a/sorting/pigeonhole_sort.cpp b/sorting/pigeonhole_sort.cpp index 764365b868c..a560f417b39 100644 --- a/sorting/pigeonhole_sort.cpp +++ b/sorting/pigeonhole_sort.cpp @@ -13,10 +13,12 @@ * The time Complexity of the algorithm is \f$O(n+N)\f$. */ -#include //for std::is_sorted -#include //for std::array -#include //for assert -#include //for io operations +#include // for is_sorted, max_element, min_element +#include // for array +#include // for assert +#include // for operator<<, char_traits, basic_ostream, basic_o... +#include // for size_t +#include // for begin, end /** * @namespace sorting diff --git a/sorting/quick_sort.cpp b/sorting/quick_sort.cpp index 88d01ea1409..d2da9737bae 100644 --- a/sorting/quick_sort.cpp +++ b/sorting/quick_sort.cpp @@ -24,12 +24,15 @@ * @author [popoapp](https://github.com/popoapp) */ -#include /// for std::is_sorted -#include /// for std::assert -#include /// for integral typedefs -#include /// for std::time -#include /// for IO operations -#include /// for std::vector +#include // for is_sorted +#include // for assert +#include // for uint64_t, int64_t +#include // for time, size_t +#include // for operator<<, cout, basic_ostream, basic_istream:... +#include // for vector +#include // for rand, srand, RAND_MAX +#include // for begin, end +#include // for swap /** * @brief Sorting algorithms diff --git a/sorting/quick_sort_3.cpp b/sorting/quick_sort_3.cpp index 72dc44d9b6c..8e212fe257a 100644 --- a/sorting/quick_sort_3.cpp +++ b/sorting/quick_sort_3.cpp @@ -9,11 +9,15 @@ * @author immortal-j * @author [Krishna Vedala](https://github/kvedala) */ -#include -#include -#include -#include -#include +#include // for int32_t +#include // for is_sorted +#include // for assert +#include // for size_t, time +#include // for operator<<, basic_ostream, char_traits, cout +#include // for vector +#include // for rand, srand +#include // for begin, end +#include // for swap namespace { /** diff --git a/sorting/quick_sort_iterative.cpp b/sorting/quick_sort_iterative.cpp index da506c9c024..f6a8751c345 100644 --- a/sorting/quick_sort_iterative.cpp +++ b/sorting/quick_sort_iterative.cpp @@ -10,11 +10,13 @@ * @author [Sebe324](https://github.com/sebe324) */ -#include /// for std::cout -#include /// for std::vector -#include /// for std::stack -#include /// for std::is_sorted -#include /// for assert +#include // for operator<<, basic_ostream, cout, char_traits +#include // for vector +#include // for stack +#include // for is_sorted +#include // for assert +#include // for begin, end +#include // for swap /** diff --git a/sorting/radix_sort.cpp b/sorting/radix_sort.cpp index a0fbfe99ee5..d6e16cc803c 100644 --- a/sorting/radix_sort.cpp +++ b/sorting/radix_sort.cpp @@ -1,7 +1,6 @@ -#include -#include -#include -#include +#include // for pow +#include // for memset +#include // for char_traits, basic_ostream, basic_ostream::opera... void radixsort(int a[], int n) { int count[10]; diff --git a/sorting/random_pivot_quick_sort.cpp b/sorting/random_pivot_quick_sort.cpp index a6ed19f1296..9ea2ede6c0e 100644 --- a/sorting/random_pivot_quick_sort.cpp +++ b/sorting/random_pivot_quick_sort.cpp @@ -44,12 +44,15 @@ * @author [Nitin Sharma](https://github.com/foo290) */ -#include /// for std::is_sorted(), std::swap() -#include /// for std::array -#include /// for assert -#include /// for initializing random number generator -#include /// for IO operations -#include /// for returning multiple values form a function at once +#include // for int64_t +#include // for rand, srand +#include // for is_sorted +#include // for array +#include // for assert +#include // for size_t, time +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for make_tuple, tie, tuple +#include // for swap /** * @namespace sorting diff --git a/sorting/recursive_bubble_sort.cpp b/sorting/recursive_bubble_sort.cpp index 5b860f83319..c5eac9337e6 100644 --- a/sorting/recursive_bubble_sort.cpp +++ b/sorting/recursive_bubble_sort.cpp @@ -57,12 +57,13 @@ * complexity */ -#include /// for std::is_sorted -#include /// for std::array -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations -#include /// for std::vector +#include // for is_sorted +#include // for assert +#include // for uint64_t, int64_t +#include // for operator<<, basic_ostream, char_traits, cout, endl +#include // for vector +#include // for begin, end +#include // for swap /** * @namespace sorting diff --git a/sorting/selection_sort_recursive.cpp b/sorting/selection_sort_recursive.cpp index 765b9709891..7232c5f7bcc 100644 --- a/sorting/selection_sort_recursive.cpp +++ b/sorting/selection_sort_recursive.cpp @@ -27,11 +27,13 @@ * @author [Tushar Khanduri](https://github.com/Tushar-K24) */ -#include /// for std::is_sorted -#include /// for assert -#include /// for integral typedefs -#include /// for std::swap and io operations -#include /// for std::vector +#include // for is_sorted +#include // for assert +#include // for uint64_t +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for vector +#include // for begin, end +#include // for swap /** * @namespace sorting diff --git a/sorting/shell_sort2.cpp b/sorting/shell_sort2.cpp index 5db773aca91..e8abc619fe8 100644 --- a/sorting/shell_sort2.cpp +++ b/sorting/shell_sort2.cpp @@ -3,12 +3,11 @@ * \brief [Shell sort](https://en.wikipedia.org/wiki/Shell_sort) algorithm * \author [Krishna Vedala](https://github.com/kvedala) */ -#include -#include -#include -#include -#include // for std::swap -#include +#include // for assert +#include // for rand, size_t, qsort, srand, NULL, atoi +#include // for clock, clock_t, CLOCKS_PER_SEC, time +#include // for operator<<, basic_ostream, char_traits, cout, endl +#include // for vector /** pretty print array * \param[in] arr array to print diff --git a/sorting/stooge_sort.cpp b/sorting/stooge_sort.cpp index b1f01321ae2..1bb72bdcd6f 100644 --- a/sorting/stooge_sort.cpp +++ b/sorting/stooge_sort.cpp @@ -1,7 +1,7 @@ /** * @file - * @brief [Stooge sort implementation](https://en.wikipedia.org/wiki/Stooge_sort) - * in C++ + * @brief [Stooge sort + *implementation](https://en.wikipedia.org/wiki/Stooge_sort) in C++ * @details * Stooge sort is a recursive sorting algorithm. * It divides the array into 3 parts and proceeds to: @@ -13,18 +13,21 @@ * on the street on average. Space complexity is O(1). */ -#include /// for vector -#include /// for assert -#include /// for std::is_sorted -#include /// for IO operations +#include // for is_sorted +#include // for assert +#include // for size_t +#include // for operator<<, basic_ostream, cout +#include // for begin, end +#include // for swap +#include // for vector - /** - * @brief The stoogeSort() function is used for sorting the array. - * @param L - vector of values (int) to be sorted in in place (ascending order) - * @param i - the first index of the array (0) - * @param j - the last index of the array (L.size() - 1) - * @returns void - */ +/** + * @brief The stoogeSort() function is used for sorting the array. + * @param L - vector of values (int) to be sorted in in place (ascending order) + * @param i - the first index of the array (0) + * @param j - the last index of the array (L.size() - 1) + * @returns void + */ void stoogeSort(std::vector* L, size_t i, size_t j) { if (i >= j) { return; @@ -45,9 +48,9 @@ void stoogeSort(std::vector* L, size_t i, size_t j) { * @returns void */ void test1() { - std::vector L = { 8, 9, 10, 4, 3, 5, 1 }; - stoogeSort(&L, 0, L.size() - 1); - assert(std::is_sorted(std::begin(L), std::end(L))); + std::vector L = {8, 9, 10, 4, 3, 5, 1}; + stoogeSort(&L, 0, L.size() - 1); + assert(std::is_sorted(std::begin(L), std::end(L))); } /** @@ -55,9 +58,9 @@ void test1() { * @returns void */ void test2() { - std::vector L = { -1 }; - stoogeSort(&L, 0, L.size() - 1); - assert(std::is_sorted(std::begin(L), std::end(L))); + std::vector L = {-1}; + stoogeSort(&L, 0, L.size() - 1); + assert(std::is_sorted(std::begin(L), std::end(L))); } /** @@ -65,9 +68,9 @@ void test2() { * @returns void */ void test3() { - std::vector L = { 1, 2, 5, 4, 1, 5 }; - stoogeSort(&L, 0, L.size() - 1); - assert(std::is_sorted(std::begin(L), std::end(L))); + std::vector L = {1, 2, 5, 4, 1, 5}; + stoogeSort(&L, 0, L.size() - 1); + assert(std::is_sorted(std::begin(L), std::end(L))); } /** @@ -77,10 +80,10 @@ void test3() { * @returns 0 on exit */ int main() { - test1(); - test2(); - test3(); - + test1(); + test2(); + test3(); + std::cout << "All tests have successfully passed!\n"; - return 0; + return 0; } diff --git a/sorting/tim_sort.cpp b/sorting/tim_sort.cpp index 03ccf3808e0..51b06eca48a 100644 --- a/sorting/tim_sort.cpp +++ b/sorting/tim_sort.cpp @@ -1,8 +1,9 @@ // C++ program to perform TimSort. -#include -#include -#include -#include +#include // for printf +#include // for min, is_sorted, reverse +#include // for assert +#include // for basic_ostream, cout, endl +#include // for iota const int RUN = 32; diff --git a/sorting/wave_sort.cpp b/sorting/wave_sort.cpp index 85fdb61ad08..7b92f3fed92 100644 --- a/sorting/wave_sort.cpp +++ b/sorting/wave_sort.cpp @@ -8,10 +8,12 @@ * @author [Swastika Gupta](https://github.com/Swastyy) */ -#include /// for std::is_sorted, std::swap -#include /// for assert -#include /// for IO operations -#include /// for std::vector +#include // for int64_t +#include // for sort +#include // for assert +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for vector, operator==, allocator +#include // for swap /** * @namespace sorting diff --git a/sorting/wiggle_sort.cpp b/sorting/wiggle_sort.cpp index fe5009bb428..a0c252cbe65 100644 --- a/sorting/wiggle_sort.cpp +++ b/sorting/wiggle_sort.cpp @@ -17,12 +17,13 @@ * arr = [2,8,9,1,7], after wiggle sort arr will become equal to [8,2,9,1,7] */ -#include -#include -#include /// for integral typedefs -#include -#include /// for io operations -#include +#include // for assert +#include // for uint32_t +#include // for time +#include // for operator<<, basic_ostream, char_traits, cout, endl +#include // for vector +#include // for rand, srand +#include // for swap /** * @namespace sorting From f2127456a8eb3e25fc54f39e129578677838f6a4 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:39:46 +0530 Subject: [PATCH 052/131] chore: use iwyu on strings/**.cpp --- strings/boyer_moore.cpp | 13 +++++++------ strings/brute_force_string_searching.cpp | 9 +++++---- strings/horspool.cpp | 7 ++++--- strings/knuth_morris_pratt.cpp | 9 +++++---- strings/manacher_algorithm.cpp | 13 +++++++------ strings/rabin_karp.cpp | 10 +++++----- strings/z_function.cpp | 12 ++++++------ 7 files changed, 39 insertions(+), 34 deletions(-) diff --git a/strings/boyer_moore.cpp b/strings/boyer_moore.cpp index de79008e326..865969e66ab 100644 --- a/strings/boyer_moore.cpp +++ b/strings/boyer_moore.cpp @@ -42,12 +42,13 @@ * @author [Stoycho Kyosev](https://github.com/stoychoX) */ -#include /// for assert -#include /// for CHAR_MAX macro -#include /// for strlen -#include /// for IO operations -#include /// for std::string -#include /// for std::vector +#include // for assert +#include // for CHAR_MAX +#include // for size_t, strlen +#include // for operator<<, basic_ostream, cout +#include // for basic_string, string +#include // for vector +#include // for max #define APLHABET_SIZE CHAR_MAX ///< number of symbols in the alphabet we use diff --git a/strings/brute_force_string_searching.cpp b/strings/brute_force_string_searching.cpp index f908d83bc03..9051e83adab 100644 --- a/strings/brute_force_string_searching.cpp +++ b/strings/brute_force_string_searching.cpp @@ -2,13 +2,14 @@ * @file * @brief String pattern search - brute force */ -#include +#include // for operator<<, basic_ostream, char_traits, cout +#include // for basic_string, operator==, string, to_string #ifdef _MSC_VER -#include // use this for MS Visual C++ +#include // for basic_string, operator==, string, to_string #else -#include +#include // for size_t #endif -#include +#include // for vector, allocator namespace string_search { /** diff --git a/strings/horspool.cpp b/strings/horspool.cpp index a43be5f0d5e..c409f531024 100644 --- a/strings/horspool.cpp +++ b/strings/horspool.cpp @@ -4,9 +4,10 @@ * @author [Harry Kontakis](https://github.com/ckontakis) */ -#include -#include -#include +#include // for unordered_map, _Node_iterator_base, operator!= +#include // for assert +#include // for basic_string, string +#include // for pair, make_pair /** * @namespace strings diff --git a/strings/knuth_morris_pratt.cpp b/strings/knuth_morris_pratt.cpp index e266d2c179c..084a5044aed 100644 --- a/strings/knuth_morris_pratt.cpp +++ b/strings/knuth_morris_pratt.cpp @@ -13,10 +13,11 @@ * @author [Yancey](https://github.com/Yancey2023) */ -#include /// for assert -#include /// for IO operations -#include /// for std::string -#include /// for std::vector +#include // for assert +#include // for size_t +#include // for operator<<, basic_ostream, cout +#include // for basic_string, string +#include // for vector /** * @namespace string_search diff --git a/strings/manacher_algorithm.cpp b/strings/manacher_algorithm.cpp index 1c1581a3374..1349caabe51 100644 --- a/strings/manacher_algorithm.cpp +++ b/strings/manacher_algorithm.cpp @@ -10,14 +10,15 @@ * @author [Riti Kumari](https://github.com/riti2409) */ -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations -#include /// for std::vector STL +#include // for assert +#include // for uint64_t +#include // for char_traits, basic_ostream, operator<<, cout, endl +#include // for allocator, vector +#include // for min +#include // for basic_string, operator==, operator+, string #ifdef _MSC_VER -#include /// for string (required for MS Visual C++) +#include // for basic_string, operator==, operator+, string #else -#include /// for string #endif /** diff --git a/strings/rabin_karp.cpp b/strings/rabin_karp.cpp index 91e104188cc..27d57a96c27 100644 --- a/strings/rabin_karp.cpp +++ b/strings/rabin_karp.cpp @@ -4,13 +4,13 @@ * Algorithm](https://en.wikipedia.org/wiki/Rabin–Karp_algorithm) for finding a * pattern within a piece of text with complexity O(n + m) */ -#include -#include -#include +#include // for int64_t +#include // for assert +#include // for pow +#include // for basic_string, string #ifdef _MSC_VER -#include // use this for MS Visucal C++ +#include // for basic_string, string #else -#include #endif #define PRIME 5 ///< Prime modulus for hash functions diff --git a/strings/z_function.cpp b/strings/z_function.cpp index 25a5755a7f7..b22197b19be 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -11,15 +11,15 @@ * @author [Ritika Gupta](https://github.com/RitikaGupta8734) */ -#include /// for integral typedefs -#include /// for IO operations +#include // for uint64_t +#include // for min +#include // for basic_string, string, operator+, char_traits #ifdef _MSC_VER -#include /// for string (use this for MS Visual C++) +#include // for basic_string, string, operator+, char_traits #else -#include /// for string #endif -#include /// for assert -#include /// for std::vector +#include // for assert +#include // for vector, allocator, operator== /** * @brief Generate the Z-function for the inputted string. From 00c5e915fd087a43bb391b0c38294c2b5882aee0 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:44:57 +0530 Subject: [PATCH 053/131] Revert "chore: use iwyu on strings/**.cpp" This reverts commit f2127456a8eb3e25fc54f39e129578677838f6a4. --- strings/boyer_moore.cpp | 13 ++++++------- strings/brute_force_string_searching.cpp | 9 ++++----- strings/horspool.cpp | 7 +++---- strings/knuth_morris_pratt.cpp | 9 ++++----- strings/manacher_algorithm.cpp | 13 ++++++------- strings/rabin_karp.cpp | 10 +++++----- strings/z_function.cpp | 12 ++++++------ 7 files changed, 34 insertions(+), 39 deletions(-) diff --git a/strings/boyer_moore.cpp b/strings/boyer_moore.cpp index 865969e66ab..de79008e326 100644 --- a/strings/boyer_moore.cpp +++ b/strings/boyer_moore.cpp @@ -42,13 +42,12 @@ * @author [Stoycho Kyosev](https://github.com/stoychoX) */ -#include // for assert -#include // for CHAR_MAX -#include // for size_t, strlen -#include // for operator<<, basic_ostream, cout -#include // for basic_string, string -#include // for vector -#include // for max +#include /// for assert +#include /// for CHAR_MAX macro +#include /// for strlen +#include /// for IO operations +#include /// for std::string +#include /// for std::vector #define APLHABET_SIZE CHAR_MAX ///< number of symbols in the alphabet we use diff --git a/strings/brute_force_string_searching.cpp b/strings/brute_force_string_searching.cpp index 9051e83adab..f908d83bc03 100644 --- a/strings/brute_force_string_searching.cpp +++ b/strings/brute_force_string_searching.cpp @@ -2,14 +2,13 @@ * @file * @brief String pattern search - brute force */ -#include // for operator<<, basic_ostream, char_traits, cout -#include // for basic_string, operator==, string, to_string +#include #ifdef _MSC_VER -#include // for basic_string, operator==, string, to_string +#include // use this for MS Visual C++ #else -#include // for size_t +#include #endif -#include // for vector, allocator +#include namespace string_search { /** diff --git a/strings/horspool.cpp b/strings/horspool.cpp index c409f531024..a43be5f0d5e 100644 --- a/strings/horspool.cpp +++ b/strings/horspool.cpp @@ -4,10 +4,9 @@ * @author [Harry Kontakis](https://github.com/ckontakis) */ -#include // for unordered_map, _Node_iterator_base, operator!= -#include // for assert -#include // for basic_string, string -#include // for pair, make_pair +#include +#include +#include /** * @namespace strings diff --git a/strings/knuth_morris_pratt.cpp b/strings/knuth_morris_pratt.cpp index 084a5044aed..e266d2c179c 100644 --- a/strings/knuth_morris_pratt.cpp +++ b/strings/knuth_morris_pratt.cpp @@ -13,11 +13,10 @@ * @author [Yancey](https://github.com/Yancey2023) */ -#include // for assert -#include // for size_t -#include // for operator<<, basic_ostream, cout -#include // for basic_string, string -#include // for vector +#include /// for assert +#include /// for IO operations +#include /// for std::string +#include /// for std::vector /** * @namespace string_search diff --git a/strings/manacher_algorithm.cpp b/strings/manacher_algorithm.cpp index 1349caabe51..1c1581a3374 100644 --- a/strings/manacher_algorithm.cpp +++ b/strings/manacher_algorithm.cpp @@ -10,15 +10,14 @@ * @author [Riti Kumari](https://github.com/riti2409) */ -#include // for assert -#include // for uint64_t -#include // for char_traits, basic_ostream, operator<<, cout, endl -#include // for allocator, vector -#include // for min -#include // for basic_string, operator==, operator+, string +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations +#include /// for std::vector STL #ifdef _MSC_VER -#include // for basic_string, operator==, operator+, string +#include /// for string (required for MS Visual C++) #else +#include /// for string #endif /** diff --git a/strings/rabin_karp.cpp b/strings/rabin_karp.cpp index 27d57a96c27..91e104188cc 100644 --- a/strings/rabin_karp.cpp +++ b/strings/rabin_karp.cpp @@ -4,13 +4,13 @@ * Algorithm](https://en.wikipedia.org/wiki/Rabin–Karp_algorithm) for finding a * pattern within a piece of text with complexity O(n + m) */ -#include // for int64_t -#include // for assert -#include // for pow -#include // for basic_string, string +#include +#include +#include #ifdef _MSC_VER -#include // for basic_string, string +#include // use this for MS Visucal C++ #else +#include #endif #define PRIME 5 ///< Prime modulus for hash functions diff --git a/strings/z_function.cpp b/strings/z_function.cpp index b22197b19be..25a5755a7f7 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -11,15 +11,15 @@ * @author [Ritika Gupta](https://github.com/RitikaGupta8734) */ -#include // for uint64_t -#include // for min -#include // for basic_string, string, operator+, char_traits +#include /// for integral typedefs +#include /// for IO operations #ifdef _MSC_VER -#include // for basic_string, string, operator+, char_traits +#include /// for string (use this for MS Visual C++) #else +#include /// for string #endif -#include // for assert -#include // for vector, allocator, operator== +#include /// for assert +#include /// for std::vector /** * @brief Generate the Z-function for the inputted string. From cb6eaeda28b1907a6fc3519899491111833bf65d Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:45:55 +0530 Subject: [PATCH 054/131] Revert "chore: use iwyu on sorting/**.cpp" This reverts commit a290ae7ee2bc73c32348aa74ef622794d02d4938. --- sorting/binary_insertion_sort.cpp | 10 ++--- sorting/bitonic_sort.cpp | 4 +- sorting/bogo_sort.cpp | 11 +++--- sorting/bubble_sort.cpp | 5 +-- sorting/cocktail_selection_sort.cpp | 6 +-- sorting/comb_sort.cpp | 7 ++-- sorting/counting_sort_string.cpp | 3 +- sorting/cycle_sort.cpp | 13 +++---- sorting/dnf_sort.cpp | 12 +++--- sorting/gnome_sort.cpp | 11 ++---- sorting/heap_sort.cpp | 7 ++-- sorting/insertion_sort.cpp | 11 ++---- sorting/library_sort.cpp | 5 +-- sorting/merge_insertion_sort.cpp | 13 +++---- sorting/non_recursive_merge_sort.cpp | 7 ++-- sorting/odd_even_sort.cpp | 5 +-- sorting/pigeonhole_sort.cpp | 10 ++--- sorting/quick_sort.cpp | 15 +++----- sorting/quick_sort_3.cpp | 14 +++---- sorting/quick_sort_iterative.cpp | 12 +++--- sorting/radix_sort.cpp | 7 ++-- sorting/random_pivot_quick_sort.cpp | 15 +++----- sorting/recursive_bubble_sort.cpp | 13 +++---- sorting/selection_sort_recursive.cpp | 12 +++--- sorting/shell_sort2.cpp | 11 +++--- sorting/stooge_sort.cpp | 57 +++++++++++++--------------- sorting/tim_sort.cpp | 9 ++--- sorting/wave_sort.cpp | 10 ++--- sorting/wiggle_sort.cpp | 13 +++---- 29 files changed, 142 insertions(+), 186 deletions(-) diff --git a/sorting/binary_insertion_sort.cpp b/sorting/binary_insertion_sort.cpp index fbba2ec1e41..f0404c6b45a 100644 --- a/sorting/binary_insertion_sort.cpp +++ b/sorting/binary_insertion_sort.cpp @@ -39,12 +39,10 @@ * \f{bmatrix}{10 &20 &30 &40 &50\f} */ -#include // for int64_t -#include // for is_sorted -#include // for assert -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for vector -#include // for begin, end +#include /// for algorithm functions +#include /// for assert +#include /// for IO operations +#include /// for working with vectors /** * \namespace sorting diff --git a/sorting/bitonic_sort.cpp b/sorting/bitonic_sort.cpp index a3eb37f2c6e..0fbb995acfd 100644 --- a/sorting/bitonic_sort.cpp +++ b/sorting/bitonic_sort.cpp @@ -3,8 +3,8 @@ /* C++ Program for Bitonic Sort. Note that this program works only when size of input is a power of 2. */ -#include // for char_traits, operator<<, basic_ostream, basic_os... -#include // for swap +#include +#include /*The parameter dir indicates the sorting direction, ASCENDING or DESCENDING; if (a[i] > a[j]) agrees with the direction, diff --git a/sorting/bogo_sort.cpp b/sorting/bogo_sort.cpp index b13939286ad..749eaddd065 100644 --- a/sorting/bogo_sort.cpp +++ b/sorting/bogo_sort.cpp @@ -14,12 +14,11 @@ * * @author [Deep Raval](https://github.com/imdeep2905) */ -#include // for operator<<, basic_ostream, cout, char_traits -#include // for is_sorted, shuffle -#include // for array -#include // for assert -#include // for random_device, mt19937 -#include // for rand, size_t +#include +#include +#include +#include +#include /** diff --git a/sorting/bubble_sort.cpp b/sorting/bubble_sort.cpp index 71e6b528a58..c43e425fcd9 100644 --- a/sorting/bubble_sort.cpp +++ b/sorting/bubble_sort.cpp @@ -37,9 +37,8 @@ can't get the best status in the code we shared above. This happens on the optimized bubble sort algorithm. It's right down there. */ -#include // for char_traits, basic_ostream, operator<<, basic_os... -#include // for vector -#include // for swap +#include +#include int main() { int n; diff --git a/sorting/cocktail_selection_sort.cpp b/sorting/cocktail_selection_sort.cpp index 6c912cef040..157acafcecb 100644 --- a/sorting/cocktail_selection_sort.cpp +++ b/sorting/cocktail_selection_sort.cpp @@ -3,9 +3,9 @@ // array simultaneously, and swaps it with the lowest and highest available // position iteratively or recursively -#include // for operator<<, basic_ostream, char_traits, basic_is... -#include // for vector -#include // for swap +#include +#include +#include // Iterative Version diff --git a/sorting/comb_sort.cpp b/sorting/comb_sort.cpp index 43125a6dfcb..3fee36d6ad0 100644 --- a/sorting/comb_sort.cpp +++ b/sorting/comb_sort.cpp @@ -15,10 +15,9 @@ * */ -#include // for is_sorted, max -#include // for assert -#include // for char_traits, operator<<, basic_istream::operator>> -#include // for swap +#include +#include +#include /** * diff --git a/sorting/counting_sort_string.cpp b/sorting/counting_sort_string.cpp index 92f693f08bf..69d80c18a32 100644 --- a/sorting/counting_sort_string.cpp +++ b/sorting/counting_sort_string.cpp @@ -1,6 +1,5 @@ // C++ Program for counting sort -#include // for char_traits, basic_ostream, operator<<, basic_is... -#include // for basic_string, string, operator<<, operator>> +#include using namespace std; diff --git a/sorting/cycle_sort.cpp b/sorting/cycle_sort.cpp index 964419743d6..1371fac94ea 100644 --- a/sorting/cycle_sort.cpp +++ b/sorting/cycle_sort.cpp @@ -11,14 +11,11 @@ * @author [TsungHan Ho](https://github.com/dalaoqi) */ -#include // for is_sorted -#include // for assert -#include // for size_t -#include // for uint32_t -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for begin, end -#include // for swap -#include // for vector +#include /// for std::is_sorted, std::swap +#include /// for assert +#include /// for integral typedefs +#include /// for io operations +#include /// for std::vector /** * @namespace sorting diff --git a/sorting/dnf_sort.cpp b/sorting/dnf_sort.cpp index 4e52367d1d4..3cdb1c34e36 100644 --- a/sorting/dnf_sort.cpp +++ b/sorting/dnf_sort.cpp @@ -10,13 +10,11 @@ * @author [Sujal Gupta](https://github.com/heysujal) */ -#include // for is_sorted -#include // for assert -#include // for uint64_t -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for vector -#include // for begin, end -#include // for swap +#include /// for std::is_sorted +#include /// for assert +#include /// for integral typedefs +#include /// for std::swap and io operations +#include /// for std::vector /** * @namespace sorting diff --git a/sorting/gnome_sort.cpp b/sorting/gnome_sort.cpp index 5decd52fd54..d56662479f4 100644 --- a/sorting/gnome_sort.cpp +++ b/sorting/gnome_sort.cpp @@ -15,13 +15,10 @@ * can be \f$O(n)\f$. */ -#include // for is_sorted -#include // for array -#include // for assert -#include // for operator<<, basic_ostream, cout, char_traits, endl -#include // for rand, size_t -#include // for begin, end -#include // for swap +#include // for std::swap +#include // for std::array +#include // for assertions +#include // for io operations /** * @namespace sorting diff --git a/sorting/heap_sort.cpp b/sorting/heap_sort.cpp index 150f710d03b..d91cdb14f0c 100644 --- a/sorting/heap_sort.cpp +++ b/sorting/heap_sort.cpp @@ -20,10 +20,9 @@ * Time Complexity - \f$O(n \log(n))\f$ * */ -#include // for is_sorted -#include // for assert -#include // for operator<<, cout, basic_ostream, basic_ostream:... -#include // for swap +#include +#include +#include /** * diff --git a/sorting/insertion_sort.cpp b/sorting/insertion_sort.cpp index 94f4ff58c57..c9bac4bf704 100644 --- a/sorting/insertion_sort.cpp +++ b/sorting/insertion_sort.cpp @@ -39,13 +39,10 @@ * \f{bmatrix}{1 &2 &3 &4 &5\f} */ -#include // for int32_t -#include // for is_sorted -#include // for assert -#include // for operator<<, basic_ostream, cout, char_traits, endl -#include // for vector -#include // for rand, size_t -#include // for begin, end +#include +#include +#include +#include /** \namespace sorting * \brief Sorting algorithms diff --git a/sorting/library_sort.cpp b/sorting/library_sort.cpp index c2f5c96ef65..33f151b296d 100644 --- a/sorting/library_sort.cpp +++ b/sorting/library_sort.cpp @@ -1,6 +1,5 @@ -#include // for lower_bound -#include // for char_traits, basic_ostream, operator<<, cout -#include // for distance +#include +#include void librarySort(int *index, int n) { int lib_size, index_pos, diff --git a/sorting/merge_insertion_sort.cpp b/sorting/merge_insertion_sort.cpp index 441989c25d6..07b2ed19dbd 100644 --- a/sorting/merge_insertion_sort.cpp +++ b/sorting/merge_insertion_sort.cpp @@ -7,13 +7,12 @@ * * @see Individual algorithms: insertion_sort.cpp and merge_sort.cpp */ -#include // for is_sorted -#include // for array -#include // for assert -#include // for size_t, time -#include // for char_traits, basic_ostream, operator<<, cout -#include // for rand, srand -#include // for begin, end +#include +#include +#include +#include +#include +#include /** \namespace sorting * \brief Sorting algorithms diff --git a/sorting/non_recursive_merge_sort.cpp b/sorting/non_recursive_merge_sort.cpp index 9ab1c744f68..b99b931080b 100644 --- a/sorting/non_recursive_merge_sort.cpp +++ b/sorting/non_recursive_merge_sort.cpp @@ -4,10 +4,9 @@ * * A generic implementation of non-recursive merge sort. */ -#include // for size_t -#include // for operator<<, basic_ostream, char_traits, basic... -#include // for move -#include // for remove_reference_t +#include // for size_t +#include +#include // for std::move & std::remove_reference_t namespace sorting { template diff --git a/sorting/odd_even_sort.cpp b/sorting/odd_even_sort.cpp index 38ce8d0f1ad..25f2a371228 100644 --- a/sorting/odd_even_sort.cpp +++ b/sorting/odd_even_sort.cpp @@ -1,7 +1,6 @@ /* C++ implementation Odd Even Sort */ -#include // for operator<<, char_traits, basic_ostream, basic_is... -#include // for vector -#include // for swap +#include +#include using namespace std; diff --git a/sorting/pigeonhole_sort.cpp b/sorting/pigeonhole_sort.cpp index a560f417b39..764365b868c 100644 --- a/sorting/pigeonhole_sort.cpp +++ b/sorting/pigeonhole_sort.cpp @@ -13,12 +13,10 @@ * The time Complexity of the algorithm is \f$O(n+N)\f$. */ -#include // for is_sorted, max_element, min_element -#include // for array -#include // for assert -#include // for operator<<, char_traits, basic_ostream, basic_o... -#include // for size_t -#include // for begin, end +#include //for std::is_sorted +#include //for std::array +#include //for assert +#include //for io operations /** * @namespace sorting diff --git a/sorting/quick_sort.cpp b/sorting/quick_sort.cpp index d2da9737bae..88d01ea1409 100644 --- a/sorting/quick_sort.cpp +++ b/sorting/quick_sort.cpp @@ -24,15 +24,12 @@ * @author [popoapp](https://github.com/popoapp) */ -#include // for is_sorted -#include // for assert -#include // for uint64_t, int64_t -#include // for time, size_t -#include // for operator<<, cout, basic_ostream, basic_istream:... -#include // for vector -#include // for rand, srand, RAND_MAX -#include // for begin, end -#include // for swap +#include /// for std::is_sorted +#include /// for std::assert +#include /// for integral typedefs +#include /// for std::time +#include /// for IO operations +#include /// for std::vector /** * @brief Sorting algorithms diff --git a/sorting/quick_sort_3.cpp b/sorting/quick_sort_3.cpp index 8e212fe257a..72dc44d9b6c 100644 --- a/sorting/quick_sort_3.cpp +++ b/sorting/quick_sort_3.cpp @@ -9,15 +9,11 @@ * @author immortal-j * @author [Krishna Vedala](https://github/kvedala) */ -#include // for int32_t -#include // for is_sorted -#include // for assert -#include // for size_t, time -#include // for operator<<, basic_ostream, char_traits, cout -#include // for vector -#include // for rand, srand -#include // for begin, end -#include // for swap +#include +#include +#include +#include +#include namespace { /** diff --git a/sorting/quick_sort_iterative.cpp b/sorting/quick_sort_iterative.cpp index f6a8751c345..da506c9c024 100644 --- a/sorting/quick_sort_iterative.cpp +++ b/sorting/quick_sort_iterative.cpp @@ -10,13 +10,11 @@ * @author [Sebe324](https://github.com/sebe324) */ -#include // for operator<<, basic_ostream, cout, char_traits -#include // for vector -#include // for stack -#include // for is_sorted -#include // for assert -#include // for begin, end -#include // for swap +#include /// for std::cout +#include /// for std::vector +#include /// for std::stack +#include /// for std::is_sorted +#include /// for assert /** diff --git a/sorting/radix_sort.cpp b/sorting/radix_sort.cpp index d6e16cc803c..a0fbfe99ee5 100644 --- a/sorting/radix_sort.cpp +++ b/sorting/radix_sort.cpp @@ -1,6 +1,7 @@ -#include // for pow -#include // for memset -#include // for char_traits, basic_ostream, basic_ostream::opera... +#include +#include +#include +#include void radixsort(int a[], int n) { int count[10]; diff --git a/sorting/random_pivot_quick_sort.cpp b/sorting/random_pivot_quick_sort.cpp index 9ea2ede6c0e..a6ed19f1296 100644 --- a/sorting/random_pivot_quick_sort.cpp +++ b/sorting/random_pivot_quick_sort.cpp @@ -44,15 +44,12 @@ * @author [Nitin Sharma](https://github.com/foo290) */ -#include // for int64_t -#include // for rand, srand -#include // for is_sorted -#include // for array -#include // for assert -#include // for size_t, time -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for make_tuple, tie, tuple -#include // for swap +#include /// for std::is_sorted(), std::swap() +#include /// for std::array +#include /// for assert +#include /// for initializing random number generator +#include /// for IO operations +#include /// for returning multiple values form a function at once /** * @namespace sorting diff --git a/sorting/recursive_bubble_sort.cpp b/sorting/recursive_bubble_sort.cpp index c5eac9337e6..5b860f83319 100644 --- a/sorting/recursive_bubble_sort.cpp +++ b/sorting/recursive_bubble_sort.cpp @@ -57,13 +57,12 @@ * complexity */ -#include // for is_sorted -#include // for assert -#include // for uint64_t, int64_t -#include // for operator<<, basic_ostream, char_traits, cout, endl -#include // for vector -#include // for begin, end -#include // for swap +#include /// for std::is_sorted +#include /// for std::array +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations +#include /// for std::vector /** * @namespace sorting diff --git a/sorting/selection_sort_recursive.cpp b/sorting/selection_sort_recursive.cpp index 7232c5f7bcc..765b9709891 100644 --- a/sorting/selection_sort_recursive.cpp +++ b/sorting/selection_sort_recursive.cpp @@ -27,13 +27,11 @@ * @author [Tushar Khanduri](https://github.com/Tushar-K24) */ -#include // for is_sorted -#include // for assert -#include // for uint64_t -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for vector -#include // for begin, end -#include // for swap +#include /// for std::is_sorted +#include /// for assert +#include /// for integral typedefs +#include /// for std::swap and io operations +#include /// for std::vector /** * @namespace sorting diff --git a/sorting/shell_sort2.cpp b/sorting/shell_sort2.cpp index e8abc619fe8..5db773aca91 100644 --- a/sorting/shell_sort2.cpp +++ b/sorting/shell_sort2.cpp @@ -3,11 +3,12 @@ * \brief [Shell sort](https://en.wikipedia.org/wiki/Shell_sort) algorithm * \author [Krishna Vedala](https://github.com/kvedala) */ -#include // for assert -#include // for rand, size_t, qsort, srand, NULL, atoi -#include // for clock, clock_t, CLOCKS_PER_SEC, time -#include // for operator<<, basic_ostream, char_traits, cout, endl -#include // for vector +#include +#include +#include +#include +#include // for std::swap +#include /** pretty print array * \param[in] arr array to print diff --git a/sorting/stooge_sort.cpp b/sorting/stooge_sort.cpp index 1bb72bdcd6f..b1f01321ae2 100644 --- a/sorting/stooge_sort.cpp +++ b/sorting/stooge_sort.cpp @@ -1,7 +1,7 @@ /** * @file - * @brief [Stooge sort - *implementation](https://en.wikipedia.org/wiki/Stooge_sort) in C++ + * @brief [Stooge sort implementation](https://en.wikipedia.org/wiki/Stooge_sort) + * in C++ * @details * Stooge sort is a recursive sorting algorithm. * It divides the array into 3 parts and proceeds to: @@ -13,21 +13,18 @@ * on the street on average. Space complexity is O(1). */ -#include // for is_sorted -#include // for assert -#include // for size_t -#include // for operator<<, basic_ostream, cout -#include // for begin, end -#include // for swap -#include // for vector +#include /// for vector +#include /// for assert +#include /// for std::is_sorted +#include /// for IO operations -/** - * @brief The stoogeSort() function is used for sorting the array. - * @param L - vector of values (int) to be sorted in in place (ascending order) - * @param i - the first index of the array (0) - * @param j - the last index of the array (L.size() - 1) - * @returns void - */ + /** + * @brief The stoogeSort() function is used for sorting the array. + * @param L - vector of values (int) to be sorted in in place (ascending order) + * @param i - the first index of the array (0) + * @param j - the last index of the array (L.size() - 1) + * @returns void + */ void stoogeSort(std::vector* L, size_t i, size_t j) { if (i >= j) { return; @@ -48,9 +45,9 @@ void stoogeSort(std::vector* L, size_t i, size_t j) { * @returns void */ void test1() { - std::vector L = {8, 9, 10, 4, 3, 5, 1}; - stoogeSort(&L, 0, L.size() - 1); - assert(std::is_sorted(std::begin(L), std::end(L))); + std::vector L = { 8, 9, 10, 4, 3, 5, 1 }; + stoogeSort(&L, 0, L.size() - 1); + assert(std::is_sorted(std::begin(L), std::end(L))); } /** @@ -58,9 +55,9 @@ void test1() { * @returns void */ void test2() { - std::vector L = {-1}; - stoogeSort(&L, 0, L.size() - 1); - assert(std::is_sorted(std::begin(L), std::end(L))); + std::vector L = { -1 }; + stoogeSort(&L, 0, L.size() - 1); + assert(std::is_sorted(std::begin(L), std::end(L))); } /** @@ -68,9 +65,9 @@ void test2() { * @returns void */ void test3() { - std::vector L = {1, 2, 5, 4, 1, 5}; - stoogeSort(&L, 0, L.size() - 1); - assert(std::is_sorted(std::begin(L), std::end(L))); + std::vector L = { 1, 2, 5, 4, 1, 5 }; + stoogeSort(&L, 0, L.size() - 1); + assert(std::is_sorted(std::begin(L), std::end(L))); } /** @@ -80,10 +77,10 @@ void test3() { * @returns 0 on exit */ int main() { - test1(); - test2(); - test3(); - + test1(); + test2(); + test3(); + std::cout << "All tests have successfully passed!\n"; - return 0; + return 0; } diff --git a/sorting/tim_sort.cpp b/sorting/tim_sort.cpp index 51b06eca48a..03ccf3808e0 100644 --- a/sorting/tim_sort.cpp +++ b/sorting/tim_sort.cpp @@ -1,9 +1,8 @@ // C++ program to perform TimSort. -#include // for printf -#include // for min, is_sorted, reverse -#include // for assert -#include // for basic_ostream, cout, endl -#include // for iota +#include +#include +#include +#include const int RUN = 32; diff --git a/sorting/wave_sort.cpp b/sorting/wave_sort.cpp index 7b92f3fed92..85fdb61ad08 100644 --- a/sorting/wave_sort.cpp +++ b/sorting/wave_sort.cpp @@ -8,12 +8,10 @@ * @author [Swastika Gupta](https://github.com/Swastyy) */ -#include // for int64_t -#include // for sort -#include // for assert -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for vector, operator==, allocator -#include // for swap +#include /// for std::is_sorted, std::swap +#include /// for assert +#include /// for IO operations +#include /// for std::vector /** * @namespace sorting diff --git a/sorting/wiggle_sort.cpp b/sorting/wiggle_sort.cpp index a0c252cbe65..fe5009bb428 100644 --- a/sorting/wiggle_sort.cpp +++ b/sorting/wiggle_sort.cpp @@ -17,13 +17,12 @@ * arr = [2,8,9,1,7], after wiggle sort arr will become equal to [8,2,9,1,7] */ -#include // for assert -#include // for uint32_t -#include // for time -#include // for operator<<, basic_ostream, char_traits, cout, endl -#include // for vector -#include // for rand, srand -#include // for swap +#include +#include +#include /// for integral typedefs +#include +#include /// for io operations +#include /** * @namespace sorting From 8e9985887fc981a74f4744a84b4b6285de073db5 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:45:59 +0530 Subject: [PATCH 055/131] Revert "chore: use iwyu on search/**.cpp" This reverts commit 19d136ae0fe13798b58b74a7932ce4c7a3950453. --- search/exponential_search.cpp | 9 +++++---- search/fibonacci_search.cpp | 9 +++++---- search/hash_search.cpp | 8 ++++++-- search/saddleback_search.cpp | 8 ++++---- search/sublist_search.cpp | 9 ++++----- search/text_search.cpp | 10 +++++----- 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/search/exponential_search.cpp b/search/exponential_search.cpp index bd3671eda64..c8370580af3 100644 --- a/search/exponential_search.cpp +++ b/search/exponential_search.cpp @@ -12,13 +12,14 @@ * algorithm return null ponter, every other cases the algoritm return fom the * loop. */ -#include // for assert -#include // for floor -#include // for int32_t, uint32_t +#include +#include +#include +#include /// for integral typedefs #ifdef _MSC_VER #include // use for MS Visual C++ #else -#include // for size_t +#include // for all other compilers #endif /** Binary Search Algorithm (used by ::struzik_search)\n diff --git a/search/fibonacci_search.cpp b/search/fibonacci_search.cpp index d01fdbc031e..be181a47d0e 100644 --- a/search/fibonacci_search.cpp +++ b/search/fibonacci_search.cpp @@ -5,10 +5,11 @@ * algorithm](https://en.wikipedia.org/wiki/Fibonacci_search_technique) */ -#include // for vector -#include // for assert -#include // for rand -#include // for find, sort, min, remove +#include +#include // for std::vector class +#include // for assert +#include // for random numbers +#include // for sorting diff --git a/search/hash_search.cpp b/search/hash_search.cpp index 905c7281523..6e4caffc30e 100644 --- a/search/hash_search.cpp +++ b/search/hash_search.cpp @@ -15,14 +15,18 @@ * @todo fix the program for memory leaks and better structure in C++ and not C * fashion */ -#include // for NULL, malloc -#include // for basic_ostream, operator<<, char_traits, basic_os... +#include +#include #define MAX 6 ///< Determines how much data #define HASHMAX 5 ///< Determines the length of the hash table int data[MAX] = {1, 10, 15, 5, 8, 7}; //!< test data +/** + * a one-way linked list + */ +typedef struct list { int key; //!< key value for node struct list* next; //!< pointer to next link in the chain } node, /**< define node as one item list */ diff --git a/search/saddleback_search.cpp b/search/saddleback_search.cpp index 12ce9c307d5..4f2a5606d2f 100644 --- a/search/saddleback_search.cpp +++ b/search/saddleback_search.cpp @@ -12,10 +12,10 @@ * * @author [Hashir Niazi](https://github.com/HashirGJ8842) */ -#include // for assert -#include // for uint32_t, int32_t -#include // for vector -#include // for pair, make_pair, operator== +#include /// for assert +#include /// for integral typedefs +#include /// for io operations, and std::pair +#include /// for std::vector /** \namespace search * \brief Algorithms for searching diff --git a/search/sublist_search.cpp b/search/sublist_search.cpp index 6058e643eaf..7b485f04184 100644 --- a/search/sublist_search.cpp +++ b/search/sublist_search.cpp @@ -25,11 +25,10 @@ * @author [Nitin Sharma](https://github.com/foo290) */ -#include // for assert -#include // for NULL -#include // for uint64_t, uint32_t -#include // for basic_ostream, operator<<, cout, char_traits, endl -#include // for vector +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations +#include /// for std::vector /** * @namespace search diff --git a/search/text_search.cpp b/search/text_search.cpp index 3e1140487e9..291b1df85dc 100644 --- a/search/text_search.cpp +++ b/search/text_search.cpp @@ -2,13 +2,13 @@ * \file * \brief Search for words in a long textual paragraph. */ -#include // for tolower -#include // for assert -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for basic_string, operator<<, string, getline +#include +#include +#include #ifdef _MSC_VER -#include // for basic_string, operator<<, string, getline +#include // required for MS Visual C++ #else +#include #endif /** From 958088f7982101f8e8211d8e404c0457a2179ee4 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:46:11 +0530 Subject: [PATCH 056/131] Revert "chore: use iwyu on probablity/**.cpp" This reverts commit 5dd7f82a34501dc48b985c9fe4822cfa2ef125c2. --- probability/geometric_dist.cpp | 17 ++++++++--------- probability/windowed_median.cpp | 13 ++++++------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/probability/geometric_dist.cpp b/probability/geometric_dist.cpp index 16a8edfb2f1..a9bc7aeb6ed 100644 --- a/probability/geometric_dist.cpp +++ b/probability/geometric_dist.cpp @@ -19,15 +19,14 @@ * @author [Domenic Zingsheim](https://github.com/DerAndereDomenic) */ -#include // for abs -#include // for rand, srand, RAND_MAX -#include // for assert -#include // for log, pow, sqrt -#include // for uint32_t -#include // for time -#include // for basic_ostream, char_traits, operator<<, cout -#include // for numeric_limits -#include // for vector +#include /// for assert +#include /// for math functions +#include /// for fixed size data types +#include /// for time to initialize rng +#include /// for std::cout +#include /// for std::numeric_limits +#include /// for random numbers +#include /// for std::vector /** * @namespace probability diff --git a/probability/windowed_median.cpp b/probability/windowed_median.cpp index 5998d90f445..52c70ae2487 100644 --- a/probability/windowed_median.cpp +++ b/probability/windowed_median.cpp @@ -28,13 +28,12 @@ * Time complexity: O(logN). Space complexity: O(N). N - size of window * @author [Yaniv Hollander](https://github.com/YanivHollander) */ -#include // for assert -#include // for rand, RAND_MAX, srand -#include // for time -#include // for _List_iterator, list -#include // for _Rb_tree_const_iterator, multiset -#include // for vector -#include // for next +#include /// for assert +#include /// for std::rand - needed in testing +#include /// for std::time - needed in testing +#include /// for std::list - used to manage sliding window +#include /// for std::multiset - used to manage multi-value sorted sliding window values +#include /// for std::vector - needed in testing /** * @namespace probability From 1694bde538fa11ff65cb166045c6f361ca740d8b Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:46:15 +0530 Subject: [PATCH 057/131] Revert "chore: use iwyu on others/**.cpp" This reverts commit 8a8fd42383207c24bee7dbf8f502ceb339b0e63d. --- others/decimal_to_roman_numeral.cpp | 6 ++++-- others/easter.cpp | 5 +++-- others/fast_integer_input.cpp | 3 +-- others/iterative_tree_traversals.cpp | 11 +++++------ others/kadanes3.cpp | 12 +++++------- others/kelvin_to_celsius.cpp | 7 +++---- others/matrix_exponentiation.cpp | 5 ++--- others/palindrome_of_number.cpp | 8 ++++---- others/paranthesis_matching.cpp | 6 +++--- others/postfix_evaluation.cpp | 8 +++----- others/smallest_circle.cpp | 7 +++---- 11 files changed, 36 insertions(+), 42 deletions(-) diff --git a/others/decimal_to_roman_numeral.cpp b/others/decimal_to_roman_numeral.cpp index c44f0af7ae7..ad4aa32c5ad 100644 --- a/others/decimal_to_roman_numeral.cpp +++ b/others/decimal_to_roman_numeral.cpp @@ -4,8 +4,10 @@ * to both Lower case and Upper case Roman Numeral */ -#include // for char_traits, basic_ostream, operator<<, basic_os... -#include // for basic_string, operator+, allocator, string, oper... +#include +#include +#include +#include /** This functions fills a string with character c, n times and returns it * @note This can probably be replace by `memcpy` function. diff --git a/others/easter.cpp b/others/easter.cpp index 639ee18d365..44b10335300 100644 --- a/others/easter.cpp +++ b/others/easter.cpp @@ -17,8 +17,9 @@ * @author [AlternateWalls](https://github.com/AlternateWalls) */ -#include // for assert -#include // for uint64_t +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations /* * @brief Contains information for Easter date diff --git a/others/fast_integer_input.cpp b/others/fast_integer_input.cpp index a3fd4e87cf2..87963c9ad88 100644 --- a/others/fast_integer_input.cpp +++ b/others/fast_integer_input.cpp @@ -3,8 +3,7 @@ * @brief Read integers from stdin continuously as they are entered without * waiting for the `\n` character */ -#include // for char_traits, basic_ostream, basic_ostream::opera... -#include // for getchar +#include /** Function to read the number from stdin. The function reads input until a non * numeric character is entered. diff --git a/others/iterative_tree_traversals.cpp b/others/iterative_tree_traversals.cpp index 2a97fbf3862..11fa1814688 100644 --- a/others/iterative_tree_traversals.cpp +++ b/others/iterative_tree_traversals.cpp @@ -35,12 +35,11 @@ * set of steps until the Stack becomes empty or the current becomes NULL. And * return the result array as the inorder traversal of a tree. */ -#include // for int64_t -#include // for reverse -#include // for assert -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for stack -#include // for vector +#include /// for `reverse` +#include /// for `assert` +#include /// for I/O operations +#include /// for `stack` +#include /// for `vector` /** * @namespace others diff --git a/others/kadanes3.cpp b/others/kadanes3.cpp index b22cb96233b..22c1119c858 100644 --- a/others/kadanes3.cpp +++ b/others/kadanes3.cpp @@ -14,13 +14,11 @@ * @author [Abhijeet Tiwari](https://github.com/thisabhijeet) */ -#include // for array -#include // for assert -#include // for INT_MIN -#include // for int64_t, uint64_t -#include // for operator<<, basic_ostream, cout -#include // for size_t - +#include /// for std::array +#include /// for assert +#include /// for INT_MIN value +#include /// for integral typedefs +#include /// for IO operations /** * @brief Utility function to check the current maximum number * \param arr input array diff --git a/others/kelvin_to_celsius.cpp b/others/kelvin_to_celsius.cpp index 149c19d48f7..b5efdeddf78 100644 --- a/others/kelvin_to_celsius.cpp +++ b/others/kelvin_to_celsius.cpp @@ -17,10 +17,9 @@ * @author [David Leal](https://github.com/Panquesito7) */ -#include // for abs -#include // for assert -#include // for operator<<, basic_ostream, cout -#include // for invalid_argument +#include /// for assert +#include /// for std::abs +#include /// for IO operations /** * @namespace diff --git a/others/matrix_exponentiation.cpp b/others/matrix_exponentiation.cpp index eec75fdfb90..bde7f521bbc 100644 --- a/others/matrix_exponentiation.cpp +++ b/others/matrix_exponentiation.cpp @@ -22,9 +22,8 @@ Steps for Matrix Expo The first element of this matrix is the required result. */ -#include // for int64_t -#include // for basic_istream, char_traits, cin, basic_ostream -#include // for vector +#include +#include using std::cin; using std::cout; diff --git a/others/palindrome_of_number.cpp b/others/palindrome_of_number.cpp index 241dcacf946..66401ff966a 100644 --- a/others/palindrome_of_number.cpp +++ b/others/palindrome_of_number.cpp @@ -5,14 +5,14 @@ * * This program cheats by using the STL library's std::reverse function. */ -#include // for reverse -#include // for operator<<, basic_ostream, cout, basic_istream:... -#include // for basic_string, allocator, operator==, string +#include +#include #ifdef _MSC_VER // Required to compile std::toString function using MSVC -#include // for basic_string, allocator, operator==, string +#include #else +#include #endif /** Main function */ diff --git a/others/paranthesis_matching.cpp b/others/paranthesis_matching.cpp index 6456d9d522e..d9c52c813a0 100644 --- a/others/paranthesis_matching.cpp +++ b/others/paranthesis_matching.cpp @@ -5,11 +5,11 @@ * @note Implementation is C-type and does not utilize the C++ constructs * @todo implement as a C++ class */ -#include // for operator<<, basic_ostream, cout, basic_istream, cin -#include // for basic_string, operator>>, string +#include #ifdef _MSC_VER -#include // for basic_string, operator>>, string +#include // Visual Studio C requires this include #else +#include #endif /** check number */ diff --git a/others/postfix_evaluation.cpp b/others/postfix_evaluation.cpp index 1b45288db0e..1ea77c6f8a5 100644 --- a/others/postfix_evaluation.cpp +++ b/others/postfix_evaluation.cpp @@ -10,13 +10,11 @@ * Evaluate the operator and push the result back to the stack * When the expression is ended, the number in the stack is the final answer */ -#include // for isdigit #include // for all_of -#include // for array +#include // for std::array #include // for assert -#include // for operator<<, basic_ostream, cout -#include // for basic_string, char_traits, string, stof -#include // for size_t +#include // for io operations +#include // for stof /** * @namespace others diff --git a/others/smallest_circle.cpp b/others/smallest_circle.cpp index 0c5879d63b4..9ee4353eb4e 100644 --- a/others/smallest_circle.cpp +++ b/others/smallest_circle.cpp @@ -7,10 +7,9 @@ * @see [other * implementation](https://www.nayuki.io/page/smallest-enclosing-circle) */ -#include // for sqrt, INFINITY -#include // for size_t -#include // for basic_ostream, char_traits, cout, endl, operator<< -#include // for vector +#include +#include +#include /** Define a point */ struct Point { From 5b6510184213c75d0aab2bab2fc63065b7ab74c8 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:46:21 +0530 Subject: [PATCH 058/131] Revert "chore: use iwyu on numerical_methods/**.cpp" This reverts commit eff2f44a502aa437903938c6a9ebbc0f8ac7d278. --- numerical_methods/babylonian_method.cpp | 7 +++---- numerical_methods/bisection_method.cpp | 6 +++--- numerical_methods/brent_method_extrema.cpp | 14 ++++++-------- numerical_methods/composite_simpson_rule.cpp | 16 ++++++++-------- numerical_methods/false_position.cpp | 4 ++-- numerical_methods/golden_search_extrema.cpp | 14 ++++++-------- numerical_methods/gram_schmidt.cpp | 10 ++++++---- numerical_methods/midpoint_integral_method.cpp | 15 +++++++-------- numerical_methods/newton_raphson_method.cpp | 11 +++++------ numerical_methods/ode_forward_euler.cpp | 12 +++++------- numerical_methods/ode_midpoint_euler.cpp | 12 +++++------- numerical_methods/ode_semi_implicit_euler.cpp | 12 +++++------- 12 files changed, 61 insertions(+), 72 deletions(-) diff --git a/numerical_methods/babylonian_method.cpp b/numerical_methods/babylonian_method.cpp index b08c0d235df..a70fa993e01 100644 --- a/numerical_methods/babylonian_method.cpp +++ b/numerical_methods/babylonian_method.cpp @@ -9,10 +9,9 @@ * @author [Ameya Chawla](https://github.com/ameyachawlaggsipu) */ -#include // for assert -#include // for NAN -#include // for operator<<, basic_ostream, cout -#include // for max, min +#include /// for assert +#include +#include /// for IO operations /** * @namespace numerical_methods diff --git a/numerical_methods/bisection_method.cpp b/numerical_methods/bisection_method.cpp index c2ef6bfb92b..c93c529d248 100644 --- a/numerical_methods/bisection_method.cpp +++ b/numerical_methods/bisection_method.cpp @@ -13,9 +13,9 @@ * * \see newton_raphson_method.cpp, false_position.cpp, secant_method.cpp */ -#include // for abs -#include // for pow -#include // for basic_ostream, char_traits, operator<<, cout +#include +#include +#include #define EPSILON \ 1e-6 // std::numeric_limits::epsilon() ///< system accuracy limit diff --git a/numerical_methods/brent_method_extrema.cpp b/numerical_methods/brent_method_extrema.cpp index 5077f0bd022..bd4d2796d29 100644 --- a/numerical_methods/brent_method_extrema.cpp +++ b/numerical_methods/brent_method_extrema.cpp @@ -14,14 +14,12 @@ * \author [Krishna Vedala](https://github.com/kvedala) */ #define _USE_MATH_DEFINES ///< required for MS Visual C++ -#include // for abs -#include // for assert -#include // for sqrt, cos, pow, M_E, M_PI -#include // for uint32_t -#include // for function -#include // for operator<<, basic_ostream, char_traits, cout -#include // for numeric_limits -#include // for swap +#include +#include +#include /// for integral typedefs +#include +#include +#include #define EPSILON \ std::sqrt( \ diff --git a/numerical_methods/composite_simpson_rule.cpp b/numerical_methods/composite_simpson_rule.cpp index 14f64bfefff..2ca58cbe4c0 100644 --- a/numerical_methods/composite_simpson_rule.cpp +++ b/numerical_methods/composite_simpson_rule.cpp @@ -35,14 +35,14 @@ * */ -#include // for assert -#include // for log, sqrt, pow, exp, NAN, isnan -#include // for int32_t -#include // for atof, atoi -#include // for function -#include // for basic_ostream, char_traits, operator<<, cout -#include // for map -#include // for pair +#include /// for assert +#include /// for math functions +#include +#include /// for integer allocation +#include /// for std::atof +#include /// for std::function +#include /// for IO operations +#include /// for std::map container /** * @namespace numerical_methods diff --git a/numerical_methods/false_position.cpp b/numerical_methods/false_position.cpp index 5d83ead3407..ad23d2677bf 100644 --- a/numerical_methods/false_position.cpp +++ b/numerical_methods/false_position.cpp @@ -22,8 +22,8 @@ * \author Unknown author * \author [Samruddha Patil](https://github.com/sampatil578) */ -#include // for int16_t -#include // for basic_ostream, char_traits, operator<<, cout, endl +#include /// for math operations +#include /// for io operations /** * @namespace numerical_methods diff --git a/numerical_methods/golden_search_extrema.cpp b/numerical_methods/golden_search_extrema.cpp index 048679a0d4c..2d9dd507013 100644 --- a/numerical_methods/golden_search_extrema.cpp +++ b/numerical_methods/golden_search_extrema.cpp @@ -8,14 +8,12 @@ * \author [Krishna Vedala](https://github.com/kvedala) */ #define _USE_MATH_DEFINES //< required for MS Visual C++ -#include // for abs -#include // for assert -#include // for cos, pow, M_E, M_PI, sqrt -#include // for uint32_t -#include // for function -#include // for operator<<, basic_ostream, char_traits, cout -#include // for numeric_limits -#include // for swap +#include +#include +#include /// for integral typedefs +#include +#include +#include #define EPSILON 1e-7 ///< solution accuracy limit diff --git a/numerical_methods/gram_schmidt.cpp b/numerical_methods/gram_schmidt.cpp index be256cf3761..c72f8553b2e 100644 --- a/numerical_methods/gram_schmidt.cpp +++ b/numerical_methods/gram_schmidt.cpp @@ -28,10 +28,12 @@ * @author [Akanksha Gupta](https://github.com/Akanksha-Gupta920) */ -#include // for array -#include // for assert -#include // for fabs, NAN -#include // for operator<<, basic_ostream, char_traits, cout +#include /// for std::array +#include /// for assert +#include /// for fabs +#include /// for io operations + +#include "math.h" /** * @namespace numerical_methods diff --git a/numerical_methods/midpoint_integral_method.cpp b/numerical_methods/midpoint_integral_method.cpp index 7a857615dfd..3eab8fd1e2d 100644 --- a/numerical_methods/midpoint_integral_method.cpp +++ b/numerical_methods/midpoint_integral_method.cpp @@ -18,14 +18,13 @@ * * @author [ggkogkou](https://github.com/ggkogkou) */ -#include // for assert -#include // for log, sqrt, pow, exp, NAN, isnan -#include // for int32_t -#include // for atof, atoi -#include // for function -#include // for basic_ostream, char_traits, operator<<, cout -#include // for map -#include // for pair +#include /// for assert +#include /// for math functions +#include /// for integer allocation +#include /// for std::atof +#include /// for std::function +#include /// for IO operations +#include /// for std::map container /** * @namespace numerical_methods diff --git a/numerical_methods/newton_raphson_method.cpp b/numerical_methods/newton_raphson_method.cpp index 7f90cef9ec5..ce75088a39a 100644 --- a/numerical_methods/newton_raphson_method.cpp +++ b/numerical_methods/newton_raphson_method.cpp @@ -12,12 +12,11 @@ * \author [Krishna Vedala](https://github.com/kvedala) * \see bisection_method.cpp, false_position.cpp */ -#include // for abs -#include // for pow, NAN -#include // for INT16_MAX, int16_t -#include // for time -#include // for char_traits, basic_ostream, operator<< -#include // for rand, srand +#include +#include /// for integral typedefs +#include +#include +#include constexpr double EPSILON = 1e-10; ///< system accuracy limit constexpr int16_t MAX_ITERATIONS = INT16_MAX; ///< Maximum number of iterations diff --git a/numerical_methods/ode_forward_euler.cpp b/numerical_methods/ode_forward_euler.cpp index cc675c5d094..5e4dda31ba7 100644 --- a/numerical_methods/ode_forward_euler.cpp +++ b/numerical_methods/ode_forward_euler.cpp @@ -36,13 +36,11 @@ * \see ode_midpoint_euler.cpp, ode_semi_implicit_euler.cpp */ -#include // for cos, sin, NAN -#include // for clock, clock_t, CLOCKS_PER_SEC, size_t -#include // for operator<<, basic_ostream, char_traits, basic_of... -#include // for cout, cin -#include // for valarray, __multiplies, operator*, _BinClos -#include // for perror -#include // for atof +#include +#include +#include +#include +#include /** * @brief Problem statement for a system with first-order differential diff --git a/numerical_methods/ode_midpoint_euler.cpp b/numerical_methods/ode_midpoint_euler.cpp index 1b14a585369..50cf4e4c6c4 100644 --- a/numerical_methods/ode_midpoint_euler.cpp +++ b/numerical_methods/ode_midpoint_euler.cpp @@ -35,13 +35,11 @@ * \see ode_forward_euler.cpp, ode_semi_implicit_euler.cpp */ -#include // for cos, sin -#include // for clock, clock_t, CLOCKS_PER_SEC, size_t -#include // for operator<<, basic_ostream, char_traits, basic_of... -#include // for cout, cin -#include // for valarray, _BinClos, __multiplies, __plus, operator* -#include // for perror -#include // for atof +#include +#include +#include +#include +#include /** * @brief Problem statement for a system with first-order differential diff --git a/numerical_methods/ode_semi_implicit_euler.cpp b/numerical_methods/ode_semi_implicit_euler.cpp index b23a81f9f58..01904ac1684 100644 --- a/numerical_methods/ode_semi_implicit_euler.cpp +++ b/numerical_methods/ode_semi_implicit_euler.cpp @@ -35,13 +35,11 @@ * \see ode_midpoint_euler.cpp, ode_forward_euler.cpp */ -#include // for cos, sin -#include // for clock, clock_t, CLOCKS_PER_SEC, size_t -#include // for operator<<, basic_ostream, char_traits, basic_of... -#include // for cout, cin -#include // for valarray, __multiplies, operator*, _BinClos -#include // for perror -#include // for atof +#include +#include +#include +#include +#include /** * @brief Problem statement for a system with first-order differential From d9e6762ceef761dd4a68de1b97c1ed571f217de7 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:46:26 +0530 Subject: [PATCH 059/131] Revert "chore: use iwyu on math/**.cpp" This reverts commit c47117ca3f02aee4ba054b861bf7ab44e2ae6348. --- math/area.cpp | 9 +++++---- math/check_prime.cpp | 5 ++--- math/complex_numbers.cpp | 13 ++++++------- math/eratosthenes.cpp | 12 +++++------- math/extended_euclid_algorithm.cpp | 6 +++--- math/factorial.cpp | 8 +++----- math/fibonacci_fast.cpp | 5 +++-- math/fibonacci_large.cpp | 9 ++++----- math/gcd_recursive_euclidean.cpp | 3 +-- math/integral_approximation2.cpp | 15 +++++++-------- math/inv_sqrt.cpp | 11 +++++------ math/iterative_factorial.cpp | 8 ++++---- math/large_factorial.cpp | 9 ++++----- math/linear_recurrence_matrix.cpp | 7 ++++--- math/modular_inverse_fermat_little_theorem.cpp | 4 ++-- math/n_bonacci.cpp | 10 ++++------ math/ncr_modulo_p.cpp | 7 +++---- math/prime_factorization.cpp | 8 ++++---- math/prime_numbers.cpp | 5 ++--- math/primes_up_to_billion.cpp | 5 ++--- math/quadratic_equations_complex_numbers.cpp | 16 ++++++++-------- math/realtime_stats.cpp | 7 +++---- math/string_fibonacci.cpp | 8 ++++---- 23 files changed, 88 insertions(+), 102 deletions(-) diff --git a/math/area.cpp b/math/area.cpp index f6ac5f4a8b8..691fe91f0fc 100644 --- a/math/area.cpp +++ b/math/area.cpp @@ -9,10 +9,11 @@ * @author [Focusucof](https://github.com/Focusucof) */ #define _USE_MATH_DEFINES -#include // for assert -#include // for NAN, M_PI, pow -#include // for uint16_t -#include // for basic_ostream, operator<<, char_traits, endl, cout +#include /// for assert +#include /// for M_PI definition and pow() +#include +#include /// for uint16_t datatype +#include /// for IO operations /** * @namespace math diff --git a/math/check_prime.cpp b/math/check_prime.cpp index add436236eb..ebd48cab5aa 100644 --- a/math/check_prime.cpp +++ b/math/check_prime.cpp @@ -14,9 +14,8 @@ * @author [ewd00010](https://github.com/ewd00010) */ -#include // for int64_t -#include // for assert -#include // for char_traits, basic_ostream, operator<<, cout, endl +#include /// for assert +#include /// for IO operations /** * @brief Mathematical algorithms diff --git a/math/complex_numbers.cpp b/math/complex_numbers.cpp index 0482a088d23..f8923864961 100644 --- a/math/complex_numbers.cpp +++ b/math/complex_numbers.cpp @@ -7,13 +7,12 @@ * operators overloaded to accommodate (mathematical) field operations. */ -#include // for assert -#include // for atan2, cos, sin, sqrt -#include // for complex, abs, arg, conj, operator*, operator+ -#include // for time -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for invalid_argument -#include // for rand, srand +#include +#include +#include +#include +#include +#include /** * \brief Class Complex to represent complex numbers as a field. diff --git a/math/eratosthenes.cpp b/math/eratosthenes.cpp index 875fce20bfc..224e9f51b31 100644 --- a/math/eratosthenes.cpp +++ b/math/eratosthenes.cpp @@ -13,13 +13,11 @@ * @author [Keval Kapdee](https://github.com/thechubbypanda) */ -#include // for duration, duration_cast, high_resolution_clock -#include // for uint64_t -#include // for assert -#include // for basic_ostream, operator<<, cout, endl -#include // for char_traits, basic_string, operator==, string -#include // for vector -#include // for ratio +#include /// For assert +#include /// For timing the sieve +#include /// For IO operations +#include /// For string handling +#include /// For std::vector /** * @namespace math diff --git a/math/extended_euclid_algorithm.cpp b/math/extended_euclid_algorithm.cpp index 5fead27b1a7..cc2eacac8e3 100644 --- a/math/extended_euclid_algorithm.cpp +++ b/math/extended_euclid_algorithm.cpp @@ -9,9 +9,9 @@ * multiplicative inverse of a number. (A * B)%M == 1 Here B is the MMI of A for * given M, so extendedEuclid (A, M) gives B. */ -#include // for char_traits, basic_ostream, basic_ostream::opera... -#include // for uint32_t, int32_t -#include // for swap +#include // for swap function +#include +#include /** * function to update the coefficients per iteration diff --git a/math/factorial.cpp b/math/factorial.cpp index f4dffc1383b..a6b039da45b 100644 --- a/math/factorial.cpp +++ b/math/factorial.cpp @@ -11,11 +11,9 @@ * @author [Akshay Gupta](https://github.com/Akshay1910) */ -#include // for assert -#include // for uint64_t, uint8_t -#include // for operator<<, basic_ostream, cout -#include // for invalid_argument - +#include /// for assert +#include /// for integral typedefs +#include /// for I/O operations /** * @namespace * @brief Mathematical algorithms diff --git a/math/fibonacci_fast.cpp b/math/fibonacci_fast.cpp index ed33af4ebd5..0948276a08a 100644 --- a/math/fibonacci_fast.cpp +++ b/math/fibonacci_fast.cpp @@ -15,8 +15,9 @@ * @see fibonacci_large.cpp, fibonacci.cpp, string_fibonacci.cpp */ -#include // for uint64_t -#include // for char_traits, basic_ostream, operator<<, cerr, cout +#include +#include +#include /** * maximum number that can be computed - The result after 93 cannot be stored diff --git a/math/fibonacci_large.cpp b/math/fibonacci_large.cpp index 73e696bddd3..e4f4e5eaf1b 100644 --- a/math/fibonacci_large.cpp +++ b/math/fibonacci_large.cpp @@ -11,12 +11,11 @@ * @see fibonacci.cpp, fibonacci_fast.cpp, string_fibonacci.cpp */ -#include // for strtoull -#include // for uint64_t -#include // for clock, clock_t, CLOCKS_PER_SEC, NULL -#include // for basic_ostream, char_traits, operator<< +#include +#include +#include -#include "./large_number.h" // for large_number, operator<<, operator== +#include "./large_number.h" /** Compute fibonacci numbers using the relation * \f[f(n)=f(n-1)+f(n-2)\f] diff --git a/math/gcd_recursive_euclidean.cpp b/math/gcd_recursive_euclidean.cpp index 368f67cde0d..2a3d2183c4e 100644 --- a/math/gcd_recursive_euclidean.cpp +++ b/math/gcd_recursive_euclidean.cpp @@ -6,8 +6,7 @@ * * @see gcd_iterative_euclidean.cpp, gcd_of_n_numbers.cpp */ -#include // for basic_ostream, char_traits, operator<<, basic_o... -#include // for domain_error +#include /** * algorithm diff --git a/math/integral_approximation2.cpp b/math/integral_approximation2.cpp index b858fedba6d..eed605e035f 100644 --- a/math/integral_approximation2.cpp +++ b/math/integral_approximation2.cpp @@ -22,14 +22,13 @@ */ #define _USE_MATH_DEFINES /// for M_PI on windows -#include // for exp, M_PI, sin, sqrt -#include // for uint32_t -#include // for time -#include // for function -#include // for basic_ostream, char_traits, operator<<, endl -#include // for normal_distribution, uniform_real_distribution -#include // for vector -#include // for min +#include /// for math functions +#include /// for fixed size data types +#include /// for time to initialize rng +#include /// for function pointers +#include /// for std::cout +#include /// for random number generation +#include /// for std::vector /** * @namespace math diff --git a/math/inv_sqrt.cpp b/math/inv_sqrt.cpp index 55088b0c0eb..1f625e1cf8a 100644 --- a/math/inv_sqrt.cpp +++ b/math/inv_sqrt.cpp @@ -8,12 +8,11 @@ * This algorithm is used to calculate shadows in Quake III Arena. */ -#include // for assert -#include // for fabs, sqrt -#include // for int32_t, int64_t -#include // for basic_ostream, char_traits, operator<<, cout -#include // for conditional - +#include /// for assert +#include /// for `std::sqrt` +#include /// for integral typedefs +#include /// for IO operations +#include /// for numeric_limits /** * @brief This is the function that calculates the fast inverse square root. * The following code is the fast inverse square root implementation from diff --git a/math/iterative_factorial.cpp b/math/iterative_factorial.cpp index 5a3454b281d..12f6afe06a0 100644 --- a/math/iterative_factorial.cpp +++ b/math/iterative_factorial.cpp @@ -25,10 +25,10 @@ * */ -#include // for assert -#include // for uint64_t, uint8_t -#include // for operator<<, basic_ostream, cout -#include // for invalid_argument +#include /// for assert +#include /// for integral types +#include /// for std::invalid_argument +#include /// for std::cout /** * @namespace diff --git a/math/large_factorial.cpp b/math/large_factorial.cpp index 5f5b5562d90..20c677cdcc4 100644 --- a/math/large_factorial.cpp +++ b/math/large_factorial.cpp @@ -5,12 +5,11 @@ * \author [Krishna Vedala](https://github.com/kvedala) * @see factorial.cpp */ -#include // for atoi -#include // for strlen, size_t -#include // for clock, clock_t, CLOCKS_PER_SEC -#include // for basic_ostream, char_traits, operator<< +#include +#include +#include -#include "./large_number.h" // for large_number, operator<< +#include "./large_number.h" /** Test implementation for 10! Result must be 3628800. * @returns True if test pass else False diff --git a/math/linear_recurrence_matrix.cpp b/math/linear_recurrence_matrix.cpp index ab5c928d30b..d59ad6aa1c0 100644 --- a/math/linear_recurrence_matrix.cpp +++ b/math/linear_recurrence_matrix.cpp @@ -17,9 +17,10 @@ * here](https://en.wikipedia.org/wiki/Exponentiation_by_squaring). * @author [Ashish Daulatabad](https://github.com/AshishYUO) */ -#include // for assert -#include // for int64_t, uint32_t, uint64_t -#include // for vector +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations +#include /// for std::vector STL /** * @namespace math diff --git a/math/modular_inverse_fermat_little_theorem.cpp b/math/modular_inverse_fermat_little_theorem.cpp index bfbd2b419dc..7550e14bf23 100644 --- a/math/modular_inverse_fermat_little_theorem.cpp +++ b/math/modular_inverse_fermat_little_theorem.cpp @@ -43,8 +43,8 @@ * (as \f$a\times a^{-1} = 1\f$) */ -#include // for int64_t -#include // for char_traits, basic_ostream, operator<<, cout, endl +#include +#include /** Recursive function to calculate exponent in \f$O(\log n)\f$ using binary * exponent. diff --git a/math/n_bonacci.cpp b/math/n_bonacci.cpp index 0660703353e..601b2edf0d7 100644 --- a/math/n_bonacci.cpp +++ b/math/n_bonacci.cpp @@ -15,12 +15,10 @@ * @author [Swastika Gupta](https://github.com/Swastyy) */ -#include // for assert -#include // for uint64_t -#include // for char_traits, basic_ostream, operator<< -#include // for vector, operator== -#include // for initializer_list - +#include /// for assert +#include /// for integral typedefs +#include /// for std::cout +#include /// for std::vector /** * @namespace math * @brief Mathematical algorithms diff --git a/math/ncr_modulo_p.cpp b/math/ncr_modulo_p.cpp index f154821c4bd..cbf5e9e1a00 100644 --- a/math/ncr_modulo_p.cpp +++ b/math/ncr_modulo_p.cpp @@ -9,10 +9,9 @@ * @author [Kaustubh Damania](https://github.com/KaustubhDamania) */ -#include // for int64_t -#include // for assert -#include // for char_traits, basic_ostream, operator<<, basic_os... -#include // for vector +#include /// for assert +#include /// for std::cout +#include /// for std::vector /** * @namespace math diff --git a/math/prime_factorization.cpp b/math/prime_factorization.cpp index 3617ea35c09..001c2c3c360 100644 --- a/math/prime_factorization.cpp +++ b/math/prime_factorization.cpp @@ -2,10 +2,10 @@ * @file * @brief Prime factorization of positive integers */ -#include // for memset -#include // for char_traits, basic_ostream, operator<<, basic_os... -#include // for vector -#include // for pair, make_pair +#include +#include +#include +#include /** Declaring variables for maintaing prime numbers and to check whether a * number is prime or not diff --git a/math/prime_numbers.cpp b/math/prime_numbers.cpp index 50723d9bc15..cd6aca0ca9c 100644 --- a/math/prime_numbers.cpp +++ b/math/prime_numbers.cpp @@ -3,9 +3,8 @@ * @brief Get list of prime numbers * @see primes_up_to_billion.cpp sieve_of_eratosthenes.cpp */ -#include // for size_t -#include // for char_traits, basic_ostream, operator<<, cout -#include // for vector +#include +#include /** Generate an increasingly large number of primes * and store in a list diff --git a/math/primes_up_to_billion.cpp b/math/primes_up_to_billion.cpp index d1dc00abfc0..b7377cea584 100644 --- a/math/primes_up_to_billion.cpp +++ b/math/primes_up_to_billion.cpp @@ -3,9 +3,8 @@ * @brief Compute prime numbers upto 1 billion * @see prime_numbers.cpp sieve_of_eratosthenes.cpp */ -#include // for int64_t -#include // for memset -#include // for operator<<, basic_ostream, cout, basic_istream, cin +#include +#include /** array to store the primes */ char prime[100000000]; diff --git a/math/quadratic_equations_complex_numbers.cpp b/math/quadratic_equations_complex_numbers.cpp index 1140e7760a6..3a50719e5dc 100644 --- a/math/quadratic_equations_complex_numbers.cpp +++ b/math/quadratic_equations_complex_numbers.cpp @@ -28,13 +28,13 @@ * (-0.5,0.866025) (-0.5,0.866025) */ -#include // for array, operator== -#include // for assert -#include // for round, sqrt, pow -#include // for complex, operator== -#include // for size_t -#include // for operator<<, basic_ostream, cout -#include // for invalid_argument +#include /// std::array +#include /// assert +#include /// std::sqrt, std::trunc, std::pow +#include /// std::complex +#include /// std::invalid_argument +#include /// std::setprecision +#include /// std::cout /** * @namespace @@ -65,7 +65,7 @@ std::array, 2> quadraticEquation(long double a, solutions[1] = -b * 0.5 / a; return solutions; } - + // Complex root (discriminant < 0) // Note that the left term (-b / 2a) is always real. The imaginary part // appears when b^2 - 4ac < 0, so sqrt(b^2 - 4ac) has no real roots. So, diff --git a/math/realtime_stats.cpp b/math/realtime_stats.cpp index 6a455115d35..672acfa03b9 100644 --- a/math/realtime_stats.cpp +++ b/math/realtime_stats.cpp @@ -7,10 +7,9 @@ * simple enough to be easily implemented in an embedded system. * \author [Krishna Vedala](https://github.com/kvedala) */ -#include // for abs -#include // for assert -#include // for sqrt -#include // for basic_ostream, char_traits, operator<<, cout +#include +#include +#include /** * \namespace statistics diff --git a/math/string_fibonacci.cpp b/math/string_fibonacci.cpp index 34db60e7e2b..a7ff4c8bbad 100644 --- a/math/string_fibonacci.cpp +++ b/math/string_fibonacci.cpp @@ -8,12 +8,12 @@ * @see fibonacci_large.cpp, fibonacci_fast.cpp, fibonacci.cpp */ -#include // for uint64_t -#include // for char_traits, basic_ostream, operator<<, cout -#include // for allocator, basic_string, operator+, string, oper... +#include /// for integral typedefs +#include #ifdef _MSC_VER -#include // for allocator, basic_string, operator+, string, oper... +#include // use this for MS Visual C #else +#include // otherwise #endif /** From 3b86febda0bd714166b54789d2aadf4205936311 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:46:37 +0530 Subject: [PATCH 060/131] Revert "chore: use iwyu on machine_learning/**.cpp" This reverts commit c3897d3763c5f0fb0077d761f824e754b7b181da. --- machine_learning/a_star_search.cpp | 24 +++++++---------- machine_learning/adaline_learning.cpp | 17 ++++++------ machine_learning/k_nearest_neighbors.cpp | 19 ++++++-------- machine_learning/neural_network.cpp | 26 +++++++++---------- .../ordinary_least_squares_regressor.cpp | 12 ++++----- 5 files changed, 43 insertions(+), 55 deletions(-) diff --git a/machine_learning/a_star_search.cpp b/machine_learning/a_star_search.cpp index f805d09efc8..9f713883a1d 100644 --- a/machine_learning/a_star_search.cpp +++ b/machine_learning/a_star_search.cpp @@ -19,21 +19,15 @@ * values having minimum F(state). * @author [Ashish Daulatabad](https://github.com/AshishYUO) */ -#include // for uint32_t, int8_t - -#include // for max, min -#include // for array, operator== -#include // for assert -#include // for size_t -#include // for function -#include // for operator<<, basic_ostream, char_traits, cout -#include // for operator!=, map, operator== -#include // for shared_ptr, make_shared, operator!= -#include // for set -#include // for tie, tuple -#include // for pair, move, make_pair, swap -#include // for vector - +#include /// for `std::reverse` function +#include /// for `std::array`, representing `EightPuzzle` board +#include /// for `assert` +#include /// for `std::function` STL +#include /// for IO operations +#include /// for `std::map` STL +#include /// for `std::shared_ptr` +#include /// for `std::set` STL +#include /// for `std::vector` STL /** * @namespace machine_learning * @brief Machine learning algorithms diff --git a/machine_learning/adaline_learning.cpp b/machine_learning/adaline_learning.cpp index 55385d130d8..6da839a9d04 100644 --- a/machine_learning/adaline_learning.cpp +++ b/machine_learning/adaline_learning.cpp @@ -26,14 +26,15 @@ * computed using stochastic gradient descent method. */ -#include // for abs -#include // for array -#include // for assert -#include // for rand, exit, srand, strtof, EXIT_FAILURE -#include // for time -#include // for basic_ostream, operator<<, char_traits, cout -#include // for inner_product -#include // for vector +#include +#include +#include +#include +#include +#include +#include +#include +#include /** Maximum number of iterations to learn */ constexpr int MAX_ITER = 500; // INT_MAX diff --git a/machine_learning/k_nearest_neighbors.cpp b/machine_learning/k_nearest_neighbors.cpp index 2ff1818fe41..92621862ccf 100644 --- a/machine_learning/k_nearest_neighbors.cpp +++ b/machine_learning/k_nearest_neighbors.cpp @@ -9,16 +9,13 @@ * the K-nearest neighbors. */ -#include // for sort, transform -#include // for assert -#include // for sqrt, pow -#include // for size_t -#include // for basic_ostream, operator<<, char_traits, cout -#include // for back_inserter -#include // for accumulate -#include // for unordered_map, _Node_iterator -#include // for pair -#include // for vector +#include /// for std::transform and std::sort +#include /// for assert +#include /// for std::pow and std::sqrt +#include /// for std::cout +#include /// for std::accumulate +#include /// for std::unordered_map +#include /// for std::vector /** * @namespace machine_learning @@ -68,7 +65,7 @@ class Knn { * @param Y labels vector */ explicit Knn(std::vector>& X, std::vector& Y) - : X_(X), Y_(Y) {}; + : X_(X), Y_(Y){}; /** * Copy Constructor for class Knn. diff --git a/machine_learning/neural_network.cpp b/machine_learning/neural_network.cpp index e3c43884915..7e20f7a4022 100644 --- a/machine_learning/neural_network.cpp +++ b/machine_learning/neural_network.cpp @@ -27,20 +27,18 @@ * MSE as loss function. Bias is also not included. */ -#include // for duration, duration_cast, high_resolution_c... -#include // for max, min -#include // for assert -#include // for exp -#include // for basic_ostream, operator<<, endl, basic_ist... -#include // for cerr, cout -#include // for basic_stringstream -#include // for char_traits, basic_string, operator<<, ope... -#include // for valarray -#include // for vector -#include // for exit, size_t, EXIT_FAILURE -#include // for pair, make_pair - -#include "vector_ops.hpp" // for argmax, apply_function, get_shape, multiply +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vector_ops.hpp" // Custom header file for vector operations /** \namespace machine_learning * \brief Machine learning algorithms diff --git a/machine_learning/ordinary_least_squares_regressor.cpp b/machine_learning/ordinary_least_squares_regressor.cpp index e9475ea4438..0c865761bee 100644 --- a/machine_learning/ordinary_least_squares_regressor.cpp +++ b/machine_learning/ordinary_least_squares_regressor.cpp @@ -9,13 +9,11 @@ * * \author [Krishna Vedala](https://github.com/kvedala) */ -#include // for abs - -#include // for assert -#include // for size_t -#include // for operator<<, setfill, setw, _Setfill, _Setw -#include // for basic_ostream, operator<<, char_traits, cout -#include // for vector +#include +#include // for std::abs +#include // for print formatting +#include +#include /** * operator to print a matrix From fe871449d0379015be833264ac7e080bb2d89f44 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:46:40 +0530 Subject: [PATCH 061/131] Revert "chore: use iwyu on hashing/**.cpp" This reverts commit 0c6611a835d75718ae060b8b634ce47c85d7690b. --- hashing/chaining.cpp | 9 ++++----- hashing/double_hash_hash_table.cpp | 7 +++---- hashing/linear_probing_hash_table.cpp | 6 ++---- hashing/quadratic_probing_hash_table.cpp | 8 +++----- hashing/sha256.cpp | 19 ++++++++----------- 5 files changed, 20 insertions(+), 29 deletions(-) diff --git a/hashing/chaining.cpp b/hashing/chaining.cpp index cf7a4dced0e..9c5a2a0766a 100644 --- a/hashing/chaining.cpp +++ b/hashing/chaining.cpp @@ -5,11 +5,10 @@ * @brief Implementation of [hash * chains](https://en.wikipedia.org/wiki/Hash_chain). */ -#include // for abs -#include // for abs -#include // for basic_ostream, operator<<, char_traits, cout -#include // for shared_ptr, __shared_ptr_access -#include // for vector +#include +#include +#include +#include /** * @brief Chain class with a given modulus diff --git a/hashing/double_hash_hash_table.cpp b/hashing/double_hash_hash_table.cpp index 221b9fcdb35..f5d803ba22f 100644 --- a/hashing/double_hash_hash_table.cpp +++ b/hashing/double_hash_hash_table.cpp @@ -6,10 +6,9 @@ * keys](https://en.wikipedia.org/wiki/Double_hashing). * @note The implementation can be optimized by using OOP style. */ -#include // for size_t -#include // for hash -#include // for basic_ostream, operator<<, char_traits, cout -#include // for vector +#include +#include +#include /** * @addtogroup open_addressing Open Addressing diff --git a/hashing/linear_probing_hash_table.cpp b/hashing/linear_probing_hash_table.cpp index 01c732bb614..d87cb9cf727 100644 --- a/hashing/linear_probing_hash_table.cpp +++ b/hashing/linear_probing_hash_table.cpp @@ -6,10 +6,8 @@ * hash](https://en.wikipedia.org/wiki/Linear_probing) keys. * @note The implementation can be optimized by using OOP style. */ -#include // for size_t -#include // for hash -#include // for basic_ostream, operator<<, char_traits, cout -#include // for vector +#include +#include /** * @addtogroup open_addressing Open Addressing diff --git a/hashing/quadratic_probing_hash_table.cpp b/hashing/quadratic_probing_hash_table.cpp index add1d38faee..258c009d0f7 100644 --- a/hashing/quadratic_probing_hash_table.cpp +++ b/hashing/quadratic_probing_hash_table.cpp @@ -6,11 +6,9 @@ * hash](https://en.wikipedia.org/wiki/Quadratic_probing) keys. * @note The implementation can be optimized by using OOP style. */ -#include // for round, pow -#include // for size_t -#include // for hash -#include // for basic_ostream, operator<<, char_traits, cout -#include // for vector +#include +#include +#include /** * @addtogroup open_addressing Open Addressing diff --git a/hashing/sha256.cpp b/hashing/sha256.cpp index 202e58275d1..0eae0bd361e 100644 --- a/hashing/sha256.cpp +++ b/hashing/sha256.cpp @@ -12,17 +12,14 @@ * used for authenticating software packages and secure password hashing. */ -#include // for array -#include // for assert -#include // for uint32_t, uint8_t -#include // for operator<<, setfill, setw, _Setfill, _Setw -#include // for char_traits, basic_ostream, operator<<, cout, hex -#include // for basic_stringstream -#include // for move -#include // for allocator, vector -#include // for size_t -#include // for out_of_range -#include // for basic_string, string, operator== +#include /// For std::array +#include /// For assert +#include /// For uint8_t, uint32_t and uint64_t data types +#include /// For std::setfill and std::setw +#include /// For IO operations +#include /// For std::stringstream +#include /// For std::move +#include /// For std::vector /** * @namespace hashing From 0ed3409878719179bad64be50fdea0a5e22959e6 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:46:50 +0530 Subject: [PATCH 062/131] Revert "chore: use iwyu on graph/**.cpp" This reverts commit dabd6d2591d2feeefec2aa512fdcfd335e600606. --- graph/bidirectional_dijkstra.cpp | 15 +- graph/breadth_first_search.cpp | 16 +- graph/connected_components.cpp | 7 +- graph/connected_components_with_dsu.cpp | 9 +- graph/cycle_check_directed_graph.cpp | 17 +- graph/depth_first_search.cpp | 6 +- graph/depth_first_search_with_stack.cpp | 169 +++++++++--------- graph/dijkstra.cpp | 15 +- graph/hamiltons_cycle.cpp | 7 +- graph/hopcroft_karp.cpp | 13 +- graph/kruskal.cpp | 11 +- graph/lowest_common_ancestor.cpp | 10 +- ...th_ford_fulkerson_and_edmond_karp_algo.cpp | 17 +- graph/prim.cpp | 8 +- graph/topological_sort_by_kahns_algo.cpp | 8 +- graph/travelling_salesman_problem.cpp | 11 +- 16 files changed, 163 insertions(+), 176 deletions(-) diff --git a/graph/bidirectional_dijkstra.cpp b/graph/bidirectional_dijkstra.cpp index b524e9371aa..5f6d369287c 100644 --- a/graph/bidirectional_dijkstra.cpp +++ b/graph/bidirectional_dijkstra.cpp @@ -13,14 +13,13 @@ * https://www.youtube.com/watch?v=DINCL5cd_w0&t=24s */ -#include // for assert -#include // for uint64_t, int64_t -#include // for basic_ostream, operator<<, char_traits, cout -#include // for numeric_limits -#include // for priority_queue -#include // for pair, make_pair -#include // for vector -#include // for greater +#include /// for assert +#include /// for integral typedefs +#include /// for io operations +#include /// for variable INF +#include /// for the priority_queue of distances +#include /// for make_pair function +#include /// for store the graph, the distances, and the path constexpr int64_t INF = std::numeric_limits::max(); diff --git a/graph/breadth_first_search.cpp b/graph/breadth_first_search.cpp index d9f25f5b2b0..4bc58f34212 100644 --- a/graph/breadth_first_search.cpp +++ b/graph/breadth_first_search.cpp @@ -45,14 +45,14 @@ * push that element into the queue and mark this as visited * */ -#include // for assert -#include // for size_t -#include // for less -#include // for basic_ostream, operator<<, cout, basic_istream... -#include // for list -#include // for map, operator== -#include // for queue -#include // for basic_string, operator<, char_traits, allocator +#include +#include +#include +#include +#include +#include +#include +#include /** * \namespace graph diff --git a/graph/connected_components.cpp b/graph/connected_components.cpp index 0a80a95b9d1..06bb1ee505e 100644 --- a/graph/connected_components.cpp +++ b/graph/connected_components.cpp @@ -25,9 +25,10 @@ * */ -#include // for assert -#include // for basic_ostream, char_traits, operator<<, basic_is... -#include // for vector +#include +#include +#include +#include /** * @namespace graph diff --git a/graph/connected_components_with_dsu.cpp b/graph/connected_components_with_dsu.cpp index 38452f1c502..72c4f34fe2b 100644 --- a/graph/connected_components_with_dsu.cpp +++ b/graph/connected_components_with_dsu.cpp @@ -17,11 +17,10 @@ * @author Unknown author * @author [Sagar Pandya](https://github.com/sagarpandyansit) */ -#include // for int64_t, uint32_t -#include // for char_traits, basic_istream, cin, basic_ostream -#include // for set -#include // for vector -#include // for swap +#include /// for integer typedefs +#include /// for IO operations +#include /// for std::set +#include /// for std::vector /** * @namespace graph diff --git a/graph/cycle_check_directed_graph.cpp b/graph/cycle_check_directed_graph.cpp index 161e768433f..fbe6063ca96 100644 --- a/graph/cycle_check_directed_graph.cpp +++ b/graph/cycle_check_directed_graph.cpp @@ -7,15 +7,14 @@ * */ -#include // for uint8_t -#include // for char_traits, basic_ostream, operator<< -#include // for map, operator!=, _Rb_tree_iterator -#include // for queue -#include // for range_error -#include // for remove_reference -#include // for move, pair -#include // for vector -#include // for initializer_list +#include /// for integral typedefs +#include // for std::cout +#include // for std::map +#include // for std::queue +#include // for throwing errors +#include // for std::remove_reference +#include // for std::move +#include // for std::vector /** * Implementation of non-weighted directed edge of a graph. diff --git a/graph/depth_first_search.cpp b/graph/depth_first_search.cpp index aa6630493a1..e99d44fc914 100644 --- a/graph/depth_first_search.cpp +++ b/graph/depth_first_search.cpp @@ -32,9 +32,9 @@ * */ -#include // for size_t -#include // for char_traits, basic_ostream, operator<<, cout -#include // for vector +#include +#include +#include /** * diff --git a/graph/depth_first_search_with_stack.cpp b/graph/depth_first_search_with_stack.cpp index e1c9d805fd5..5376ea4c419 100644 --- a/graph/depth_first_search_with_stack.cpp +++ b/graph/depth_first_search_with_stack.cpp @@ -2,8 +2,7 @@ * * @file * @brief [Depth First Search Algorithm using Stack - * (Depth First Search - * Algorithm)](https://en.wikipedia.org/wiki/Depth-first_search) + * (Depth First Search Algorithm)](https://en.wikipedia.org/wiki/Depth-first_search) * * @author [Ayaan Khan](http://github.com/ayaankhan98) * @author [Saurav Uppoor](https://github.com/sauravUppoor) @@ -25,26 +24,23 @@ *

Working

* 1. Mark all vertices as unvisited (colour it WHITE). * 2. Push starting vertex into the stack and colour it GREY. - * 3. Once a node is popped out of the stack and is coloured GREY, we colour it - * BLACK. + * 3. Once a node is popped out of the stack and is coloured GREY, we colour it BLACK. * 4. Push all its neighbours which are not coloured BLACK. * 5. Repeat steps 4 and 5 until the stack is empty. */ -#include // for int16_t, int64_t +#include /// for IO operations +#include /// header for std::stack +#include /// header for std::vector +#include /// header for preprocessor macro assert() +#include /// header for limits of integral types -#include // for assert -#include // for size_t -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for numeric_limits -#include // for stack -#include // for vector, operator== - -constexpr int WHITE = 0; /// indicates the node hasn't been explored -constexpr int GREY = 1; /// indicates node is in stack waiting to be explored -constexpr int BLACK = 2; /// indicates node has already been explored +constexpr int WHITE = 0; /// indicates the node hasn't been explored +constexpr int GREY = 1; /// indicates node is in stack waiting to be explored +constexpr int BLACK = 2; /// indicates node has already been explored constexpr int64_t INF = std::numeric_limits::max(); + /** * @namespace graph * @brief Graph algorithms @@ -52,8 +48,7 @@ constexpr int64_t INF = std::numeric_limits::max(); namespace graph { /** * @namespace depth_first_search - * @brief Functions for [Depth First - * Search](https://en.wikipedia.org/wiki/Depth-first_search) algorithm + * @brief Functions for [Depth First Search](https://en.wikipedia.org/wiki/Depth-first_search) algorithm */ namespace depth_first_search { /** @@ -67,14 +62,14 @@ namespace depth_first_search { * */ void addEdge(std::vector> *adj, size_t u, size_t v) { - /* - * - * Here we are considering undirected graph that's the - * reason we are adding v to the adjacency list representation of u - * and also adding u to the adjacency list representation of v - * - */ - (*adj)[u - 1].push_back(v - 1); + /* + * + * Here we are considering undirected graph that's the + * reason we are adding v to the adjacency list representation of u + * and also adding u to the adjacency list representation of v + * + */ + (*adj)[u - 1].push_back(v - 1); } /** @@ -89,8 +84,7 @@ void addEdge(std::vector> *adj, size_t u, size_t v) { * @return vector with nodes stored in the order of DFS traversal * */ -std::vector dfs(const std::vector> &graph, - size_t start) { +std::vector dfs(const std::vector > &graph, size_t start) { /// checked[i] stores the status of each node std::vector checked(graph.size(), WHITE), traversed_path; @@ -127,51 +121,49 @@ std::vector dfs(const std::vector> &graph, * @returns none */ static void tests() { - size_t start_pos; - - /// Test 1 - std::cout << "Case 1: " << std::endl; - start_pos = 1; - std::vector> g1(3, std::vector()); - - graph::depth_first_search::addEdge(&g1, 1, 2); - graph::depth_first_search::addEdge(&g1, 2, 3); - graph::depth_first_search::addEdge(&g1, 3, 1); - - std::vector expected1{ - 1, 2, 3}; /// for the above sample data, this is the expected output - assert(graph::depth_first_search::dfs(g1, start_pos - 1) == expected1); - std::cout << "Passed" << std::endl; - - /// Test 2 - std::cout << "Case 2: " << std::endl; - start_pos = 1; - std::vector> g2(4, std::vector()); - - graph::depth_first_search::addEdge(&g2, 1, 2); - graph::depth_first_search::addEdge(&g2, 1, 3); - graph::depth_first_search::addEdge(&g2, 2, 4); - graph::depth_first_search::addEdge(&g2, 4, 1); - - std::vector expected2{ - 1, 3, 2, 4}; /// for the above sample data, this is the expected output - assert(graph::depth_first_search::dfs(g2, start_pos - 1) == expected2); - std::cout << "Passed" << std::endl; - - /// Test 3 - std::cout << "Case 3: " << std::endl; - start_pos = 2; - std::vector> g3(4, std::vector()); - - graph::depth_first_search::addEdge(&g3, 1, 2); - graph::depth_first_search::addEdge(&g3, 1, 3); - graph::depth_first_search::addEdge(&g3, 2, 4); - graph::depth_first_search::addEdge(&g3, 4, 1); - - std::vector expected3{ - 2, 4, 1, 3}; /// for the above sample data, this is the expected output - assert(graph::depth_first_search::dfs(g3, start_pos - 1) == expected3); - std::cout << "Passed" << std::endl; + size_t start_pos; + + /// Test 1 + std::cout << "Case 1: " << std::endl; + start_pos = 1; + std::vector > g1(3, std::vector()); + + graph::depth_first_search::addEdge(&g1, 1, 2); + graph::depth_first_search::addEdge(&g1, 2, 3); + graph::depth_first_search::addEdge(&g1, 3, 1); + + std::vector expected1 {1, 2, 3}; /// for the above sample data, this is the expected output + assert(graph::depth_first_search::dfs(g1, start_pos - 1) == expected1); + std::cout << "Passed" << std::endl; + + /// Test 2 + std::cout << "Case 2: " << std::endl; + start_pos = 1; + std::vector > g2(4, std::vector()); + + graph::depth_first_search::addEdge(&g2, 1, 2); + graph::depth_first_search::addEdge(&g2, 1, 3); + graph::depth_first_search::addEdge(&g2, 2, 4); + graph::depth_first_search::addEdge(&g2, 4, 1); + + std::vector expected2 {1, 3, 2, 4}; /// for the above sample data, this is the expected output + assert(graph::depth_first_search::dfs(g2, start_pos - 1) == expected2); + std::cout << "Passed" << std::endl; + + /// Test 3 + std::cout << "Case 3: " << std::endl; + start_pos = 2; + std::vector > g3(4, std::vector()); + + graph::depth_first_search::addEdge(&g3, 1, 2); + graph::depth_first_search::addEdge(&g3, 1, 3); + graph::depth_first_search::addEdge(&g3, 2, 4); + graph::depth_first_search::addEdge(&g3, 4, 1); + + std::vector expected3 {2, 4, 1, 3}; /// for the above sample data, this is the expected output + assert(graph::depth_first_search::dfs(g3, start_pos - 1) == expected3); + std::cout << "Passed" << std::endl; + } /** @@ -182,35 +174,34 @@ int main() { tests(); // execute the tests size_t vertices = 0, edges = 0, start_pos = 1; - std::vector traversal; + std::vector traversal; std::cout << "Enter the Vertices : "; - std::cin >> vertices; - std::cout << "Enter the Edges : "; - std::cin >> edges; + std::cin >> vertices; + std::cout << "Enter the Edges : "; + std::cin >> edges; /// creating a graph - std::vector> adj(vertices, std::vector()); + std::vector > adj(vertices, std::vector()); /// taking input for the edges - std::cout << "Enter the vertices which have edges between them : " - << std::endl; - while (edges--) { - size_t u = 0, v = 0; - std::cin >> u >> v; - graph::depth_first_search::addEdge(&adj, u, v); - } + std::cout << "Enter the vertices which have edges between them : " << std::endl; + while (edges--) { + size_t u = 0, v = 0; + std::cin >> u >> v; + graph::depth_first_search::addEdge(&adj, u, v); + } /// taking input for the starting position std::cout << "Enter the starting vertex [1,n]: " << std::endl; - std::cin >> start_pos; - start_pos -= 1; - traversal = graph::depth_first_search::dfs(adj, start_pos); + std::cin >> start_pos; + start_pos -= 1; + traversal = graph::depth_first_search::dfs(adj, start_pos); /// Printing the order of traversal for (auto x : traversal) { - std::cout << x << ' '; - } + std::cout << x << ' '; + } return 0; } diff --git a/graph/dijkstra.cpp b/graph/dijkstra.cpp index a4b7c705adb..a7621456009 100644 --- a/graph/dijkstra.cpp +++ b/graph/dijkstra.cpp @@ -23,14 +23,13 @@ * at the code below to understand in better way. * */ -#include // for int64_t -#include // for assert -#include // for basic_ostream, char_traits, operator<<, basic_... -#include // for numeric_limits -#include // for priority_queue -#include // for pair, make_pair -#include // for vector -#include // for greater +#include +#include +#include +#include +#include +#include +#include constexpr int64_t INF = std::numeric_limits::max(); diff --git a/graph/hamiltons_cycle.cpp b/graph/hamiltons_cycle.cpp index a646321a60e..1506b78d2fc 100644 --- a/graph/hamiltons_cycle.cpp +++ b/graph/hamiltons_cycle.cpp @@ -15,10 +15,9 @@ * @author [vakhokoto](https://github.com/vakhokoto) * @author [Krishna Vedala](https://github.com/kvedala) */ -#include // for assert -#include // for size_t -#include // for operator<<, basic_ostream, cout -#include // for vector +#include +#include +#include /** * The function determines if there is a hamilton's cycle in the graph diff --git a/graph/hopcroft_karp.cpp b/graph/hopcroft_karp.cpp index c5ba5e1b875..d4e002948a7 100644 --- a/graph/hopcroft_karp.cpp +++ b/graph/hopcroft_karp.cpp @@ -45,12 +45,13 @@ */ -#include // for char_traits, basic_istream::operator>>, basic_is... -#include // for queue -#include // for list, operator!=, _List_iterator -#include // for INT_MAX -#include // for assert -#include // for vector +#include +#include +#include +#include +#include +#include +#include /** * @namespace graph diff --git a/graph/kruskal.cpp b/graph/kruskal.cpp index 9cf83d52d42..39f695cb04d 100644 --- a/graph/kruskal.cpp +++ b/graph/kruskal.cpp @@ -1,10 +1,7 @@ -#include // for int64_t -#include // for sort -#include // for array -#include // for char_traits, basic_istream::operator>>, basic_i... -#include // for vector -#include // for pair, make_pair - +#include +#include +#include +#include //#include // using namespace boost::multiprecision; const int mx = 1e6 + 5; diff --git a/graph/lowest_common_ancestor.cpp b/graph/lowest_common_ancestor.cpp index cfb8efbdf99..7d5ab42b49f 100644 --- a/graph/lowest_common_ancestor.cpp +++ b/graph/lowest_common_ancestor.cpp @@ -35,11 +35,11 @@ * lowest_common_ancestor(x, y) = lowest_common_ancestor(y, x) */ -#include // for assert -#include // for size_t -#include // for queue -#include // for pair, swap -#include // for vector +#include +#include +#include +#include +#include /** * \namespace graph diff --git a/graph/max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp b/graph/max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp index 6708c303c24..20571cdc518 100644 --- a/graph/max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp +++ b/graph/max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp @@ -4,14 +4,15 @@ * Copyright: 2020, Open-Source * Last Modified: May 25, 2020 */ -#include // for min -#include // for bitset -#include // for char_traits, basic_ostream, operator<<, basic_i... -#include // for numeric_limits -#include // for queue -#include // for tuple, make_tuple, tie -#include // for vector - +#include +#include +#include +#include +#include +#include +#include +#include +#include // std::max capacity of node in graph const int MAXN = 505; class Graph { diff --git a/graph/prim.cpp b/graph/prim.cpp index 9e56dba65f0..f1def6161d9 100644 --- a/graph/prim.cpp +++ b/graph/prim.cpp @@ -1,9 +1,7 @@ // C++ program to implement Prim's Algorithm -#include // for char_traits, basic_istream::operator>>, basic_... -#include // for priority_queue -#include // for vector -#include // for greater -#include // for make_pair, pair +#include +#include +#include using PII = std::pair; diff --git a/graph/topological_sort_by_kahns_algo.cpp b/graph/topological_sort_by_kahns_algo.cpp index 612186d8f61..d491fa80fa5 100644 --- a/graph/topological_sort_by_kahns_algo.cpp +++ b/graph/topological_sort_by_kahns_algo.cpp @@ -1,6 +1,8 @@ -#include // for char_traits, basic_istream::operator>>, basic_is... -#include // for queue -#include // for vector +#include +#include +#include +#include +#include std::vector topoSortKahn(int N, const std::vector > &adj); diff --git a/graph/travelling_salesman_problem.cpp b/graph/travelling_salesman_problem.cpp index 72a02b82c7e..8b46080093f 100644 --- a/graph/travelling_salesman_problem.cpp +++ b/graph/travelling_salesman_problem.cpp @@ -17,11 +17,12 @@ * This is the naive implementation of the problem. */ -#include // for min, next_permutation -#include // for assert -#include // for uint32_t, int32_t -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for vector +#include /// for std::min +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations +#include /// for limits of integral types +#include /// for std::vector /** * @namespace graph From 53008831102df9b554317cbcc5ddaec758d7235a Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:46:56 +0530 Subject: [PATCH 063/131] Revert "chore: use iwyu on geometry/**.cpp" This reverts commit 740bd65932f7db3e94b2f541b7eb3b9859be61c9. --- geometry/line_segment_intersection.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/geometry/line_segment_intersection.cpp b/geometry/line_segment_intersection.cpp index c6a6bdacc07..d523ae0a413 100644 --- a/geometry/line_segment_intersection.cpp +++ b/geometry/line_segment_intersection.cpp @@ -3,9 +3,8 @@ * @brief check whether two line segments intersect each other * or not. */ -#include // for printf -#include // for max, min -#include // for basic_istream::operator>>, char_traits, basic_i... +#include +#include /** * Define a Point. From 380127e33c0cc0fd54c51f1ef2f0af28de64b737 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:47:01 +0530 Subject: [PATCH 064/131] Revert "chore: use iwyu on divide_and_conquer/**.cpp" This reverts commit 16ee49e0868d28d7c5fbefaf86d8e5a2b1c7cd7d. --- .../karatsuba_algorithm_for_fast_multiplication.cpp | 9 ++++----- .../strassen_matrix_multiplication.cpp | 13 +++++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/divide_and_conquer/karatsuba_algorithm_for_fast_multiplication.cpp b/divide_and_conquer/karatsuba_algorithm_for_fast_multiplication.cpp index 7cbab23f565..1d9bd86cdda 100644 --- a/divide_and_conquer/karatsuba_algorithm_for_fast_multiplication.cpp +++ b/divide_and_conquer/karatsuba_algorithm_for_fast_multiplication.cpp @@ -12,11 +12,10 @@ * @author [Ameer Carlo Lubang](https://github.com/poypoyan) */ -#include // for int64_t -#include // for assert -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for max -#include // for basic_string, string +#include /// for assert +#include /// for string +#include /// for IO operations +#include /// for std::vector /** * @namespace divide_and_conquer diff --git a/divide_and_conquer/strassen_matrix_multiplication.cpp b/divide_and_conquer/strassen_matrix_multiplication.cpp index 75b727d7293..47498c966b1 100644 --- a/divide_and_conquer/strassen_matrix_multiplication.cpp +++ b/divide_and_conquer/strassen_matrix_multiplication.cpp @@ -10,14 +10,11 @@ * * @author [AshishYUO](https://github.com/AshishYUO) */ -#include // for duration, operator-, system_clock, time_point - -#include // for assert -#include // for size_t -#include // for char_traits, basic_ostream, operator<<, cout -#include // for enable_if, is_integral, is_floating_point -#include // for operator==, pair -#include // for vector +#include /// For assert operation +#include /// For std::chrono; time measurement +#include /// For I/O operations +#include /// For std::tuple +#include /// For creating dynamic arrays /** * @namespace divide_and_conquer From 1901732ee2d0d151b9eb52e539c9034012381c18 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:47:05 +0530 Subject: [PATCH 065/131] Revert "chore: use iwyu on data_structures/**.cpp" This reverts commit a3b719e3684d32d966ed64f31d3c20bdfd3b5ea3. --- data_structures/binary_search_tree.cpp | 47 +- data_structures/binary_search_tree2.cpp | 12 +- data_structures/bloom_filter.cpp | 13 +- data_structures/cll/cll.cpp | 4 - data_structures/cll/main_cll.cpp | 5 +- data_structures/doubly_linked_list.cpp | 5 +- data_structures/dsu_path_compression.cpp | 10 +- data_structures/dsu_union_rank.cpp | 9 +- data_structures/linked_list.cpp | 7 +- data_structures/list_array.cpp | 9 +- data_structures/morrisinorder.cpp | 5 +- data_structures/queue_using_array.cpp | 7 +- data_structures/queue_using_linked_list.cpp | 4 +- data_structures/queue_using_linkedlist.cpp | 3 +- data_structures/queue_using_two_stacks.cpp | 7 +- data_structures/rb_tree.cpp | 892 +++++++++++--------- data_structures/reverse_a_linked_list.cpp | 9 +- data_structures/skip_list.cpp | 12 +- data_structures/sparse_table.cpp | 11 +- data_structures/stack_using_array.cpp | 9 +- data_structures/stack_using_queue.cpp | 7 +- data_structures/test_queue.cpp | 9 +- data_structures/test_stack.cpp | 11 +- data_structures/test_stack_students.cpp | 15 +- data_structures/treap.cpp | 9 +- data_structures/tree.cpp | 54 +- data_structures/tree_234.cpp | 15 +- data_structures/trie_modern.cpp | 9 +- data_structures/trie_tree.cpp | 13 +- data_structures/trie_using_hashmap.cpp | 14 +- 30 files changed, 634 insertions(+), 602 deletions(-) diff --git a/data_structures/binary_search_tree.cpp b/data_structures/binary_search_tree.cpp index 637a587781a..86057c6c507 100644 --- a/data_structures/binary_search_tree.cpp +++ b/data_structures/binary_search_tree.cpp @@ -6,8 +6,7 @@ * \warning This program is a poor implementation - C style - and does not * utilize any of the C++ STL features. */ -#include // for NULL -#include // for operator<<, basic_ostream, char_traits, cout +#include struct node { int val; @@ -146,28 +145,28 @@ int main() { std::cin >> ch; int x; switch (ch) { - case 1: - std::cout << "\nEnter the value to be Inserted : "; - std::cin >> x; - Insert(root, x); - break; - case 2: - std::cout << "\nEnter the value to be Deleted : "; - std::cin >> x; - Remove(root, root, x); - break; - case 3: - BFT(root); - break; - case 4: - Pre(root); - break; - case 5: - In(root); - break; - case 6: - Post(root); - break; + case 1: + std::cout << "\nEnter the value to be Inserted : "; + std::cin >> x; + Insert(root, x); + break; + case 2: + std::cout << "\nEnter the value to be Deleted : "; + std::cin >> x; + Remove(root, root, x); + break; + case 3: + BFT(root); + break; + case 4: + Pre(root); + break; + case 5: + In(root); + break; + case 6: + Post(root); + break; } } while (ch != 0); diff --git a/data_structures/binary_search_tree2.cpp b/data_structures/binary_search_tree2.cpp index b1fbac9a91f..55ae3a43877 100644 --- a/data_structures/binary_search_tree2.cpp +++ b/data_structures/binary_search_tree2.cpp @@ -5,13 +5,11 @@ * @see binary_search_tree.cpp */ -#include // for assert -#include // for function -#include // for basic_ostream, operator<<, cout, char_traits -#include // for operator==, unique_ptr, allocator -#include // for vector, operator== -#include // for size_t -#include // for move +#include +#include +#include +#include +#include /** * @brief The Binary Search Tree class. diff --git a/data_structures/bloom_filter.cpp b/data_structures/bloom_filter.cpp index 75a7d71a2fa..e2f7372e0c4 100644 --- a/data_structures/bloom_filter.cpp +++ b/data_structures/bloom_filter.cpp @@ -22,13 +22,12 @@ * @author [DanArmor](https://github.com/DanArmor) */ -#include // for assert -#include // for function -#include // for initializer_list -#include // for basic_string, string -#include // for vector -#include // for operator<<, basic_ostream, cout -#include // for size_t +#include /// for assert +#include /// for list of hash functions for bloom filter constructor +#include /// for initializer_list for bloom filter constructor +#include /// for testing on strings +#include /// for std::vector +#include /// for IO operations /** * @namespace data_structures diff --git a/data_structures/cll/cll.cpp b/data_structures/cll/cll.cpp index 68f2e93d878..42bc9067e20 100644 --- a/data_structures/cll/cll.cpp +++ b/data_structures/cll/cll.cpp @@ -2,10 +2,6 @@ A simple class for Cicular Linear Linked List */ #include "cll.h" - -#include // for NULL -#include // for basic_ostream, char_traits, operator<<, cout - using namespace std; /* Constructor */ diff --git a/data_structures/cll/main_cll.cpp b/data_structures/cll/main_cll.cpp index 3f67b628b9e..0b6bfd3edef 100644 --- a/data_structures/cll/main_cll.cpp +++ b/data_structures/cll/main_cll.cpp @@ -1,7 +1,4 @@ -#include // for basic_ostream, operator<<, char_traits, cout, endl - -#include "cll.h" // for cll - +#include "cll.h" using namespace std; int main() { diff --git a/data_structures/doubly_linked_list.cpp b/data_structures/doubly_linked_list.cpp index ea09a1d7a29..30cc257d84f 100644 --- a/data_structures/doubly_linked_list.cpp +++ b/data_structures/doubly_linked_list.cpp @@ -1,5 +1,6 @@ -#include // for NULL -#include // for operator<<, basic_ostream, cout, char_traits +#include +#include +#include struct node { int val; diff --git a/data_structures/dsu_path_compression.cpp b/data_structures/dsu_path_compression.cpp index 8bcaf7cbfb9..9dff7b40bb0 100644 --- a/data_structures/dsu_path_compression.cpp +++ b/data_structures/dsu_path_compression.cpp @@ -18,12 +18,10 @@ * @see dsu_union_rank.cpp */ -#include // for assert -#include // for uint64_t -#include // for char_traits, basic_ostream, operator<<, cout, endl -#include // for vector -#include // for max, min -#include // for swap +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations +#include /// for std::vector using std::cout; using std::endl; diff --git a/data_structures/dsu_union_rank.cpp b/data_structures/dsu_union_rank.cpp index 3a491254a46..4ca53bb76f6 100644 --- a/data_structures/dsu_union_rank.cpp +++ b/data_structures/dsu_union_rank.cpp @@ -19,11 +19,10 @@ * @see dsu_path_compression.cpp */ -#include // for assert -#include // for uint64_t -#include // for char_traits, basic_ostream, operator<<, cout, endl -#include // for vector -#include // for swap +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations +#include /// for std::vector using std::cout; using std::endl; diff --git a/data_structures/linked_list.cpp b/data_structures/linked_list.cpp index c10b76c98ad..08bfe68b1e9 100644 --- a/data_structures/linked_list.cpp +++ b/data_structures/linked_list.cpp @@ -14,10 +14,9 @@ * to point to the node that the current node is pointing to, and then returning * the current node to heap store. */ -#include // for isdigit -#include // for operator<<, basic_ostream, cout, basic_istream, cin -#include // for shared_ptr, __shared_ptr_access, make_shared -#include // for char_traits, basic_string, operator>>, stoi, string +#include +#include +#include /** * @namespace data_structures diff --git a/data_structures/list_array.cpp b/data_structures/list_array.cpp index 0660d4b08c8..8995b6ce2e1 100644 --- a/data_structures/list_array.cpp +++ b/data_structures/list_array.cpp @@ -14,11 +14,10 @@ * and print the list. */ -#include // for array -#include // for assert -#include // for uint64_t -#include // for operator<<, basic_ostream::operator<<, basic_ost... -#include // for swap +#include /// for std::array +#include /// for assert +#include /// for integral typedefs +#include /// for io operations /** * @namespace data_structures diff --git a/data_structures/morrisinorder.cpp b/data_structures/morrisinorder.cpp index ae70bc1e74f..f1f9e068c9f 100644 --- a/data_structures/morrisinorder.cpp +++ b/data_structures/morrisinorder.cpp @@ -1,6 +1,5 @@ -#include // for NULL -#include // for char_traits, operator<<, basic_ostream, basic_os... -#include // for queue +#include +#include /************************** @author shrutisheoran diff --git a/data_structures/queue_using_array.cpp b/data_structures/queue_using_array.cpp index 5afd4701171..cbd84a62397 100644 --- a/data_structures/queue_using_array.cpp +++ b/data_structures/queue_using_array.cpp @@ -17,10 +17,9 @@ * @author [Pooja](https://github.com/pooja-git11) * @author [Farbod Ahmadian](https://github.com/farbodahm) */ -#include // for exit -#include // for array -#include // for int16_t, int8_t, uint16_t -#include // for operator<<, basic_ostream, cout, char_traits +#include /// for std::array +#include /// for integral typedefs +#include /// for io operations constexpr uint16_t max_size{10}; ///< Maximum size of the queue diff --git a/data_structures/queue_using_linked_list.cpp b/data_structures/queue_using_linked_list.cpp index 39eae2895c7..7b44d240c74 100644 --- a/data_structures/queue_using_linked_list.cpp +++ b/data_structures/queue_using_linked_list.cpp @@ -1,6 +1,4 @@ -#include // for NULL -#include // for operator<<, basic_ostream, char_traits, cout - +#include using namespace std; struct node { diff --git a/data_structures/queue_using_linkedlist.cpp b/data_structures/queue_using_linkedlist.cpp index d487cf7d342..f1bf18123f9 100644 --- a/data_structures/queue_using_linkedlist.cpp +++ b/data_structures/queue_using_linkedlist.cpp @@ -1,8 +1,7 @@ /* Write a program to implement Queue using linkedlist. */ -#include // for NULL, exit -#include // for operator<<, basic_ostream, cout, char_traits +#include struct linkedlist { int data; diff --git a/data_structures/queue_using_two_stacks.cpp b/data_structures/queue_using_two_stacks.cpp index 117f5b2c416..a096446865a 100644 --- a/data_structures/queue_using_two_stacks.cpp +++ b/data_structures/queue_using_two_stacks.cpp @@ -5,10 +5,9 @@ * Implementation of a Queue using two Stacks. */ -#include // for exit -#include // for assert -#include // for operator<<, basic_ostream, char_traits, cout, cerr -#include // for stack +#include +#include +#include namespace { /** diff --git a/data_structures/rb_tree.cpp b/data_structures/rb_tree.cpp index cda06d63939..f2a51a30c20 100644 --- a/data_structures/rb_tree.cpp +++ b/data_structures/rb_tree.cpp @@ -1,431 +1,505 @@ -#include // for NULL -#include +#include using namespace std; -struct node { - int key; - node *parent; - char color; - node *left; - node *right; +struct node +{ + int key; + node *parent; + char color; + node *left; + node *right; }; -class RBtree { - node *root; - node *q; - - public: - RBtree() { - q = NULL; - root = NULL; - } - void insert(); - void insertfix(node *); - void leftrotate(node *); - void rightrotate(node *); - void del(); - node *successor(node *); - void delfix(node *); - void disp(); - void display(node *); - void search(); +class RBtree +{ + node *root; + node *q; +public: + RBtree() + { + q = NULL; + root = NULL; + } + void insert(); + void insertfix(node *); + void leftrotate(node *); + void rightrotate(node *); + void del(); + node* successor(node *); + void delfix(node *); + void disp(); + void display(node *); + void search(); }; -void RBtree::insert() { - int z, i = 0; - cout << "\nEnter key of the node to be inserted: "; - cin >> z; - node *p, *q; - node *t = new node; - t->key = z; - t->left = NULL; - t->right = NULL; - t->color = 'r'; - p = root; - q = NULL; - if (root == NULL) { - root = t; - t->parent = NULL; - } else { - while (p != NULL) { - q = p; - if (p->key < t->key) - p = p->right; - else - p = p->left; - } - t->parent = q; - if (q->key < t->key) - q->right = t; - else - q->left = t; - } - insertfix(t); +void RBtree::insert() +{ + int z, i = 0; + cout << "\nEnter key of the node to be inserted: "; + cin >> z; + node *p, *q; + node *t = new node; + t->key = z; + t->left = NULL; + t->right = NULL; + t->color = 'r'; + p = root; + q = NULL; + if (root == NULL) + { + root = t; + t->parent = NULL; + } + else + { + while (p != NULL) + { + q = p; + if (p->key < t->key) + p = p->right; + else + p = p->left; + } + t->parent = q; + if (q->key < t->key) + q->right = t; + else + q->left = t; + } + insertfix(t); } -void RBtree::insertfix(node *t) { - node *u; - if (root == t) { - t->color = 'b'; - return; - } - while (t->parent != NULL && t->parent->color == 'r') { - node *g = t->parent->parent; - if (g->left == t->parent) { - if (g->right != NULL) { - u = g->right; - if (u->color == 'r') { - t->parent->color = 'b'; - u->color = 'b'; - g->color = 'r'; - t = g; - } - } else { - if (t->parent->right == t) { - t = t->parent; - leftrotate(t); - } - t->parent->color = 'b'; - g->color = 'r'; - rightrotate(g); - } - } else { - if (g->left != NULL) { - u = g->left; - if (u->color == 'r') { - t->parent->color = 'b'; - u->color = 'b'; - g->color = 'r'; - t = g; - } - } else { - if (t->parent->left == t) { - t = t->parent; - rightrotate(t); - } - t->parent->color = 'b'; - g->color = 'r'; - leftrotate(g); - } - } - root->color = 'b'; - } +void RBtree::insertfix(node *t) +{ + node *u; + if (root == t) + { + t->color = 'b'; + return; + } + while (t->parent != NULL && t->parent->color == 'r') + { + node *g = t->parent->parent; + if (g->left == t->parent) + { + if (g->right != NULL) + { + u = g->right; + if (u->color == 'r') + { + t->parent->color = 'b'; + u->color = 'b'; + g->color = 'r'; + t = g; + } + } + else + { + if (t->parent->right == t) + { + t = t->parent; + leftrotate(t); + } + t->parent->color = 'b'; + g->color = 'r'; + rightrotate(g); + } + } + else + { + if (g->left != NULL) + { + u = g->left; + if (u->color == 'r') + { + t->parent->color = 'b'; + u->color = 'b'; + g->color = 'r'; + t = g; + } + } + else + { + if (t->parent->left == t) + { + t = t->parent; + rightrotate(t); + } + t->parent->color = 'b'; + g->color = 'r'; + leftrotate(g); + } + } + root->color = 'b'; + } } -void RBtree::del() { - if (root == NULL) { - cout << "\nEmpty Tree."; - return; - } - int x; - cout << "\nEnter the key of the node to be deleted: "; - cin >> x; - node *p; - p = root; - node *y = NULL; - node *q = NULL; - int found = 0; - while (p != NULL && found == 0) { - if (p->key == x) - found = 1; - if (found == 0) { - if (p->key < x) - p = p->right; - else - p = p->left; - } - } - if (found == 0) { - cout << "\nElement Not Found."; - return; - } else { - cout << "\nDeleted Element: " << p->key; - cout << "\nColour: "; - if (p->color == 'b') - cout << "Black\n"; - else - cout << "Red\n"; +void RBtree::del() +{ + if (root == NULL) + { + cout << "\nEmpty Tree."; + return; + } + int x; + cout << "\nEnter the key of the node to be deleted: "; + cin >> x; + node *p; + p = root; + node *y = NULL; + node *q = NULL; + int found = 0; + while (p != NULL && found == 0) + { + if (p->key == x) + found = 1; + if (found == 0) + { + if (p->key < x) + p = p->right; + else + p = p->left; + } + } + if (found == 0) + { + cout << "\nElement Not Found."; + return; + } + else + { + cout << "\nDeleted Element: " << p->key; + cout << "\nColour: "; + if (p->color == 'b') + cout << "Black\n"; + else + cout << "Red\n"; - if (p->parent != NULL) - cout << "\nParent: " << p->parent->key; - else - cout << "\nThere is no parent of the node. "; - if (p->right != NULL) - cout << "\nRight Child: " << p->right->key; - else - cout << "\nThere is no right child of the node. "; - if (p->left != NULL) - cout << "\nLeft Child: " << p->left->key; - else - cout << "\nThere is no left child of the node. "; - cout << "\nNode Deleted."; - if (p->left == NULL || p->right == NULL) - y = p; - else - y = successor(p); - if (y->left != NULL) - q = y->left; - else { - if (y->right != NULL) - q = y->right; - else - q = NULL; - } - if (q != NULL) - q->parent = y->parent; - if (y->parent == NULL) - root = q; - else { - if (y == y->parent->left) - y->parent->left = q; - else - y->parent->right = q; - } - if (y != p) { - p->color = y->color; - p->key = y->key; - } - if (y->color == 'b') - delfix(q); - } + if (p->parent != NULL) + cout << "\nParent: " << p->parent->key; + else + cout << "\nThere is no parent of the node. "; + if (p->right != NULL) + cout << "\nRight Child: " << p->right->key; + else + cout << "\nThere is no right child of the node. "; + if (p->left != NULL) + cout << "\nLeft Child: " << p->left->key; + else + cout << "\nThere is no left child of the node. "; + cout << "\nNode Deleted."; + if (p->left == NULL || p->right == NULL) + y = p; + else + y = successor(p); + if (y->left != NULL) + q = y->left; + else + { + if (y->right != NULL) + q = y->right; + else + q = NULL; + } + if (q != NULL) + q->parent = y->parent; + if (y->parent == NULL) + root = q; + else + { + if (y == y->parent->left) + y->parent->left = q; + else + y->parent->right = q; + } + if (y != p) + { + p->color = y->color; + p->key = y->key; + } + if (y->color == 'b') + delfix(q); + } } -void RBtree::delfix(node *p) { - node *s; - while (p != root && p->color == 'b') { - if (p->parent->left == p) { - s = p->parent->right; - if (s->color == 'r') { - s->color = 'b'; - p->parent->color = 'r'; - leftrotate(p->parent); - s = p->parent->right; - } - if (s->right->color == 'b' && s->left->color == 'b') { - s->color = 'r'; - p = p->parent; - } else { - if (s->right->color == 'b') { - s->left->color = 'b'; - s->color = 'r'; - rightrotate(s); - s = p->parent->right; - } - s->color = p->parent->color; - p->parent->color = 'b'; - s->right->color = 'b'; - leftrotate(p->parent); - p = root; - } - } else { - s = p->parent->left; - if (s->color == 'r') { - s->color = 'b'; - p->parent->color = 'r'; - rightrotate(p->parent); - s = p->parent->left; - } - if (s->left->color == 'b' && s->right->color == 'b') { - s->color = 'r'; - p = p->parent; - } else { - if (s->left->color == 'b') { - s->right->color = 'b'; - s->color = 'r'; - leftrotate(s); - s = p->parent->left; - } - s->color = p->parent->color; - p->parent->color = 'b'; - s->left->color = 'b'; - rightrotate(p->parent); - p = root; - } - } - p->color = 'b'; - root->color = 'b'; - } +void RBtree::delfix(node *p) +{ + node *s; + while (p != root && p->color == 'b') + { + if (p->parent->left == p) + { + s = p->parent->right; + if (s->color == 'r') + { + s->color = 'b'; + p->parent->color = 'r'; + leftrotate(p->parent); + s = p->parent->right; + } + if (s->right->color == 'b'&&s->left->color == 'b') + { + s->color = 'r'; + p = p->parent; + } + else + { + if (s->right->color == 'b') + { + s->left->color = 'b'; + s->color = 'r'; + rightrotate(s); + s = p->parent->right; + } + s->color = p->parent->color; + p->parent->color = 'b'; + s->right->color = 'b'; + leftrotate(p->parent); + p = root; + } + } + else + { + s = p->parent->left; + if (s->color == 'r') + { + s->color = 'b'; + p->parent->color = 'r'; + rightrotate(p->parent); + s = p->parent->left; + } + if (s->left->color == 'b'&&s->right->color == 'b') + { + s->color = 'r'; + p = p->parent; + } + else + { + if (s->left->color == 'b') + { + s->right->color = 'b'; + s->color = 'r'; + leftrotate(s); + s = p->parent->left; + } + s->color = p->parent->color; + p->parent->color = 'b'; + s->left->color = 'b'; + rightrotate(p->parent); + p = root; + } + } + p->color = 'b'; + root->color = 'b'; + } } -void RBtree::leftrotate(node *p) { - if (p->right == NULL) - return; - else { - node *y = p->right; - if (y->left != NULL) { - p->right = y->left; - y->left->parent = p; - } else - p->right = NULL; - if (p->parent != NULL) - y->parent = p->parent; - if (p->parent == NULL) - root = y; - else { - if (p == p->parent->left) - p->parent->left = y; - else - p->parent->right = y; - } - y->left = p; - p->parent = y; - } +void RBtree::leftrotate(node *p) +{ + if (p->right == NULL) + return; + else + { + node *y = p->right; + if (y->left != NULL) + { + p->right = y->left; + y->left->parent = p; + } + else + p->right = NULL; + if (p->parent != NULL) + y->parent = p->parent; + if (p->parent == NULL) + root = y; + else + { + if (p == p->parent->left) + p->parent->left = y; + else + p->parent->right = y; + } + y->left = p; + p->parent = y; + } } -void RBtree::rightrotate(node *p) { - if (p->left == NULL) - return; - else { - node *y = p->left; - if (y->right != NULL) { - p->left = y->right; - y->right->parent = p; - } else - p->left = NULL; - if (p->parent != NULL) - y->parent = p->parent; - if (p->parent == NULL) - root = y; - else { - if (p == p->parent->left) - p->parent->left = y; - else - p->parent->right = y; - } - y->right = p; - p->parent = y; - } +void RBtree::rightrotate(node *p) +{ + if (p->left == NULL) + return; + else + { + node *y = p->left; + if (y->right != NULL) + { + p->left = y->right; + y->right->parent = p; + } + else + p->left = NULL; + if (p->parent != NULL) + y->parent = p->parent; + if (p->parent == NULL) + root = y; + else + { + if (p == p->parent->left) + p->parent->left = y; + else + p->parent->right = y; + } + y->right = p; + p->parent = y; + } } -node *RBtree::successor(node *p) { - node *y = NULL; - if (p->left != NULL) { - y = p->left; - while (y->right != NULL) y = y->right; - } else { - y = p->right; - while (y->left != NULL) y = y->left; - } - return y; +node* RBtree::successor(node *p) +{ + node *y = NULL; + if (p->left != NULL) + { + y = p->left; + while (y->right != NULL) + y = y->right; + } + else + { + y = p->right; + while (y->left != NULL) + y = y->left; + } + return y; } -void RBtree::disp() { display(root); } -void RBtree::display(node *p) { - if (root == NULL) { - cout << "\nEmpty Tree."; - return; - } - if (p != NULL) { - cout << "\n\t NODE: "; - cout << "\n Key: " << p->key; - cout << "\n Colour: "; - if (p->color == 'b') - cout << "Black"; - else - cout << "Red"; - if (p->parent != NULL) - cout << "\n Parent: " << p->parent->key; - else - cout << "\n There is no parent of the node. "; - if (p->right != NULL) - cout << "\n Right Child: " << p->right->key; - else - cout << "\n There is no right child of the node. "; - if (p->left != NULL) - cout << "\n Left Child: " << p->left->key; - else - cout << "\n There is no left child of the node. "; - cout << endl; - if (p->left) { - cout << "\n\nLeft:\n"; - display(p->left); - } - /*else - cout<<"\nNo Left Child.\n";*/ - if (p->right) { - cout << "\n\nRight:\n"; - display(p->right); - } - /*else - cout<<"\nNo Right Child.\n"*/ - } +void RBtree::disp() +{ + display(root); +} +void RBtree::display(node *p) +{ + if (root == NULL) + { + cout << "\nEmpty Tree."; + return; + } + if (p != NULL) + { + cout << "\n\t NODE: "; + cout << "\n Key: " << p->key; + cout << "\n Colour: "; + if (p->color == 'b') + cout << "Black"; + else + cout << "Red"; + if (p->parent != NULL) + cout << "\n Parent: " << p->parent->key; + else + cout << "\n There is no parent of the node. "; + if (p->right != NULL) + cout << "\n Right Child: " << p->right->key; + else + cout << "\n There is no right child of the node. "; + if (p->left != NULL) + cout << "\n Left Child: " << p->left->key; + else + cout << "\n There is no left child of the node. "; + cout << endl; + if (p->left) + { + cout << "\n\nLeft:\n"; + display(p->left); + } + /*else + cout<<"\nNo Left Child.\n";*/ + if (p->right) + { + cout << "\n\nRight:\n"; + display(p->right); + } + /*else + cout<<"\nNo Right Child.\n"*/ + } } -void RBtree::search() { - if (root == NULL) { - cout << "\nEmpty Tree\n"; - return; - } - int x; - cout << "\n Enter key of the node to be searched: "; - cin >> x; - node *p = root; - int found = 0; - while (p != NULL && found == 0) { - if (p->key == x) - found = 1; - if (found == 0) { - if (p->key < x) - p = p->right; - else - p = p->left; - } - } - if (found == 0) - cout << "\nElement Not Found."; - else { - cout << "\n\t FOUND NODE: "; - cout << "\n Key: " << p->key; - cout << "\n Colour: "; - if (p->color == 'b') - cout << "Black"; - else - cout << "Red"; - if (p->parent != NULL) - cout << "\n Parent: " << p->parent->key; - else - cout << "\n There is no parent of the node. "; - if (p->right != NULL) - cout << "\n Right Child: " << p->right->key; - else - cout << "\n There is no right child of the node. "; - if (p->left != NULL) - cout << "\n Left Child: " << p->left->key; - else - cout << "\n There is no left child of the node. "; - cout << endl; - } +void RBtree::search() +{ + if (root == NULL) + { + cout << "\nEmpty Tree\n"; + return; + } + int x; + cout << "\n Enter key of the node to be searched: "; + cin >> x; + node *p = root; + int found = 0; + while (p != NULL && found == 0) + { + if (p->key == x) + found = 1; + if (found == 0) + { + if (p->key < x) + p = p->right; + else + p = p->left; + } + } + if (found == 0) + cout << "\nElement Not Found."; + else + { + cout << "\n\t FOUND NODE: "; + cout << "\n Key: " << p->key; + cout << "\n Colour: "; + if (p->color == 'b') + cout << "Black"; + else + cout << "Red"; + if (p->parent != NULL) + cout << "\n Parent: " << p->parent->key; + else + cout << "\n There is no parent of the node. "; + if (p->right != NULL) + cout << "\n Right Child: " << p->right->key; + else + cout << "\n There is no right child of the node. "; + if (p->left != NULL) + cout << "\n Left Child: " << p->left->key; + else + cout << "\n There is no left child of the node. "; + cout << endl; + + } } -int main() { - int ch, y = 0; - RBtree obj; - do { - cout << "\n\t RED BLACK TREE "; - cout << "\n 1. Insert in the tree "; - cout << "\n 2. Delete a node from the tree"; - cout << "\n 3. Search for an element in the tree"; - cout << "\n 4. Display the tree "; - cout << "\n 5. Exit "; - cout << "\nEnter Your Choice: "; - cin >> ch; - switch (ch) { - case 1: - obj.insert(); - cout << "\nNode Inserted.\n"; - break; - case 2: - obj.del(); - break; - case 3: - obj.search(); - break; - case 4: - obj.disp(); - break; - case 5: - y = 1; - break; - default: - cout << "\nEnter a Valid Choice."; - } - cout << endl; +int main() +{ + int ch, y = 0; + RBtree obj; + do + { + cout << "\n\t RED BLACK TREE "; + cout << "\n 1. Insert in the tree "; + cout << "\n 2. Delete a node from the tree"; + cout << "\n 3. Search for an element in the tree"; + cout << "\n 4. Display the tree "; + cout << "\n 5. Exit "; + cout << "\nEnter Your Choice: "; + cin >> ch; + switch (ch) + { + case 1: obj.insert(); + cout << "\nNode Inserted.\n"; + break; + case 2: obj.del(); + break; + case 3: obj.search(); + break; + case 4: obj.disp(); + break; + case 5: y = 1; + break; + default: cout << "\nEnter a Valid Choice."; + } + cout << endl; - } while (y != 1); - return 1; + } while (y != 1); + return 1; } diff --git a/data_structures/reverse_a_linked_list.cpp b/data_structures/reverse_a_linked_list.cpp index d776c83bfc2..d8315b4bb47 100644 --- a/data_structures/reverse_a_linked_list.cpp +++ b/data_structures/reverse_a_linked_list.cpp @@ -22,12 +22,9 @@ *scenes](https://drive.google.com/file/d/1pM5COF0wx-wermnNy_svtyZquaCUP2xS/view?usp=sharing) */ -#include // for int32_t -#include // for exit -#include // for assert -#include // for char_traits, basic_ostream, operator<<, cerr, cout -#include // for bad_alloc -#include // for logic_error +#include /// for assert +#include /// for I/O operations +#include /// for managing dynamic storage /** * @namespace data_structures diff --git a/data_structures/skip_list.cpp b/data_structures/skip_list.cpp index bac77da2c9b..9cf8c430f4a 100644 --- a/data_structures/skip_list.cpp +++ b/data_structures/skip_list.cpp @@ -13,12 +13,12 @@ * @author [Krishna Vedala](https://github.com/kvedala) */ -#include // for array -#include // for time -#include // for basic_ostream, operator<<, char_traits, cout -#include // for shared_ptr, __shared_ptr_access, operator!=, ope... -#include // for vector -#include // for rand, srand, RAND_MAX +#include +#include +#include +#include +#include +#include /** \namespace data_structures * \brief Data-structure algorithms diff --git a/data_structures/sparse_table.cpp b/data_structures/sparse_table.cpp index 654c81d6ede..507dd39449d 100644 --- a/data_structures/sparse_table.cpp +++ b/data_structures/sparse_table.cpp @@ -22,13 +22,10 @@ * `gcd()`, `lcm()`, and `max()` by changing a few lines of code. */ -#include // for copy -#include // for array -#include // for assert -#include // for size_t -#include // for int64_t, uint32_t, uint8_t -#include // for char_traits, basic_ostream, operator<<, cout, endl -#include // for begin, end +#include /// for std::array +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations /** * @namespace data_structures diff --git a/data_structures/stack_using_array.cpp b/data_structures/stack_using_array.cpp index bda5ff0f267..73feaf445cc 100644 --- a/data_structures/stack_using_array.cpp +++ b/data_structures/stack_using_array.cpp @@ -1,8 +1,7 @@ -#include // for assert -#include // for char_traits, basic_ostream, cout, operator<<, endl -#include // for unique_ptr -#include // for out_of_range -#include // for basic_string, operator==, string +#include /// For std::assert +#include /// For std::cout +#include /// For std::unique_ptr +#include /// For std::out_of_range /** * @namespace diff --git a/data_structures/stack_using_queue.cpp b/data_structures/stack_using_queue.cpp index 0bf69170dee..7867d55caa0 100644 --- a/data_structures/stack_using_queue.cpp +++ b/data_structures/stack_using_queue.cpp @@ -8,9 +8,10 @@ * [StudyTonight](https://www.studytonight.com/data-structures/stack-using-queue) * @author [tushar2407](https://github.com/tushar2407) */ -#include // for assert -#include // for int64_t, uint32_t -#include // for queue, swap +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations +#include /// for queue data structure /** * @namespace data_structures diff --git a/data_structures/test_queue.cpp b/data_structures/test_queue.cpp index 3463f490beb..d0fa3502ece 100644 --- a/data_structures/test_queue.cpp +++ b/data_structures/test_queue.cpp @@ -1,10 +1,7 @@ -#include // for assert -#include // for operator<<, basic_ostream, cout -#include // for operator== -#include // for invalid_argument -#include // for vector, operator== +#include /// for assert +#include /// for std::cout -#include "./queue.hpp" // for queue +#include "./queue.hpp" template void testConstructedQueueIsEmpty() { diff --git a/data_structures/test_stack.cpp b/data_structures/test_stack.cpp index 551261ac8cf..81039e7962c 100644 --- a/data_structures/test_stack.cpp +++ b/data_structures/test_stack.cpp @@ -1,10 +1,9 @@ -#include // for assert -#include // for operator<<, basic_ostream, cout -#include // for invalid_argument -#include // for vector, operator== -#include // for operator== +#include /// for assert +#include /// for std::cout +#include /// std::invalid_argument +#include /// for std::vector -#include "./stack.hpp" // for stack +#include "./stack.hpp" template void testConstructedStackIsEmpty() { diff --git a/data_structures/test_stack_students.cpp b/data_structures/test_stack_students.cpp index 2b2b275bc9b..dc3514bcb1b 100644 --- a/data_structures/test_stack_students.cpp +++ b/data_structures/test_stack_students.cpp @@ -8,15 +8,14 @@ * ./main student.txt ************************************************************ * */ -#include // for assert -#include // for NAN -#include // for basic_ostream, basic_ifstream, basic_istream -#include // for operator<<, setprecision, _Setprecision -#include // for cout -#include // for char_traits, operator>>, basic_string, operat... -#include // for operator== +#include +#include +#include +#include +#include +#include -#include "./stack.hpp" // for stack +#include "./stack.hpp" int main(int argc, char* argv[]) { double GPA = NAN; diff --git a/data_structures/treap.cpp b/data_structures/treap.cpp index 8170fa6c1de..5be3b241643 100644 --- a/data_structures/treap.cpp +++ b/data_structures/treap.cpp @@ -17,11 +17,10 @@ * @author [Kairao ZHENG](https://github.com/fgmn) */ -#include // for rand -#include // for array -#include // for assert -#include // for INT32_MAX -#include // for operator<<, basic_ostream, cout +#include /// For array +#include /// For assert +#include /// for integral typedefs +#include /// For IO operations /** * @namespace diff --git a/data_structures/tree.cpp b/data_structures/tree.cpp index 980709bab98..f46c31ff22a 100644 --- a/data_structures/tree.cpp +++ b/data_structures/tree.cpp @@ -1,7 +1,5 @@ -#include // for NULL -#include // for operator<<, basic_ostream, char_traits, cout -#include // for list - +#include +#include using namespace std; struct node { @@ -92,30 +90,30 @@ int main() { cout << "\nEnter Your Choice : "; cin >> ch; switch (ch) { - case 1: - int x; - char pos; - cout << "\nEnter the value to be Inserted : "; - cin >> x; - cout << "\nLeft or Right of Root : "; - cin >> pos; - if (pos == 'l') - CreateTree(root, root->left, x, pos); - else if (pos == 'r') - CreateTree(root, root->right, x, pos); - break; - case 2: - BFT(root); - break; - case 3: - Pre(root); - break; - case 4: - In(root); - break; - case 5: - Post(root); - break; + case 1: + int x; + char pos; + cout << "\nEnter the value to be Inserted : "; + cin >> x; + cout << "\nLeft or Right of Root : "; + cin >> pos; + if (pos == 'l') + CreateTree(root, root->left, x, pos); + else if (pos == 'r') + CreateTree(root, root->right, x, pos); + break; + case 2: + BFT(root); + break; + case 3: + Pre(root); + break; + case 4: + In(root); + break; + case 5: + Post(root); + break; } } while (ch != 0); } diff --git a/data_structures/tree_234.cpp b/data_structures/tree_234.cpp index e87b42191b6..46de03bfaef 100644 --- a/data_structures/tree_234.cpp +++ b/data_structures/tree_234.cpp @@ -13,14 +13,13 @@ Introduction](https://www.educative.io/page/5689413791121408/80001) * Other operations should be easy to be added. * @author [liuhuan](https://github.com/fedom) */ -#include // for int64_t, int8_t, int16_t -#include // for array -#include // for assert -#include // for basic_ostream, operator<<, basic_ofstream, ofstream -#include // for cout -#include // for allocator, unique_ptr -#include // for queue -#include // for char_traits, basic_string, operator+, stoi, to_s... +#include /// for std::array +#include /// for assert +#include /// for std::ofstream +#include /// for std::cout +#include /// for std::unique_ptr +#include /// for std::queue +#include /// for std::to_string /** * @namespace data_structures diff --git a/data_structures/trie_modern.cpp b/data_structures/trie_modern.cpp index b0da638e8d8..470af07a456 100644 --- a/data_structures/trie_modern.cpp +++ b/data_structures/trie_modern.cpp @@ -4,12 +4,9 @@ * @author Anmol3299 * \brief A basic implementation of trie class to store only lower-case strings. */ -#include // for size_t -#include // for basic_ostream, operator<<, cout -#include // for shared_ptr, __shared_ptr_access, make_shared -#include // for runtime_error -#include // for basic_string, char_traits, string -#include // for move +#include // for io operations +#include // for std::shared_ptr<> +#include // for std::string class /** * A basic implementation of trie class to store only lower-case strings. diff --git a/data_structures/trie_tree.cpp b/data_structures/trie_tree.cpp index 1c852f21060..e966b2dfde2 100644 --- a/data_structures/trie_tree.cpp +++ b/data_structures/trie_tree.cpp @@ -7,13 +7,12 @@ * @note the function ::data_structure::trie::deleteString might be erroneous * @see trie_modern.cpp */ -#include // for uint8_t -#include // for array -#include // for assert -#include // for operator<<, basic_ostream, cout, basic_ostream::... -#include // for shared_ptr, __shared_ptr_access -#include // for char_traits, basic_string, string -#include // for exit, EXIT_FAILURE +#include +#include +#include +#include +#include +#include /** \namespace data_structures * \brief Data-structure algorithms diff --git a/data_structures/trie_using_hashmap.cpp b/data_structures/trie_using_hashmap.cpp index b043720fd01..5fb9602a9bb 100644 --- a/data_structures/trie_using_hashmap.cpp +++ b/data_structures/trie_using_hashmap.cpp @@ -10,14 +10,12 @@ * in trie. * @see trie_modern.cpp for difference */ -#include // for assert -#include // for basic_ostream, operator<<, char_traits, cout -#include // for shared_ptr, __shared_ptr_access, make_shared -#include // for stack -#include // for unordered_map, operator==, _Node_iterator_base -#include // for vector -#include // for basic_string, string, operator<< -#include // for pair +#include /// for assert +#include /// for IO operations +#include /// for std::shared_ptr +#include /// for std::stack +#include /// for std::unordered_map +#include /// for std::vector /** * @namespace data_structures From d0af25f22fa3325a9c67869378e90a46a215e883 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:47:11 +0530 Subject: [PATCH 066/131] Revert "chore: use iwyu on cpu_scheduling_algorithms/**.cpp" This reverts commit 24e597f7e249c7fd6998b2db39eba7a91d484455. --- cpu_scheduling_algorithms/fcfs_scheduling.cpp | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/cpu_scheduling_algorithms/fcfs_scheduling.cpp b/cpu_scheduling_algorithms/fcfs_scheduling.cpp index 4e899e5df32..6eab989e4f2 100644 --- a/cpu_scheduling_algorithms/fcfs_scheduling.cpp +++ b/cpu_scheduling_algorithms/fcfs_scheduling.cpp @@ -9,17 +9,16 @@ * @author [Pratyush Vatsa](https://github.com/Pratyush219) */ -#include // for sort -#include // for assert -#include // for uint32_t -#include // for rand, srand, size_t -#include // for time -#include // for setw, operator<<, _Setw, setprecision, _Set... -#include // for basic_ostream, char_traits, operator<<, left -#include // for priority_queue -#include // for unordered_set, operator== -#include // for vector, operator==, allocator -#include // for tuple, get, make_tuple, operator==, swap +#include /// for sorting +#include /// for assert +#include /// for integral typedefs +#include /// random number generation +#include /// for time +#include /// for formatting the output +#include /// for IO operations +#include /// for std::priority_queue +#include /// for std::unordered_set +#include /// for std::vector using std::cin; using std::cout; From d8895b70b2d0cc57e69018785ea088613c41797c Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:47:17 +0530 Subject: [PATCH 067/131] Revert "chore: use iwyu on ciphers/**.cpp" This reverts commit 3d80295883d15a6753f1e0e746c19a0c3ea35abe. --- ciphers/a1z26_cipher.cpp | 18 +-- ciphers/atbash_cipher.cpp | 9 +- ciphers/base64_encoding.cpp | 7 +- ciphers/elliptic_curve_key_exchange.cpp | 8 +- ciphers/morse_code.cpp | 9 +- ciphers/vigenere_cipher.cpp | 197 +++++++++++------------- 6 files changed, 113 insertions(+), 135 deletions(-) diff --git a/ciphers/a1z26_cipher.cpp b/ciphers/a1z26_cipher.cpp index 7aa28a02e2a..82a3d3bb4e0 100644 --- a/ciphers/a1z26_cipher.cpp +++ b/ciphers/a1z26_cipher.cpp @@ -9,16 +9,14 @@ * @author [Focusucof](https://github.com/Focusucof) */ -#include // for tolower, toupper -#include // for replace, transform -#include // for assert -#include // for uint8_t -#include // for basic_ostream, operator<<, basic_istream, cout -#include // for map -#include // for basic_stringstream -#include // for basic_string, char_traits, operator<<, string -#include // for vector -#include // for pair +#include /// for std::transform and std::replace +#include /// for assert +#include /// for uint8_t +#include /// for IO operations +#include /// for std::map +#include /// for std::stringstream +#include /// for std::string +#include /// for std::vector /** * @namespace ciphers diff --git a/ciphers/atbash_cipher.cpp b/ciphers/atbash_cipher.cpp index 11b2f3dc2e6..4f0d793f237 100644 --- a/ciphers/atbash_cipher.cpp +++ b/ciphers/atbash_cipher.cpp @@ -12,11 +12,10 @@ * * @author [Focusucof](https://github.com/Focusucof) */ -#include // for assert -#include // for basic_ostream, operator<<, cout, endl -#include // for map -#include // for basic_string, char_traits, allocator, operator<< -#include // for pair +#include /// for assert +#include /// for IO operations +#include /// for std::map +#include /// for std::string /** \namespace ciphers * \brief Algorithms for encryption and decryption diff --git a/ciphers/base64_encoding.cpp b/ciphers/base64_encoding.cpp index d4090a59646..52bce90ff9a 100644 --- a/ciphers/base64_encoding.cpp +++ b/ciphers/base64_encoding.cpp @@ -11,9 +11,10 @@ * digits. * @author [Ashish Daulatabad](https://github.com/AshishYUO) */ -#include // for assert -#include // for uint32_t, uint8_t -#include // for basic_string, allocator, string, char_traits, ope... +#include /// for `std::array` +#include /// for `assert` operations +#include /// for integral typedefs +#include /// for IO operations /** * @namespace ciphers diff --git a/ciphers/elliptic_curve_key_exchange.cpp b/ciphers/elliptic_curve_key_exchange.cpp index 7955466ae5b..0a9ce3cd0e3 100644 --- a/ciphers/elliptic_curve_key_exchange.cpp +++ b/ciphers/elliptic_curve_key_exchange.cpp @@ -21,12 +21,10 @@ * alicePubKey * bobPrivKey = bobPubKey * alicePrivKey = secret * @author [Ashish Daulatabad](https://github.com/AshishYUO) */ -#include // for assert -#include // for basic_ostream, operator<<, char_traits, cout -#include // for basic_string +#include /// for assert +#include /// for IO operations -#include "uint256_t.hpp" // for uint256_t, operator<< -#include "uint128_t.hpp" // for uint128_t +#include "uint256_t.hpp" /// for 256-bit integer /** * @namespace ciphers diff --git a/ciphers/morse_code.cpp b/ciphers/morse_code.cpp index f446a8ec5e3..f8ff51c5c1d 100644 --- a/ciphers/morse_code.cpp +++ b/ciphers/morse_code.cpp @@ -11,11 +11,10 @@ * and dashes or dits and dahs. Morse code is named after Samuel Morse, an * inventor of the telegraph. */ -#include // for assert -#include // for basic_ostream, operator<<, endl, cout, cerr -#include // for basic_string, operator==, char_traits, string -#include // for vector -#include // for exit, size_t +#include +#include +#include +#include /** \namespace ciphers * \brief Algorithms for encryption and decryption diff --git a/ciphers/vigenere_cipher.cpp b/ciphers/vigenere_cipher.cpp index 17e1e3c552b..4efd56c0013 100644 --- a/ciphers/vigenere_cipher.cpp +++ b/ciphers/vigenere_cipher.cpp @@ -1,126 +1,109 @@ /** * @file vigenere_cipher.cpp - * @brief Implementation of [Vigenère - * cipher](https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher) algorithm. + * @brief Implementation of [Vigenère cipher](https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher) algorithm. * * @details - * The Vigenère cipher is a method of encrypting alphabetic text by using a - * series of interwoven vigenere ciphers, based on the letters of a keyword. It - * employs a form of polyalphabetic substitution. + * The Vigenère cipher is a method of encrypting alphabetic text by using a series of interwoven vigenere + * ciphers, based on the letters of a keyword. It employs a form of polyalphabetic substitution. * * ### Algorithm - * The encryption can also be represented using modular arithmetic by first - * transforming the letters into numbers, according to the scheme, A → 0, B → 1, - * ..., Z → 25. Encryption of \f$i^{th}\f$ character in Message M by key K can - * be described mathematically as, - * + * The encryption can also be represented using modular arithmetic by first transforming + * the letters into numbers, according to the scheme, A → 0, B → 1, ..., Z → 25. + * Encryption of \f$i^{th}\f$ character in Message M by key K can be described mathematically as, + * * \f[ E_{K}(M_{i}) = (M_{i} + K_{i})\;\mbox{mod}\; 26\f] - * - * while decryption of \f$i^{th}\f$ character in Cipher C by key K can be - * described mathematically as, + * + * while decryption of \f$i^{th}\f$ character in Cipher C by key K can be described mathematically as, * * \f[ D_{k}(C_{i}) = (C_{i} - K_{i} + 26)\;\mbox{mod}\; 26\f] - * - * Where \f$K_{i}\f$ denotes corresponding character in key. If \f$|key| < - * |text|\f$ than same key is repeated untill their lengths are equal. - * + * + * Where \f$K_{i}\f$ denotes corresponding character in key. If \f$|key| < |text|\f$ than + * same key is repeated untill their lengths are equal. + * * For Example, * If M = "ATTACKATDAWN" and K = "LEMON" than K becomes "LEMONLEMONLE". - * - * \note Rather than creating new key of equal length this program does this by - * using modular index for key (i.e. \f$(j + 1) \;\mbox{mod}\; |\mbox{key}|\f$) - * - * \note This program implements Vigenère cipher for only uppercase English - * alphabet characters (i.e. A-Z). - * + * + * \note Rather than creating new key of equal length this program does this by using modular index for key + * (i.e. \f$(j + 1) \;\mbox{mod}\; |\mbox{key}|\f$) + * + * \note This program implements Vigenère cipher for only uppercase English alphabet characters (i.e. A-Z). + * * @author [Deep Raval](https://github.com/imdeep2905) */ -#include // for assert -#include // for size_t -#include // for basic_ostream, operator<<, cout, endl -#include // for basic_string, char_traits, string, operator<< +#include +#include +#include /** \namespace ciphers * \brief Algorithms for encryption and decryption */ namespace ciphers { -/** \namespace vigenere - * \brief Functions for [vigenère - * cipher](https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher) algorithm. - */ -namespace vigenere { -namespace { -/** - * This function finds character for given value (i.e.A-Z) - * @param x value for which we want character - * @return corresponding character for perticular value - */ -inline char get_char(const int x) { - // By adding 65 we are scaling 0-25 to 65-90. - // Which are in fact ASCII values of A-Z. - return char(x + 65); -} -/** - * This function finds value for given character (i.e.0-25) - * @param c character for which we want value - * @return returns corresponding value for perticular character - */ -inline int get_value(const char c) { - // A-Z have ASCII values in range 65-90. - // Hence subtracting 65 will scale them to 0-25. - return int(c - 65); -} -} // Unnamed namespace -/** - * Encrypt given text using vigenere cipher. - * @param text text to be encrypted - * @param key to be used for encryption - * @return new encrypted text - */ -std::string encrypt(const std::string &text, const std::string &key) { - std::string encrypted_text = ""; // Empty string to store encrypted text - // Going through each character of text and key - // Note that key is visited in circular way hence j = (j + 1) % |key| - for (size_t i = 0, j = 0; i < text.length(); - i++, j = (j + 1) % key.length()) { - int place_value_text = - get_value(text[i]); // Getting value of character in text - int place_value_key = - get_value(key[j]); // Getting value of character in key - place_value_text = - (place_value_text + place_value_key) % 26; // Applying encryption - char encrypted_char = get_char( - place_value_text); // Getting new character from encrypted value - encrypted_text += encrypted_char; // Appending encrypted character - } - return encrypted_text; // Returning encrypted text -} -/** - * Decrypt given text using vigenere cipher. - * @param text text to be decrypted - * @param key key to be used for decryption - * @return new decrypted text - */ -std::string decrypt(const std::string &text, const std::string &key) { - // Going through each character of text and key - // Note that key is visited in circular way hence j = (j + 1) % |key| - std::string decrypted_text = ""; // Empty string to store decrypted text - for (size_t i = 0, j = 0; i < text.length(); - i++, j = (j + 1) % key.length()) { - int place_value_text = - get_value(text[i]); // Getting value of character in text - int place_value_key = - get_value(key[j]); // Getting value of character in key - place_value_text = (place_value_text - place_value_key + 26) % - 26; // Applying decryption - char decrypted_char = get_char( - place_value_text); // Getting new character from decrypted value - decrypted_text += decrypted_char; // Appending decrypted character - } - return decrypted_text; // Returning decrypted text -} -} // namespace vigenere -} // namespace ciphers + /** \namespace vigenere + * \brief Functions for [vigenère cipher](https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher) algorithm. + */ + namespace vigenere { + namespace { + /** + * This function finds character for given value (i.e.A-Z) + * @param x value for which we want character + * @return corresponding character for perticular value + */ + inline char get_char(const int x) { + // By adding 65 we are scaling 0-25 to 65-90. + // Which are in fact ASCII values of A-Z. + return char(x + 65); + } + /** + * This function finds value for given character (i.e.0-25) + * @param c character for which we want value + * @return returns corresponding value for perticular character + */ + inline int get_value(const char c) { + // A-Z have ASCII values in range 65-90. + // Hence subtracting 65 will scale them to 0-25. + return int(c - 65); + } + } // Unnamed namespace + /** + * Encrypt given text using vigenere cipher. + * @param text text to be encrypted + * @param key to be used for encryption + * @return new encrypted text + */ + std::string encrypt (const std::string &text, const std::string &key) { + std::string encrypted_text = ""; // Empty string to store encrypted text + // Going through each character of text and key + // Note that key is visited in circular way hence j = (j + 1) % |key| + for(size_t i = 0, j = 0; i < text.length(); i++, j = (j + 1) % key.length()) { + int place_value_text = get_value(text[i]); // Getting value of character in text + int place_value_key = get_value(key[j]); // Getting value of character in key + place_value_text = (place_value_text + place_value_key) % 26; // Applying encryption + char encrypted_char = get_char(place_value_text); // Getting new character from encrypted value + encrypted_text += encrypted_char; // Appending encrypted character + } + return encrypted_text; // Returning encrypted text + } + /** + * Decrypt given text using vigenere cipher. + * @param text text to be decrypted + * @param key key to be used for decryption + * @return new decrypted text + */ + std::string decrypt (const std::string &text, const std::string &key) { + // Going through each character of text and key + // Note that key is visited in circular way hence j = (j + 1) % |key| + std::string decrypted_text = ""; // Empty string to store decrypted text + for(size_t i = 0, j = 0; i < text.length(); i++, j = (j + 1) % key.length()) { + int place_value_text = get_value(text[i]); // Getting value of character in text + int place_value_key = get_value(key[j]); // Getting value of character in key + place_value_text = (place_value_text - place_value_key + 26) % 26; // Applying decryption + char decrypted_char = get_char(place_value_text); // Getting new character from decrypted value + decrypted_text += decrypted_char; // Appending decrypted character + } + return decrypted_text; // Returning decrypted text + } + } // namespace vigenere +} // namespace ciphers /** * Function to test above algorithm @@ -133,7 +116,7 @@ void test() { assert(text1 == decrypted1); std::cout << "Original text : " << text1; std::cout << " , Encrypted text (with key = TESLA) : " << encrypted1; - std::cout << " , Decrypted text : " << decrypted1 << std::endl; + std::cout << " , Decrypted text : "<< decrypted1 << std::endl; // Test 2 std::string text2 = "GOOGLEIT"; std::string encrypted2 = ciphers::vigenere::encrypt(text2, "REALLY"); @@ -141,7 +124,7 @@ void test() { assert(text2 == decrypted2); std::cout << "Original text : " << text2; std::cout << " , Encrypted text (with key = REALLY) : " << encrypted2; - std::cout << " , Decrypted text : " << decrypted2 << std::endl; + std::cout << " , Decrypted text : "<< decrypted2 << std::endl; } /** Driver Code */ From 7920c501339ce0de3f0a99bd2a4467c0bf397f74 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:47:22 +0530 Subject: [PATCH 068/131] Revert "chore: use iwyu on bit_manip/**.cpp" This reverts commit 7edcb6e458fecd7ed05a7d4e87418680f443ec23. --- bit_manipulation/find_non_repeating_number.cpp | 7 +++---- bit_manipulation/hamming_distance.cpp | 8 +++----- .../travelling_salesman_using_bit_manipulation.cpp | 11 ++++++----- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/bit_manipulation/find_non_repeating_number.cpp b/bit_manipulation/find_non_repeating_number.cpp index e5ea483d2d9..cc63d29cc70 100644 --- a/bit_manipulation/find_non_repeating_number.cpp +++ b/bit_manipulation/find_non_repeating_number.cpp @@ -15,10 +15,9 @@ * @author [Ravidev Pandey](https://github.com/literalEval) */ -#include // for int64_t -#include // for assert -#include // for char_traits, basic_ostream, operator<<, cout, endl -#include // for vector +#include /// for assert +#include /// for IO operations +#include /// storing the numbers /** * @namespace bit_manipulation diff --git a/bit_manipulation/hamming_distance.cpp b/bit_manipulation/hamming_distance.cpp index 935ac5a58d6..1f6685ffca8 100644 --- a/bit_manipulation/hamming_distance.cpp +++ b/bit_manipulation/hamming_distance.cpp @@ -12,11 +12,9 @@ * @author [Ravishankar Joshi](https://github.com/ravibitsgoa) */ -#include // for assert -#include // for size_t -#include // for uint64_t -#include // for char_traits, basic_ostream, operator<<, cout, endl -#include // for basic_string, string +#include /// for assert +#include /// for integral typedefs +#include /// for io operations /** * @namespace bit_manipulation diff --git a/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp b/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp index 7b234dbccf6..5eac30bc776 100644 --- a/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp +++ b/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp @@ -20,11 +20,12 @@ * Space complexity: O(n) * @author [Utkarsh Yadav](https://github.com/Rytnix) */ -#include // for min -#include // for assert -#include // for uint64_t, uint32_t -#include // for operator<<, char_traits, basic_ostream, cout -#include // for vector +#include /// for std::min +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations +#include /// for limits of integral types +#include /// for std::vector /** * @namespace bit_manipulation From bcae88d7202be771c4e2d5b41f97e113f801dbc0 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:47:26 +0530 Subject: [PATCH 069/131] Revert "chore: use iwyu on backtracking/**.cpp" This reverts commit f0a30d7cdbc0b06330b02d9ff0387feb3d9b380b. --- backtracking/generate_parentheses.cpp | 7 +++---- backtracking/graph_coloring.cpp | 6 +++--- backtracking/knight_tour.cpp | 5 ++--- backtracking/minimax.cpp | 9 ++++----- backtracking/n_queens.cpp | 5 ++--- backtracking/n_queens_all_solution_optimised.cpp | 5 ++--- backtracking/nqueen_print_all_solutions.cpp | 6 ++---- backtracking/rat_maze.cpp | 7 +++---- backtracking/sudoku_solver.cpp | 6 ++---- backtracking/wildcard_matching.cpp | 9 ++++----- 10 files changed, 27 insertions(+), 38 deletions(-) diff --git a/backtracking/generate_parentheses.cpp b/backtracking/generate_parentheses.cpp index 83cce0d89de..8a9e3b3301d 100644 --- a/backtracking/generate_parentheses.cpp +++ b/backtracking/generate_parentheses.cpp @@ -11,10 +11,9 @@ */ -#include // for assert -#include // for char_traits, operator<<, basic_ostream, cout -#include // for allocator, vector, operator== -#include // for basic_string, string, operator+, operator== +#include /// for assert +#include /// for I/O operation +#include /// for vector container /** * @brief Backtracking algorithms diff --git a/backtracking/graph_coloring.cpp b/backtracking/graph_coloring.cpp index b6b4e06a592..8fb328a1a80 100644 --- a/backtracking/graph_coloring.cpp +++ b/backtracking/graph_coloring.cpp @@ -18,9 +18,9 @@ * @author [David Leal](https://github.com/Panquesito7) */ -#include // for array -#include // for size_t -#include // for operator<<, cout, basic_ostream, basic_ostream::... +#include /// for std::array +#include /// for IO operations +#include /// for std::vector /** * @namespace backtracking diff --git a/backtracking/knight_tour.cpp b/backtracking/knight_tour.cpp index b97d876dfc6..0223462db7b 100644 --- a/backtracking/knight_tour.cpp +++ b/backtracking/knight_tour.cpp @@ -13,9 +13,8 @@ * @author [Nikhil Arora](https://github.com/nikhilarora068) * @author [David Leal](https://github.com/Panquesito7) */ -#include // for array -#include // for size_t -#include // for char_traits, operator<<, basic_ostream, cout +#include /// for std::array +#include /// for IO operations /** * @namespace backtracking diff --git a/backtracking/minimax.cpp b/backtracking/minimax.cpp index 99d8009d031..b27c85e1047 100644 --- a/backtracking/minimax.cpp +++ b/backtracking/minimax.cpp @@ -16,11 +16,10 @@ * @author [Gleison Batista](https://github.com/gleisonbs) * @author [David Leal](https://github.com/Panquesito7) */ -#include // for max, min -#include // for array -#include // for log2 -#include // for size_t -#include // for char_traits, basic_ostream, basic_ostream::oper... +#include /// for std::max, std::min +#include /// for std::array +#include /// for log2 +#include /// for IO operations /** * @namespace backtracking diff --git a/backtracking/n_queens.cpp b/backtracking/n_queens.cpp index 1f10f6e2f4d..f9742eb7a53 100644 --- a/backtracking/n_queens.cpp +++ b/backtracking/n_queens.cpp @@ -15,9 +15,8 @@ * @author [David Leal](https://github.com/Panquesito7) * */ -#include // for array -#include // for size_t -#include // for operator<<, basic_ostream, cout, basic_ostream::... +#include +#include /** * @namespace backtracking diff --git a/backtracking/n_queens_all_solution_optimised.cpp b/backtracking/n_queens_all_solution_optimised.cpp index b661c49c0a0..525d4c2db18 100644 --- a/backtracking/n_queens_all_solution_optimised.cpp +++ b/backtracking/n_queens_all_solution_optimised.cpp @@ -7,9 +7,8 @@ * @author [David Leal](https://github.com/Panquesito7) */ -#include // for array -#include // for size_t -#include // for cout, basic_ostream, endl, basic_ostream::operat... +#include +#include /** * @namespace backtracking diff --git a/backtracking/nqueen_print_all_solutions.cpp b/backtracking/nqueen_print_all_solutions.cpp index a0d41f009d6..8824cf0a828 100644 --- a/backtracking/nqueen_print_all_solutions.cpp +++ b/backtracking/nqueen_print_all_solutions.cpp @@ -7,10 +7,8 @@ * @author [David Leal](https://github.com/Panquesito7) * */ -#include // for array -#include // for size_t -#include // for cout, basic_ostream, endl, basic_ostream::operat... - +#include /// for std::array +#include /// for IO operations /** * @namespace backtracking diff --git a/backtracking/rat_maze.cpp b/backtracking/rat_maze.cpp index c18bc8f0dd9..60bc521c88f 100644 --- a/backtracking/rat_maze.cpp +++ b/backtracking/rat_maze.cpp @@ -16,10 +16,9 @@ * @author [David Leal](https://github.com/Panquesito7) */ -#include // for array -#include // for assert -#include // for size_t -#include // for cout, basic_ostream, basic_ostream::operator<< +#include /// for std::array +#include /// for assert +#include /// for IO operations /** * @namespace backtracking diff --git a/backtracking/sudoku_solver.cpp b/backtracking/sudoku_solver.cpp index bc359a91eb3..38ccfa0b4dc 100644 --- a/backtracking/sudoku_solver.cpp +++ b/backtracking/sudoku_solver.cpp @@ -15,10 +15,8 @@ * @author [DarthCoder3200](https://github.com/DarthCoder3200) * @author [David Leal](https://github.com/Panquesito7) */ -#include // for array -#include // for size_t -#include // for basic_ostream, char_traits, cout, operator<< - +#include /// for assert +#include /// for IO operations /** * @namespace backtracking diff --git a/backtracking/wildcard_matching.cpp b/backtracking/wildcard_matching.cpp index e1b83a6bbe6..b637f9f2d03 100644 --- a/backtracking/wildcard_matching.cpp +++ b/backtracking/wildcard_matching.cpp @@ -11,11 +11,10 @@ * @author [Swastika Gupta](https://github.com/Swastyy) */ -#include // for assert -#include // for uint32_t, int64_t -#include // for basic_ostream, operator<<, char_traits, cout, endl -#include // for vector -#include // for basic_string, string +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations +#include /// for std::vector /** * @namespace backtracking From f60bc8b25b4227e0faa7841bf54b5a00bbd10068 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:42:48 +0530 Subject: [PATCH 070/131] Update search/binary_search.cpp --- search/binary_search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search/binary_search.cpp b/search/binary_search.cpp index 20c8b1ab141..84fef6fb97d 100644 --- a/search/binary_search.cpp +++ b/search/binary_search.cpp @@ -36,7 +36,7 @@ #include /// for std::sort function #include /// for std::assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector /****************************************************************************** From 523d02e7eedf16788874bca2078687b5db0d2f1b Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:42:57 +0530 Subject: [PATCH 071/131] Update backtracking/subarray_sum.cpp --- backtracking/subarray_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backtracking/subarray_sum.cpp b/backtracking/subarray_sum.cpp index fde1fe98798..ba9834e87a6 100644 --- a/backtracking/subarray_sum.cpp +++ b/backtracking/subarray_sum.cpp @@ -14,7 +14,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for unordered_map #include /// for std::vector From 9c35a066eaf8ca2b311c9ea5fa3ccafa2de8369a Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:43:05 +0530 Subject: [PATCH 072/131] Update backtracking/subset_sum.cpp --- backtracking/subset_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backtracking/subset_sum.cpp b/backtracking/subset_sum.cpp index bcc8ae744bd..8551a66e0ca 100644 --- a/backtracking/subset_sum.cpp +++ b/backtracking/subset_sum.cpp @@ -10,7 +10,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector From 4e49a136f3b91ddd387f2d84bd8738811cdaefd0 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:43:16 +0530 Subject: [PATCH 073/131] Update backtracking/wildcard_matching.cpp --- backtracking/wildcard_matching.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backtracking/wildcard_matching.cpp b/backtracking/wildcard_matching.cpp index b637f9f2d03..cd0bd72ad8c 100644 --- a/backtracking/wildcard_matching.cpp +++ b/backtracking/wildcard_matching.cpp @@ -12,7 +12,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector From 9a1c789b8b6af306ee02a85e5166194a92cd2baa Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:43:24 +0530 Subject: [PATCH 074/131] Update bit_manipulation/count_bits_flip.cpp --- bit_manipulation/count_bits_flip.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bit_manipulation/count_bits_flip.cpp b/bit_manipulation/count_bits_flip.cpp index 61b2cd5c576..2ab2ce31c15 100644 --- a/bit_manipulation/count_bits_flip.cpp +++ b/bit_manipulation/count_bits_flip.cpp @@ -20,7 +20,7 @@ * @author [Yash Raj Singh](https://github.com/yashrajyash) */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations /** * @namespace bit_manipulation From 8a7eec582fba763a4665667378b589667900f87e Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:43:31 +0530 Subject: [PATCH 075/131] Update bit_manipulation/count_of_set_bits.cpp --- bit_manipulation/count_of_set_bits.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bit_manipulation/count_of_set_bits.cpp b/bit_manipulation/count_of_set_bits.cpp index 5e34c4df053..dd29fd8bf19 100644 --- a/bit_manipulation/count_of_set_bits.cpp +++ b/bit_manipulation/count_of_set_bits.cpp @@ -16,7 +16,7 @@ * @author [Prashant Thakur](https://github.com/prashant-th18) */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations /** * @namespace bit_manipulation From 503f3aec17b01d279181d0851f22577d8308bedb Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:43:40 +0530 Subject: [PATCH 076/131] Update bit_manipulation/count_of_trailing_ciphers_in_factorial_n.cpp --- bit_manipulation/count_of_trailing_ciphers_in_factorial_n.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bit_manipulation/count_of_trailing_ciphers_in_factorial_n.cpp b/bit_manipulation/count_of_trailing_ciphers_in_factorial_n.cpp index 493094de552..c1c57d0a617 100644 --- a/bit_manipulation/count_of_trailing_ciphers_in_factorial_n.cpp +++ b/bit_manipulation/count_of_trailing_ciphers_in_factorial_n.cpp @@ -18,7 +18,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations /** From c6e8264b1c190ef65a7076f63cd9f4ec05753a55 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:43:48 +0530 Subject: [PATCH 077/131] Update bit_manipulation/hamming_distance.cpp --- bit_manipulation/hamming_distance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bit_manipulation/hamming_distance.cpp b/bit_manipulation/hamming_distance.cpp index 1f6685ffca8..ca4e9fc5b36 100644 --- a/bit_manipulation/hamming_distance.cpp +++ b/bit_manipulation/hamming_distance.cpp @@ -13,7 +13,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for io operations /** From b31776d907ba3f6fe1a182ae191858161511a78a Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:43:58 +0530 Subject: [PATCH 078/131] Update bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp --- .../next_higher_number_with_same_number_of_set_bits.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp b/bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp index 06f91c61943..f6d840f91bd 100644 --- a/bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp +++ b/bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp @@ -16,7 +16,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations /** From 20073f3eed012016a5458b9e219f4b48efcb1843 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:44:24 +0530 Subject: [PATCH 079/131] Update bit_manipulation/power_of_2.cpp --- bit_manipulation/power_of_2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bit_manipulation/power_of_2.cpp b/bit_manipulation/power_of_2.cpp index 14092e8952c..f35361c8a9d 100644 --- a/bit_manipulation/power_of_2.cpp +++ b/bit_manipulation/power_of_2.cpp @@ -16,7 +16,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations /** From f50900579c9139c66e27313d2dea63331986aeb4 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:44:42 +0530 Subject: [PATCH 080/131] Update others/lru_cache.cpp --- others/lru_cache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/others/lru_cache.cpp b/others/lru_cache.cpp index 5a07c3e4fa9..29f8bd0ed16 100644 --- a/others/lru_cache.cpp +++ b/others/lru_cache.cpp @@ -46,7 +46,7 @@ * */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO Operations #include /// for std::list #include /// for std::unordered_map From 12f0d525ab0ce1012fb8f4ae5311bdb2a4c172ce Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:45:07 +0530 Subject: [PATCH 081/131] Update bit_manipulation/set_kth_bit.cpp --- bit_manipulation/set_kth_bit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bit_manipulation/set_kth_bit.cpp b/bit_manipulation/set_kth_bit.cpp index 04e69c6a04b..d3d50e6cb28 100644 --- a/bit_manipulation/set_kth_bit.cpp +++ b/bit_manipulation/set_kth_bit.cpp @@ -19,7 +19,7 @@ */ #include /// for assert -#include /// for integral typdefs +#include #include /// for IO operations /** From 49f0be3d96420df2ab3d232ee42f5eed0b928835 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:45:15 +0530 Subject: [PATCH 082/131] Update bit_manipulation/travelling_salesman_using_bit_manipulation.cpp --- bit_manipulation/travelling_salesman_using_bit_manipulation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp b/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp index 5eac30bc776..9858b8107a3 100644 --- a/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp +++ b/bit_manipulation/travelling_salesman_using_bit_manipulation.cpp @@ -22,7 +22,7 @@ */ #include /// for std::min #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for limits of integral types #include /// for std::vector From deaecb98493284f3e73ac2632888170f90ef4620 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:45:26 +0530 Subject: [PATCH 083/131] Update ciphers/base64_encoding.cpp --- ciphers/base64_encoding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/base64_encoding.cpp b/ciphers/base64_encoding.cpp index 52bce90ff9a..81459408a8e 100644 --- a/ciphers/base64_encoding.cpp +++ b/ciphers/base64_encoding.cpp @@ -13,7 +13,7 @@ */ #include /// for `std::array` #include /// for `assert` operations -#include /// for integral typedefs +#include #include /// for IO operations /** From f94271c128a8131061bc67fd9d353f40475c45ca Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:45:36 +0530 Subject: [PATCH 084/131] Update ciphers/hill_cipher.cpp --- ciphers/hill_cipher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/hill_cipher.cpp b/ciphers/hill_cipher.cpp index a57935bf610..d77a51c22b3 100644 --- a/ciphers/hill_cipher.cpp +++ b/ciphers/hill_cipher.cpp @@ -35,7 +35,7 @@ #include #include -#include /// for integral typedefs +#include #include #include #include From 054e37cf91d084ca4cf4b6a3e8e2449adf96a6d4 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:45:48 +0530 Subject: [PATCH 085/131] Update ciphers/uint128_t.hpp --- ciphers/uint128_t.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/uint128_t.hpp b/ciphers/uint128_t.hpp index 141864c8d5f..7abffb08a61 100644 --- a/ciphers/uint128_t.hpp +++ b/ciphers/uint128_t.hpp @@ -8,7 +8,7 @@ */ #include /// for `std::reverse` and other operations -#include /// for integral typedefs +#include #include /// for `std::cout` overload #include /// for `std::string` #include /// for `std::pair` library From b34dbff1eea85270f802481fca2395182d30740b Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:45:59 +0530 Subject: [PATCH 086/131] Update cpu_scheduling_algorithms/fcfs_scheduling.cpp --- cpu_scheduling_algorithms/fcfs_scheduling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu_scheduling_algorithms/fcfs_scheduling.cpp b/cpu_scheduling_algorithms/fcfs_scheduling.cpp index 6eab989e4f2..5c5e2fa3c58 100644 --- a/cpu_scheduling_algorithms/fcfs_scheduling.cpp +++ b/cpu_scheduling_algorithms/fcfs_scheduling.cpp @@ -11,7 +11,7 @@ #include /// for sorting #include /// for assert -#include /// for integral typedefs +#include #include /// random number generation #include /// for time #include /// for formatting the output From b20f01c1dc502fcf4e511e6b45386e4791b46416 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:46:10 +0530 Subject: [PATCH 087/131] Update data_structures/dsu_path_compression.cpp --- data_structures/dsu_path_compression.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/dsu_path_compression.cpp b/data_structures/dsu_path_compression.cpp index 9dff7b40bb0..c08040570dd 100644 --- a/data_structures/dsu_path_compression.cpp +++ b/data_structures/dsu_path_compression.cpp @@ -19,7 +19,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector From 465eb7b13b957334c550ffc87fe5ba235f077972 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:46:20 +0530 Subject: [PATCH 088/131] Update data_structures/dsu_union_rank.cpp --- data_structures/dsu_union_rank.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/dsu_union_rank.cpp b/data_structures/dsu_union_rank.cpp index 4ca53bb76f6..16e1d3275bf 100644 --- a/data_structures/dsu_union_rank.cpp +++ b/data_structures/dsu_union_rank.cpp @@ -20,7 +20,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector From 04c9f15da8655ae6278e6c86c3a14c93e4af2219 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:46:35 +0530 Subject: [PATCH 089/131] Update data_structures/list_array.cpp --- data_structures/list_array.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/list_array.cpp b/data_structures/list_array.cpp index 8995b6ce2e1..0c8099f5788 100644 --- a/data_structures/list_array.cpp +++ b/data_structures/list_array.cpp @@ -16,7 +16,7 @@ #include /// for std::array #include /// for assert -#include /// for integral typedefs +#include #include /// for io operations /** From bbbd9abdedbb18e6d5ff449f1eac90ca68bbff43 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:46:49 +0530 Subject: [PATCH 090/131] Update data_structures/queue_using_array.cpp --- data_structures/queue_using_array.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/queue_using_array.cpp b/data_structures/queue_using_array.cpp index cbd84a62397..c2437258328 100644 --- a/data_structures/queue_using_array.cpp +++ b/data_structures/queue_using_array.cpp @@ -18,7 +18,7 @@ * @author [Farbod Ahmadian](https://github.com/farbodahm) */ #include /// for std::array -#include /// for integral typedefs +#include #include /// for io operations constexpr uint16_t max_size{10}; ///< Maximum size of the queue From 227e9d29a7fb3103ad1a030f033ba4190cc4e50a Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:47:00 +0530 Subject: [PATCH 091/131] Update data_structures/sparse_table.cpp --- data_structures/sparse_table.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/sparse_table.cpp b/data_structures/sparse_table.cpp index 507dd39449d..7b3d74b90c3 100644 --- a/data_structures/sparse_table.cpp +++ b/data_structures/sparse_table.cpp @@ -24,7 +24,7 @@ #include /// for std::array #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations /** From 572bb35b277c699fec3e53d8a3b020c59f8dccde Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:47:11 +0530 Subject: [PATCH 092/131] Update data_structures/stack_using_queue.cpp --- data_structures/stack_using_queue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/stack_using_queue.cpp b/data_structures/stack_using_queue.cpp index 7867d55caa0..c5fc55a3e61 100644 --- a/data_structures/stack_using_queue.cpp +++ b/data_structures/stack_using_queue.cpp @@ -9,7 +9,7 @@ * @author [tushar2407](https://github.com/tushar2407) */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for queue data structure From 5e53d924eda652a1789332710bb5cee7fa61b2da Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:47:22 +0530 Subject: [PATCH 093/131] Update data_structures/treap.cpp --- data_structures/treap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/treap.cpp b/data_structures/treap.cpp index 5be3b241643..592f49e7dfb 100644 --- a/data_structures/treap.cpp +++ b/data_structures/treap.cpp @@ -19,7 +19,7 @@ #include /// For array #include /// For assert -#include /// for integral typedefs +#include #include /// For IO operations /** From 99839c31721db596ac6e088280e22efb475abad8 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:47:43 +0530 Subject: [PATCH 094/131] Update geometry/graham_scan_functions.hpp --- geometry/graham_scan_functions.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geometry/graham_scan_functions.hpp b/geometry/graham_scan_functions.hpp index 58002db266d..58ac066e498 100644 --- a/geometry/graham_scan_functions.hpp +++ b/geometry/graham_scan_functions.hpp @@ -39,7 +39,7 @@ * *******************************************************************************/ #include /// for std::swap -#include /// for integral typedefs +#include #include /// for mathematics and datatype conversion #include /// for IO operations #include /// for std::stack From 21446efd32239b32fec2054a717ea1e088a19ad0 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:47:58 +0530 Subject: [PATCH 095/131] Update graph/bidirectional_dijkstra.cpp --- graph/bidirectional_dijkstra.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graph/bidirectional_dijkstra.cpp b/graph/bidirectional_dijkstra.cpp index 5f6d369287c..b4f58d22621 100644 --- a/graph/bidirectional_dijkstra.cpp +++ b/graph/bidirectional_dijkstra.cpp @@ -14,7 +14,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for io operations #include /// for variable INF #include /// for the priority_queue of distances From 7ccca6083db7bc4e2f8e0038acfeb92a7053c088 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:48:09 +0530 Subject: [PATCH 096/131] Update graph/connected_components_with_dsu.cpp --- graph/connected_components_with_dsu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graph/connected_components_with_dsu.cpp b/graph/connected_components_with_dsu.cpp index 72c4f34fe2b..59dc2fda3cd 100644 --- a/graph/connected_components_with_dsu.cpp +++ b/graph/connected_components_with_dsu.cpp @@ -17,7 +17,7 @@ * @author Unknown author * @author [Sagar Pandya](https://github.com/sagarpandyansit) */ -#include /// for integer typedefs +#include #include /// for IO operations #include /// for std::set #include /// for std::vector From d6ea50281d66284472416535ecd9a7c1002fdb15 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:48:21 +0530 Subject: [PATCH 097/131] Update graph/cycle_check_directed_graph.cpp --- graph/cycle_check_directed_graph.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graph/cycle_check_directed_graph.cpp b/graph/cycle_check_directed_graph.cpp index fbe6063ca96..15b92c4d6d2 100644 --- a/graph/cycle_check_directed_graph.cpp +++ b/graph/cycle_check_directed_graph.cpp @@ -7,7 +7,7 @@ * */ -#include /// for integral typedefs +#include #include // for std::cout #include // for std::map #include // for std::queue From 016a2d8b23dff928fd73c48010256aeb4bd1b5c8 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:50:23 +0530 Subject: [PATCH 098/131] Update graph/is_graph_bipartite2.cpp --- graph/is_graph_bipartite2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graph/is_graph_bipartite2.cpp b/graph/is_graph_bipartite2.cpp index d55f2c84b53..0711dfb9296 100644 --- a/graph/is_graph_bipartite2.cpp +++ b/graph/is_graph_bipartite2.cpp @@ -15,7 +15,7 @@ * @author [tushar2407](https://github.com/tushar2407) */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for queue data structure #include /// for vector data structure From 929af50a2743c2f983be24191747813cef1860d9 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:50:36 +0530 Subject: [PATCH 099/131] Update graph/travelling_salesman_problem.cpp --- graph/travelling_salesman_problem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graph/travelling_salesman_problem.cpp b/graph/travelling_salesman_problem.cpp index 8b46080093f..1b329d5cb32 100644 --- a/graph/travelling_salesman_problem.cpp +++ b/graph/travelling_salesman_problem.cpp @@ -19,7 +19,7 @@ #include /// for std::min #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for limits of integral types #include /// for std::vector From 5d6fa2b641124657192ecb596c3412f18e052592 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:50:47 +0530 Subject: [PATCH 100/131] Update hashing/md5.cpp --- hashing/md5.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashing/md5.cpp b/hashing/md5.cpp index 2a0f289f3c4..52bc898f7d4 100644 --- a/hashing/md5.cpp +++ b/hashing/md5.cpp @@ -41,7 +41,7 @@ #include /// Used for std::copy #include /// Used for std::array #include /// Used for assert -#include /// for integral typedefs +#include #include /// Used for std::memcopy #include /// Used for IO operations #include /// Used for strings From ac91c019454a8cdbd343a988c3531672d155e6df Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:50:58 +0530 Subject: [PATCH 101/131] Update hashing/sha1.cpp --- hashing/sha1.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashing/sha1.cpp b/hashing/sha1.cpp index 5b55e58c6ba..2d551b99316 100644 --- a/hashing/sha1.cpp +++ b/hashing/sha1.cpp @@ -32,7 +32,7 @@ #include /// For std::copy #include /// For std::array #include /// For assert -#include /// for integral typedefs +#include #include /// For std::memcopy #include /// For IO operations #include /// For strings From 1abafa4fa9256efcb0bb9b98a22f2670d500890e Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:51:14 +0530 Subject: [PATCH 102/131] Update math/n_choose_r.cpp --- math/n_choose_r.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/n_choose_r.cpp b/math/n_choose_r.cpp index d2aabc28a55..5e151f39a84 100644 --- a/math/n_choose_r.cpp +++ b/math/n_choose_r.cpp @@ -11,7 +11,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for io operations /** * @namespace math From 10373fe08617d7dc609a2326e337a2acf96fdc7f Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:52:13 +0530 Subject: [PATCH 103/131] Update strings/z_function.cpp --- strings/z_function.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index 25a5755a7f7..d32f19b9f4a 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -11,7 +11,7 @@ * @author [Ritika Gupta](https://github.com/RitikaGupta8734) */ -#include /// for integral typedefs +#include #include /// for IO operations #ifdef _MSC_VER #include /// for string (use this for MS Visual C++) From ca6577d8356b0a9761eeb1471ce1203a19136e14 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:52:26 +0530 Subject: [PATCH 104/131] Update strings/manacher_algorithm.cpp --- strings/manacher_algorithm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/manacher_algorithm.cpp b/strings/manacher_algorithm.cpp index 1c1581a3374..e544d818d8c 100644 --- a/strings/manacher_algorithm.cpp +++ b/strings/manacher_algorithm.cpp @@ -11,7 +11,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector STL #ifdef _MSC_VER From 6c2158ee2a8ec5ad11eb8c3d8b80e10b4b72ecad Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:52:39 +0530 Subject: [PATCH 105/131] Update sorting/wiggle_sort.cpp --- sorting/wiggle_sort.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/wiggle_sort.cpp b/sorting/wiggle_sort.cpp index fe5009bb428..45ba788a86e 100644 --- a/sorting/wiggle_sort.cpp +++ b/sorting/wiggle_sort.cpp @@ -19,7 +19,7 @@ #include #include -#include /// for integral typedefs +#include #include #include /// for io operations #include From 4b6c5ff6d203d3d8e95c747215de983c209aaa31 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:52:52 +0530 Subject: [PATCH 106/131] Update sorting/selection_sort_recursive.cpp --- sorting/selection_sort_recursive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/selection_sort_recursive.cpp b/sorting/selection_sort_recursive.cpp index 765b9709891..2ef6219b8dc 100644 --- a/sorting/selection_sort_recursive.cpp +++ b/sorting/selection_sort_recursive.cpp @@ -29,7 +29,7 @@ #include /// for std::is_sorted #include /// for assert -#include /// for integral typedefs +#include #include /// for std::swap and io operations #include /// for std::vector From 15f8b88b91f35462d7d530c6cc2db01df288e586 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:53:06 +0530 Subject: [PATCH 107/131] Update sorting/selection_sort_iterative.cpp --- sorting/selection_sort_iterative.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/selection_sort_iterative.cpp b/sorting/selection_sort_iterative.cpp index c25dac9814f..db293b88d03 100644 --- a/sorting/selection_sort_iterative.cpp +++ b/sorting/selection_sort_iterative.cpp @@ -29,7 +29,7 @@ *******************************************************************************/ #include /// for std::is_sorted #include /// for std::assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector From 70393b74364e1b3e93c6a23beff745c40c2880ed Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:53:22 +0530 Subject: [PATCH 108/131] Update sorting/recursive_bubble_sort.cpp --- sorting/recursive_bubble_sort.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/recursive_bubble_sort.cpp b/sorting/recursive_bubble_sort.cpp index 5b860f83319..f73cc0aeac5 100644 --- a/sorting/recursive_bubble_sort.cpp +++ b/sorting/recursive_bubble_sort.cpp @@ -60,7 +60,7 @@ #include /// for std::is_sorted #include /// for std::array #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector From f526abe37250d6c787037b529f096d71aebfbf7c Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:53:35 +0530 Subject: [PATCH 109/131] Update sorting/radix_sort2.cpp --- sorting/radix_sort2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/radix_sort2.cpp b/sorting/radix_sort2.cpp index 84dd6911f83..d20e81bccae 100644 --- a/sorting/radix_sort2.cpp +++ b/sorting/radix_sort2.cpp @@ -26,7 +26,7 @@ #include /// for collection of functions #include /// for a macro called assert which can be used to verify assumptions -#include /// for integral typedefs +#include #include /// for io operations #include /// for std::vector From 929f1ee36f44081ace70021027745addd6e9e4d2 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:53:47 +0530 Subject: [PATCH 110/131] Update sorting/dnf_sort.cpp --- sorting/dnf_sort.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/dnf_sort.cpp b/sorting/dnf_sort.cpp index 3cdb1c34e36..4fe0129cc81 100644 --- a/sorting/dnf_sort.cpp +++ b/sorting/dnf_sort.cpp @@ -12,7 +12,7 @@ #include /// for std::is_sorted #include /// for assert -#include /// for integral typedefs +#include #include /// for std::swap and io operations #include /// for std::vector From 768534b253adbab6226a6e1816ac32332c198b79 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:54:10 +0530 Subject: [PATCH 111/131] Update sorting/cycle_sort.cpp --- sorting/cycle_sort.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/cycle_sort.cpp b/sorting/cycle_sort.cpp index 1371fac94ea..88364bf12a0 100644 --- a/sorting/cycle_sort.cpp +++ b/sorting/cycle_sort.cpp @@ -13,7 +13,7 @@ #include /// for std::is_sorted, std::swap #include /// for assert -#include /// for integral typedefs +#include #include /// for io operations #include /// for std::vector From 01e263510e0a5155ba3792336ded5fab6f0c2a54 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:54:23 +0530 Subject: [PATCH 112/131] Update search/sublist_search.cpp --- search/sublist_search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search/sublist_search.cpp b/search/sublist_search.cpp index 7b485f04184..bb63cac0fa5 100644 --- a/search/sublist_search.cpp +++ b/search/sublist_search.cpp @@ -26,7 +26,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector From c1949c18a356f4e2f3c537e3628f1852685e5a2f Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:54:39 +0530 Subject: [PATCH 113/131] Update search/saddleback_search.cpp --- search/saddleback_search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search/saddleback_search.cpp b/search/saddleback_search.cpp index 4f2a5606d2f..d75c65e3ea6 100644 --- a/search/saddleback_search.cpp +++ b/search/saddleback_search.cpp @@ -13,7 +13,7 @@ * @author [Hashir Niazi](https://github.com/HashirGJ8842) */ #include /// for assert -#include /// for integral typedefs +#include #include /// for io operations, and std::pair #include /// for std::vector From eb9043c8754f14013d18f011412430b80fb269ec Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:54:53 +0530 Subject: [PATCH 114/131] Update search/interpolation_search.cpp --- search/interpolation_search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search/interpolation_search.cpp b/search/interpolation_search.cpp index f2b0205ea68..234d90ff698 100644 --- a/search/interpolation_search.cpp +++ b/search/interpolation_search.cpp @@ -31,7 +31,7 @@ #include /// for std::sort function #include /// for std::assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector From e01b4934e857ababee12205a135cbb63fa5276ec Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:55:09 +0530 Subject: [PATCH 115/131] Update search/floyd_cycle_detection_algo.cpp --- search/floyd_cycle_detection_algo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search/floyd_cycle_detection_algo.cpp b/search/floyd_cycle_detection_algo.cpp index 4b4a34c31e4..58c994dccf3 100644 --- a/search/floyd_cycle_detection_algo.cpp +++ b/search/floyd_cycle_detection_algo.cpp @@ -12,7 +12,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector /** From f042a15f35f754eda5c88bd347e21d34cb5fae40 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:55:27 +0530 Subject: [PATCH 116/131] Update search/exponential_search.cpp --- search/exponential_search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search/exponential_search.cpp b/search/exponential_search.cpp index c8370580af3..019180e439a 100644 --- a/search/exponential_search.cpp +++ b/search/exponential_search.cpp @@ -15,7 +15,7 @@ #include #include #include -#include /// for integral typedefs +#include #ifdef _MSC_VER #include // use for MS Visual C++ #else From 10e2edbdb54f3ae8f0e6440b24990add20e5b575 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 05:56:13 +0530 Subject: [PATCH 117/131] Update search/exponential_search.cpp --- search/exponential_search.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/search/exponential_search.cpp b/search/exponential_search.cpp index 019180e439a..6443084dc25 100644 --- a/search/exponential_search.cpp +++ b/search/exponential_search.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #ifdef _MSC_VER #include // use for MS Visual C++ #else From 229bb39136177e1da48482bb93f5328d113aa63b Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 06:10:45 +0530 Subject: [PATCH 118/131] Update math/n_bonacci.cpp --- math/n_bonacci.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/n_bonacci.cpp b/math/n_bonacci.cpp index 601b2edf0d7..bb2e85d13e4 100644 --- a/math/n_bonacci.cpp +++ b/math/n_bonacci.cpp @@ -16,7 +16,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for std::cout #include /// for std::vector /** From 35b6bfcdc4b065ea08a7f8d77f3b76f2ee5641b8 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 06:10:52 +0530 Subject: [PATCH 119/131] Update math/aliquot_sum.cpp --- math/aliquot_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/aliquot_sum.cpp b/math/aliquot_sum.cpp index 837be6b2f00..0b8afdf8920 100644 --- a/math/aliquot_sum.cpp +++ b/math/aliquot_sum.cpp @@ -20,7 +20,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations /** From 78cb6ea7d5457687fd62ca3e52c09f7f5df94f08 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 06:11:05 +0530 Subject: [PATCH 120/131] Update math/check_factorial.cpp --- math/check_factorial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/check_factorial.cpp b/math/check_factorial.cpp index 05898fbcde8..0b63433ebe4 100644 --- a/math/check_factorial.cpp +++ b/math/check_factorial.cpp @@ -10,7 +10,7 @@ * @author [ewd00010](https://github.com/ewd00010) */ #include /// for assert -#include /// for integral typedefs +#include #include /// for cout /** From cb98ef5a6e1250849cf8dc70da3b67357dd96657 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 08:02:47 +0530 Subject: [PATCH 121/131] Update math/double_factorial.cpp --- math/double_factorial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/double_factorial.cpp b/math/double_factorial.cpp index 878f87ec446..5832ce440d6 100644 --- a/math/double_factorial.cpp +++ b/math/double_factorial.cpp @@ -10,7 +10,7 @@ */ #include -#include /// for integral typedefs +#include #include /** Compute double factorial using iterative method From cb6ac14205b29ad8b22fe1c41c024223b056c01b Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 08:03:00 +0530 Subject: [PATCH 122/131] Update math/eulers_totient_function.cpp --- math/eulers_totient_function.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/eulers_totient_function.cpp b/math/eulers_totient_function.cpp index da03a2531c6..768034327da 100644 --- a/math/eulers_totient_function.cpp +++ b/math/eulers_totient_function.cpp @@ -26,7 +26,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations /** From 16d4ed95c61e28d9713d0c3290ca96c09c245169 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 08:03:09 +0530 Subject: [PATCH 123/131] Update math/factorial.cpp --- math/factorial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/factorial.cpp b/math/factorial.cpp index a6b039da45b..aca1886c783 100644 --- a/math/factorial.cpp +++ b/math/factorial.cpp @@ -12,7 +12,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for I/O operations /** * @namespace From af35499e38de75a95a22ae968ea35e5e1967a165 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 08:03:18 +0530 Subject: [PATCH 124/131] Update math/fibonacci.cpp --- math/fibonacci.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/fibonacci.cpp b/math/fibonacci.cpp index 1cd50e7cef3..c471fc97770 100644 --- a/math/fibonacci.cpp +++ b/math/fibonacci.cpp @@ -9,7 +9,7 @@ * @see fibonacci_large.cpp, fibonacci_fast.cpp, string_fibonacci.cpp */ #include -#include /// for integral typedefs +#include #include /** * Recursively compute sequences From 0ddbef6500ec2358d4be11db7b6ee6850eadd0cd Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 08:03:27 +0530 Subject: [PATCH 125/131] Update math/fibonacci_matrix_exponentiation.cpp --- math/fibonacci_matrix_exponentiation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/fibonacci_matrix_exponentiation.cpp b/math/fibonacci_matrix_exponentiation.cpp index 347d3800c80..915cf62b580 100644 --- a/math/fibonacci_matrix_exponentiation.cpp +++ b/math/fibonacci_matrix_exponentiation.cpp @@ -13,7 +13,7 @@ */ #include -#include /// for integral typedefs +#include #include #include From 57722cc202ba8738a359fba5c4ac454d4ca463da Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 08:03:38 +0530 Subject: [PATCH 126/131] Update math/fibonacci_sum.cpp --- math/fibonacci_sum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/fibonacci_sum.cpp b/math/fibonacci_sum.cpp index 4c52951deca..9373e21cb87 100644 --- a/math/fibonacci_sum.cpp +++ b/math/fibonacci_sum.cpp @@ -13,7 +13,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for std::cin and std::cout #include /// for std::vector From a7c8741efbd5a047bb37f35f6dd1853ea5383621 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 08:03:45 +0530 Subject: [PATCH 127/131] Update math/finding_number_of_digits_in_a_number.cpp --- math/finding_number_of_digits_in_a_number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/finding_number_of_digits_in_a_number.cpp b/math/finding_number_of_digits_in_a_number.cpp index e94a6c21728..b0edb746d65 100644 --- a/math/finding_number_of_digits_in_a_number.cpp +++ b/math/finding_number_of_digits_in_a_number.cpp @@ -18,7 +18,7 @@ #include /// for assert #include /// for log calculation -#include /// for integral typedefs +#include #include /// for IO operations /** From db9ebd9a402f01ff90e89ff464189fa47f5c7ca6 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:25:16 +0530 Subject: [PATCH 128/131] chore: remove "/// for integral typedefs" --- math/integral_approximation.cpp | 2 +- math/inv_sqrt.cpp | 2 +- math/largest_power.cpp | 2 +- math/lcm_sum.cpp | 2 +- math/linear_recurrence_matrix.cpp | 2 +- math/magic_number.cpp | 2 +- math/modular_exponentiation.cpp | 2 +- math/modular_inverse_simple.cpp | 2 +- math/sieve_of_eratosthenes.cpp | 2 +- math/string_fibonacci.cpp | 2 +- math/sum_of_binomial_coefficient.cpp | 2 +- numerical_methods/brent_method_extrema.cpp | 2 +- numerical_methods/durand_kerner_roots.cpp | 2 +- numerical_methods/fast_fourier_transform.cpp | 2 +- numerical_methods/golden_search_extrema.cpp | 2 +- numerical_methods/inverse_fast_fourier_transform.cpp | 2 +- numerical_methods/newton_raphson_method.cpp | 2 +- numerical_methods/rungekutta.cpp | 2 +- others/easter.cpp | 2 +- others/kadanes3.cpp | 2 +- sorting/quick_sort.cpp | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/math/integral_approximation.cpp b/math/integral_approximation.cpp index 033742f633b..2d1d42f916d 100644 --- a/math/integral_approximation.cpp +++ b/math/integral_approximation.cpp @@ -22,7 +22,7 @@ */ #include /// for assert #include /// for mathematical functions -#include /// for integral typedefs +#include #include /// for passing in functions #include /// for IO operations diff --git a/math/inv_sqrt.cpp b/math/inv_sqrt.cpp index 1f625e1cf8a..96a13fc08a1 100644 --- a/math/inv_sqrt.cpp +++ b/math/inv_sqrt.cpp @@ -10,7 +10,7 @@ #include /// for assert #include /// for `std::sqrt` -#include /// for integral typedefs +#include #include /// for IO operations #include /// for numeric_limits /** diff --git a/math/largest_power.cpp b/math/largest_power.cpp index 22f6da7380d..bc1ba484754 100644 --- a/math/largest_power.cpp +++ b/math/largest_power.cpp @@ -12,7 +12,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for std::cin and std::cout /** * @namespace math diff --git a/math/lcm_sum.cpp b/math/lcm_sum.cpp index b8477ddf174..7e9fc49b569 100644 --- a/math/lcm_sum.cpp +++ b/math/lcm_sum.cpp @@ -13,7 +13,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for std::cin and std::cout #include /// for std::vector diff --git a/math/linear_recurrence_matrix.cpp b/math/linear_recurrence_matrix.cpp index d59ad6aa1c0..c54d1272bf7 100644 --- a/math/linear_recurrence_matrix.cpp +++ b/math/linear_recurrence_matrix.cpp @@ -18,7 +18,7 @@ * @author [Ashish Daulatabad](https://github.com/AshishYUO) */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector STL diff --git a/math/magic_number.cpp b/math/magic_number.cpp index 7ba3ab0bcd1..c07869e3dfe 100644 --- a/math/magic_number.cpp +++ b/math/magic_number.cpp @@ -17,7 +17,7 @@ * @author [Neha Hasija](https://github.com/neha-hasija17) */ #include /// for assert -#include /// for integral typedefs +#include #include /// for io operations /** diff --git a/math/modular_exponentiation.cpp b/math/modular_exponentiation.cpp index a022939330a..d4a9dd84d07 100644 --- a/math/modular_exponentiation.cpp +++ b/math/modular_exponentiation.cpp @@ -17,7 +17,7 @@ * @author [Shri2206](https://github.com/Shri2206) */ #include /// for assert -#include /// for integral typedefs +#include #include /// for io operations /** * @namespace math diff --git a/math/modular_inverse_simple.cpp b/math/modular_inverse_simple.cpp index b2c79fe9a9b..f8a36d4eae9 100644 --- a/math/modular_inverse_simple.cpp +++ b/math/modular_inverse_simple.cpp @@ -8,7 +8,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations /** diff --git a/math/sieve_of_eratosthenes.cpp b/math/sieve_of_eratosthenes.cpp index e252e1955cb..98df5833c2c 100644 --- a/math/sieve_of_eratosthenes.cpp +++ b/math/sieve_of_eratosthenes.cpp @@ -12,7 +12,7 @@ */ #include -#include /// for integral typedefs +#include #include #include diff --git a/math/string_fibonacci.cpp b/math/string_fibonacci.cpp index a7ff4c8bbad..1aef80f7a3c 100644 --- a/math/string_fibonacci.cpp +++ b/math/string_fibonacci.cpp @@ -8,7 +8,7 @@ * @see fibonacci_large.cpp, fibonacci_fast.cpp, fibonacci.cpp */ -#include /// for integral typedefs +#include #include #ifdef _MSC_VER #include // use this for MS Visual C diff --git a/math/sum_of_binomial_coefficient.cpp b/math/sum_of_binomial_coefficient.cpp index 38e02be21c7..c5b1fbeb681 100644 --- a/math/sum_of_binomial_coefficient.cpp +++ b/math/sum_of_binomial_coefficient.cpp @@ -10,7 +10,7 @@ * @author [muskan0719](https://github.com/muskan0719) */ #include /// for assert -#include /// for integral typedefs +#include #include /// for std::cin and std::cout /** diff --git a/numerical_methods/brent_method_extrema.cpp b/numerical_methods/brent_method_extrema.cpp index bd4d2796d29..ea3c783bc53 100644 --- a/numerical_methods/brent_method_extrema.cpp +++ b/numerical_methods/brent_method_extrema.cpp @@ -16,7 +16,7 @@ #define _USE_MATH_DEFINES ///< required for MS Visual C++ #include #include -#include /// for integral typedefs +#include #include #include #include diff --git a/numerical_methods/durand_kerner_roots.cpp b/numerical_methods/durand_kerner_roots.cpp index d8665a68aa4..a5afc6a0046 100644 --- a/numerical_methods/durand_kerner_roots.cpp +++ b/numerical_methods/durand_kerner_roots.cpp @@ -33,7 +33,7 @@ #include #include #include -#include /// for integral typedefs +#include #include #include #include diff --git a/numerical_methods/fast_fourier_transform.cpp b/numerical_methods/fast_fourier_transform.cpp index 23b52622b61..392789ea710 100644 --- a/numerical_methods/fast_fourier_transform.cpp +++ b/numerical_methods/fast_fourier_transform.cpp @@ -22,7 +22,7 @@ #include /// for assert #include /// for mathematical-related functions #include /// for storing points and coefficents -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector diff --git a/numerical_methods/golden_search_extrema.cpp b/numerical_methods/golden_search_extrema.cpp index 2d9dd507013..3f72db06f56 100644 --- a/numerical_methods/golden_search_extrema.cpp +++ b/numerical_methods/golden_search_extrema.cpp @@ -10,7 +10,7 @@ #define _USE_MATH_DEFINES //< required for MS Visual C++ #include #include -#include /// for integral typedefs +#include #include #include #include diff --git a/numerical_methods/inverse_fast_fourier_transform.cpp b/numerical_methods/inverse_fast_fourier_transform.cpp index 793588cb675..928a20da802 100644 --- a/numerical_methods/inverse_fast_fourier_transform.cpp +++ b/numerical_methods/inverse_fast_fourier_transform.cpp @@ -14,7 +14,7 @@ #include /// for assert #include /// for mathematical-related functions #include /// for storing points and coefficents -#include /// for integral typedefs +#include #include /// for IO operations #include /// for std::vector diff --git a/numerical_methods/newton_raphson_method.cpp b/numerical_methods/newton_raphson_method.cpp index ce75088a39a..1f5c9849f74 100644 --- a/numerical_methods/newton_raphson_method.cpp +++ b/numerical_methods/newton_raphson_method.cpp @@ -13,7 +13,7 @@ * \see bisection_method.cpp, false_position.cpp */ #include -#include /// for integral typedefs +#include #include #include #include diff --git a/numerical_methods/rungekutta.cpp b/numerical_methods/rungekutta.cpp index 2f446d4456a..8522bd0ebc2 100644 --- a/numerical_methods/rungekutta.cpp +++ b/numerical_methods/rungekutta.cpp @@ -19,7 +19,7 @@ * There can be many such equations */ #include /// asserting the test functions -#include /// for integral typedefs +#include #include /// for io operations #include /// for using the vector container /** diff --git a/others/easter.cpp b/others/easter.cpp index 44b10335300..6ae357deba7 100644 --- a/others/easter.cpp +++ b/others/easter.cpp @@ -18,7 +18,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations /* diff --git a/others/kadanes3.cpp b/others/kadanes3.cpp index 22c1119c858..3d7ef442cfd 100644 --- a/others/kadanes3.cpp +++ b/others/kadanes3.cpp @@ -17,7 +17,7 @@ #include /// for std::array #include /// for assert #include /// for INT_MIN value -#include /// for integral typedefs +#include #include /// for IO operations /** * @brief Utility function to check the current maximum number diff --git a/sorting/quick_sort.cpp b/sorting/quick_sort.cpp index 88d01ea1409..8a582790817 100644 --- a/sorting/quick_sort.cpp +++ b/sorting/quick_sort.cpp @@ -26,7 +26,7 @@ #include /// for std::is_sorted #include /// for std::assert -#include /// for integral typedefs +#include #include /// for std::time #include /// for IO operations #include /// for std::vector From 2d7f443b4c6d72acd1d4f3e1cf485beb924c8d81 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:29:11 +0530 Subject: [PATCH 129/131] chore: remove for integral typedefs from modular division --- math/modular_division.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/modular_division.cpp b/math/modular_division.cpp index 8208222f060..d37341b4a47 100644 --- a/math/modular_division.cpp +++ b/math/modular_division.cpp @@ -25,7 +25,7 @@ */ #include /// for assert -#include /// for integral typedefs +#include #include /// for IO operations /** From 39cd383a6d50a9759ed0a84174db5b7238f9e0f5 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 4 Oct 2024 18:49:04 +0530 Subject: [PATCH 130/131] fix: remove comment from include --- dynamic_programming/trapped_rainwater.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dynamic_programming/trapped_rainwater.cpp b/dynamic_programming/trapped_rainwater.cpp index 8ac80835180..d9e16682754 100644 --- a/dynamic_programming/trapped_rainwater.cpp +++ b/dynamic_programming/trapped_rainwater.cpp @@ -11,8 +11,8 @@ #include /// For std::min and std::max #include /// For assert #include /// For std::size_t -#include /// For integral typedefs -#include /// For std::vector +#include +#include /// For std::vector /* * @namespace From 030431fbe4122884c13d68aa7d2c34ecbe13a586 Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 4 Oct 2024 18:55:20 +0530 Subject: [PATCH 131/131] fix: add cstdint to gale shapely --- greedy_algorithms/gale_shapley.cpp | 96 +++++++++++++++++++----------- 1 file changed, 61 insertions(+), 35 deletions(-) diff --git a/greedy_algorithms/gale_shapley.cpp b/greedy_algorithms/gale_shapley.cpp index ddc6298fa44..6267bf3b160 100644 --- a/greedy_algorithms/gale_shapley.cpp +++ b/greedy_algorithms/gale_shapley.cpp @@ -1,24 +1,26 @@ /** * @file - * @brief [Gale Shapley Algorithm](https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm) + * @brief [Gale Shapley + * Algorithm](https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm) * @details - * This implementation utilizes the Gale-Shapley algorithm to find stable matches. + * This implementation utilizes the Gale-Shapley algorithm to find stable + * matches. * - * **Gale Shapley Algorithm** aims to find a stable matching between two equally sized - * sets of elements given an ordinal preference for each element. The algorithm was - * introduced by David Gale and Lloyd Shapley in 1962. - * - * Reference: + * **Gale Shapley Algorithm** aims to find a stable matching between two equally + * sized sets of elements given an ordinal preference for each element. The + * algorithm was introduced by David Gale and Lloyd Shapley in 1962. + * + * Reference: * [Wikipedia](https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm) * [Wikipedia](https://en.wikipedia.org/wiki/Stable_matching_problem) * * @author [B Karthik](https://github.com/BKarthik7) */ -#include /// for std::u32int_t -#include /// for std::vector #include /// for std::find #include /// for assert +#include /// for std::uint32_t +#include /// for std::vector /** * @namespace @@ -31,19 +33,25 @@ namespace greedy_algorithms { */ namespace stable_matching { /** - * @brief The main function that finds the stable matching between two sets of elements - * using the Gale-Shapley Algorithm. - * @note This doesn't work on negative preferences. the preferences should be continuous integers starting from - * 0 to number of preferences - 1. - * @param primary_preferences the preferences of the primary set should be a 2D vector - * @param secondary_preferences the preferences of the secondary set should be a 2D vector + * @brief The main function that finds the stable matching between two sets of + * elements using the Gale-Shapley Algorithm. + * @note This doesn't work on negative preferences. the preferences should be + * continuous integers starting from 0 to number of preferences - 1. + * @param primary_preferences the preferences of the primary set should be a 2D + * vector + * @param secondary_preferences the preferences of the secondary set should be a + * 2D vector * @returns matches the stable matching between the two sets */ -std::vector gale_shapley(const std::vector>& secondary_preferences, const std::vector>& primary_preferences) { +std::vector gale_shapley( + const std::vector>& secondary_preferences, + const std::vector>& primary_preferences) { std::uint32_t num_elements = secondary_preferences.size(); std::vector matches(num_elements, -1); std::vector is_free_primary(num_elements, true); - std::vector proposal_index(num_elements, 0); // Tracks the next secondary to propose for each primary + std::vector proposal_index( + num_elements, + 0); // Tracks the next secondary to propose for each primary while (true) { int free_primary_index = -1; @@ -57,10 +65,13 @@ std::vector gale_shapley(const std::vector gale_shapley(const std::vector gale_shapley(const std::vector> primary_preferences = {{0, 1, 2, 3}, {2, 1, 3, 0}, {1, 2, 0, 3}, {3, 0, 1, 2}}; - std::vector> secondary_preferences = {{1, 0, 2, 3}, {3, 0, 1, 2}, {0, 2, 1, 3}, {1, 2, 0, 3}}; - assert(greedy_algorithms::stable_matching::gale_shapley(secondary_preferences, primary_preferences) == std::vector({0, 2, 1, 3})); + std::vector> primary_preferences = { + {0, 1, 2, 3}, {2, 1, 3, 0}, {1, 2, 0, 3}, {3, 0, 1, 2}}; + std::vector> secondary_preferences = { + {1, 0, 2, 3}, {3, 0, 1, 2}, {0, 2, 1, 3}, {1, 2, 0, 3}}; + assert(greedy_algorithms::stable_matching::gale_shapley( + secondary_preferences, primary_preferences) == + std::vector({0, 2, 1, 3})); // Test Case 2 - primary_preferences = {{0, 2, 1, 3}, {2, 3, 0, 1}, {3, 1, 2, 0}, {2, 1, 0, 3}}; - secondary_preferences = {{1, 0, 2, 3}, {3, 0, 1, 2}, {0, 2, 1, 3}, {1, 2, 0, 3}}; - assert(greedy_algorithms::stable_matching::gale_shapley(secondary_preferences, primary_preferences) == std::vector({0, 3, 1, 2})); + primary_preferences = { + {0, 2, 1, 3}, {2, 3, 0, 1}, {3, 1, 2, 0}, {2, 1, 0, 3}}; + secondary_preferences = { + {1, 0, 2, 3}, {3, 0, 1, 2}, {0, 2, 1, 3}, {1, 2, 0, 3}}; + assert(greedy_algorithms::stable_matching::gale_shapley( + secondary_preferences, primary_preferences) == + std::vector({0, 3, 1, 2})); // Test Case 3 primary_preferences = {{0, 1, 2}, {2, 1, 0}, {1, 2, 0}}; secondary_preferences = {{1, 0, 2}, {2, 0, 1}, {0, 2, 1}}; - assert(greedy_algorithms::stable_matching::gale_shapley(secondary_preferences, primary_preferences) == std::vector({0, 2, 1})); + assert(greedy_algorithms::stable_matching::gale_shapley( + secondary_preferences, primary_preferences) == + std::vector({0, 2, 1})); // Test Case 4 primary_preferences = {}; secondary_preferences = {}; - assert(greedy_algorithms::stable_matching::gale_shapley(secondary_preferences, primary_preferences) == std::vector({})); + assert(greedy_algorithms::stable_matching::gale_shapley( + secondary_preferences, primary_preferences) == + std::vector({})); } /** @@ -124,6 +150,6 @@ static void tests() { * @returns 0 on exit */ int main() { - tests(); // Run self-test implementations + tests(); // Run self-test implementations return 0; }