text stringlengths 24 1.04M | metadata stringlengths 233 497 |
|---|---|
### File: others/fast_integer_input.cpp
/**
* @file
* @brief Read integers from stdin continuously as they are entered without
* waiting for the `\n` character
*/
#include <iostream>
/** Function to read the number from stdin. The function reads input until a non
* numeric character is entered.
*/
void fastinput... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/fast_integer_input.cpp", "license": "mit", "size": 1103} |
### File: others/happy_number.cpp
/**
* @file
* @brief A happy number is a number whose sum of digits is calculated until the
* sum is a single digit, and this sum turns out to be 1
*/
#include <iostream>
/**
* Checks if a decimal number is a happy number
* \returns true if happy else false
*/
template <typena... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/happy_number.cpp", "license": "mit", "size": 924} |
### File: others/iterative_tree_traversals.cpp
/**
* @file
* @brief Iterative version of Preorder, Postorder, and preorder [Traversal of
* the Tree] (https://en.wikipedia.org/wiki/Tree_traversal)
* @author [Motasim](https://github.com/motasimmakki)
* @details
*
* ### Iterative Preorder Traversal of a tree... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/iterative_tree_traversals.cpp", "license": "mit", "size": 14993} |
### File: others/kadanes3.cpp
/**
* @file
* @brief Efficient implementation for maximum contiguous subarray sum by
* [Kadane's
* algorithm](https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/).
* @details
* Our task is to take length of array and then the whole array as input from
* the user and then ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/kadanes3.cpp", "license": "mit", "size": 2775} |
### File: others/kelvin_to_celsius.cpp
/**
* @file
* @brief Conversion from [Kelvin to
* Celsius](https://byjus.com/chemistry/kelvin-to-celsius/) degrees.
* @details
* The algorithm consists on converting a Kelvin degree value to a Celsius
* value.
* The formula to convert a Kelvin to a Celsius value is:
* @f[ ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/kelvin_to_celsius.cpp", "license": "mit", "size": 2803} |
### File: others/lfu_cache.cpp
/**
* @file
* @brief Implementation for [LFU Cache]
* (https://en.wikipedia.org/wiki/Least_frequently_used)
*
* @details
* LFU discards the least frequently used value. if there are multiple items
* with the same minimum frequency then, the least recently used among them is
* disc... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/lfu_cache.cpp", "license": "mit", "size": 8691} |
### File: others/longest_substring_without_repeating_characters.cpp
/**
* @file
* @brief Solution for Longest Substring Without Repeating Characters problem.
* @details
* Problem link: https://leetcode.com/problems/longest-substring-without-repeating-characters/description/
*
* Intuition:
* 1) The intuition is ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/longest_substring_without_repeating_characters.cpp", "license": "mit", "size": 3823} |
### File: others/lru_cache.cpp
/**
* @file
* @brief An implementation of
* [LRU
* Cache](https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)).
* Lru is a part of cache algorithms (also frequently called cache replacement
* algorithms or cache replacement policies).
*
* ### Logic
... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/lru_cache.cpp", "license": "mit", "size": 7882} |
### File: others/lru_cache2.cpp
/**
* @file
* @brief Implementation for [LRU Cache]
* (https://en.wikipedia.org/wiki/Cache_replacement_policies#:~:text=Least%20Recently%20Used%20(LRU))
*
* @details
* LRU discards the least recently used value.
* Data structures used - doubly linked list and unordered_map
*
* u... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/lru_cache2.cpp", "license": "mit", "size": 7232} |
### File: others/matrix_exponentiation.cpp
/**
@file
@brief Matrix Exponentiation.
The problem can be solved with DP but constraints are high.
<br/>\f$a_i = b_i\f$ (for \f$i <= k\f$)
<br/>\f$a_i = c_1 a_{i-1} + c_2 a_{i-2} + ... + c_k a_{i-k}\f$ (for \f$i > k\f$)
<br/>Taking the example of Fibonacci series, \f$k=2\f$
... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/matrix_exponentiation.cpp", "license": "mit", "size": 3937} |
### File: others/palindrome_of_number.cpp
/**
* @file
* @brief Check if a number is
* [palindrome](https://en.wikipedia.org/wiki/Palindrome) or not.
*
* This program cheats by using the STL library's std::reverse function.
*/
#include <algorithm>
#include <iostream>
#ifdef _MSC_VER
// Required to compile std::to... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/palindrome_of_number.cpp", "license": "mit", "size": 780} |
### File: others/paranthesis_matching.cpp
/**
* @file
* @brief Perform paranthesis matching. \note Do not know the application of
* this, however.
* @note Implementation is C-type and does not utilize the C++ constructs
* @todo implement as a C++ class
*/
#include <iostream>
#ifdef _MSC_VER
#include <string> // ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/paranthesis_matching.cpp", "license": "mit", "size": 1716} |
### File: others/pascal_triangle.cpp
/**
* @file
* @brief Pascal's triangle implementation
*/
#ifdef _MSC_VER
#include <string> // required for Visual C
#else
#include <cstring>
#endif
#include <iomanip>
#include <iostream>
/**
* Print the triangle
* \param [in] arr 2D-array containing Pascal numbers
* \param ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/pascal_triangle.cpp", "license": "mit", "size": 1749} |
### File: others/postfix_evaluation.cpp
/**
* @file
* @brief Evaluation of [Postfix
* Expression](https://en.wikipedia.org/wiki/Reverse_Polish_notation)
* @author [Darshana Sarma](https://github.com/Darshana-Sarma)
* @details
* Create a stack to store operands (or values).
* Scan the given expression and do foll... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/postfix_evaluation.cpp", "license": "mit", "size": 5892} |
### File: others/primality_test.cpp
/**
* @file
* @brief [Primality test](https://en.wikipedia.org/wiki/Primality_test)
* implementation.
*
* A simple and efficient implementation of a function to test if a number is
* prime, based on the fact that
* > Every Prime number, except 2 and 3, are of the form \f$6k\pm... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/primality_test.cpp", "license": "mit", "size": 1124} |
### File: others/recursive_tree_traversal.cpp
/**
* @file
* @brief Recursive version of Inorder, Preorder, and Postorder [Traversal of
* the Tree] (https://en.wikipedia.org/wiki/Tree_traversal)
*
* @details
*
* ### Iterative Inorder Traversal of a tree
* For traversing a (non-empty) binary tree in an inorder fa... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/recursive_tree_traversal.cpp", "license": "mit", "size": 14601} |
### File: others/smallest_circle.cpp
/**
* @file
* @brief Get centre and radius of the
* [smallest circle](https://en.wikipedia.org/wiki/Smallest-circle_problem)
* that circumscribes given set of points.
*
* @see [other
* implementation](https://www.nayuki.io/page/smallest-enclosing-circle)
*/
#include <cmath>
... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/smallest_circle.cpp", "license": "mit", "size": 6838} |
### File: others/sparse_matrix.cpp
/** @file
* A sparse matrix is a matrix which has number of zeroes greater than
* \f$\frac{m\times n}{2}\f$, where m and n are the dimensions of the matrix.
*/
#include <iostream>
/** main function */
int main() {
int m, n;
int counterZeros = 0;
std::cout << "Enter d... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/sparse_matrix.cpp", "license": "mit", "size": 1207} |
### File: others/spiral_print.cpp
/**
* @file
* @brief Print the elements of a matrix traversing it spirally
*/
#include <iostream>
/** Arrange sequence of numbers from '1' in a matrix form
* \param [out] a matrix to fill
* \param [in] r number of rows
* \param [in] c number of columns
*/
void genArray(int **a,... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/spiral_print.cpp", "license": "mit", "size": 1967} |
### File: others/stairs_pattern.cpp
/**
* @file
@brief This program is use to print the following pattern<pre>
\*\*
\*\*
\*\*\*\*
\*\*\*\*
\*\*\*\*\*\*
\*\*\*\*\*\*
\*\*\*\*\*\*\*\*
********</pre>
where number of pairs line is given by user
*/
#include <iostream>
/** main function */
int main() {
int ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/stairs_pattern.cpp", "license": "mit", "size": 725} |
### File: others/tower_of_hanoi.cpp
/**
* @file
* @brief Solve the [Tower of
* Hanoi](https://en.wikipedia.org/wiki/Tower_of_Hanoi) problem.
*/
#include <iostream>
/**
* Define the state of tower
*/
struct tower {
//! Values in the tower
int values[10];
//! top tower ID
int top;
};
/** Display t... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/tower_of_hanoi.cpp", "license": "mit", "size": 1871} |
### File: others/vector_important_functions.cpp
/**
* @file
* @brief A C++ program to demonstrate working of std::sort(), std::reverse()
*/
#include <algorithm>
#include <iostream>
#include <numeric> // For accumulate operation
#include <vector>
/** Main function */
int main() {
// Initializing vector with arr... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "others/vector_important_functions.cpp", "license": "mit", "size": 1277} |
### File: physics/CMakeLists.txt
# If necessary, use the RELATIVE flag, otherwise each source file may be listed
# with full pathname. The RELATIVE flag makes it easier to extract an executable's name
# automatically.
file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp )
foreach( testsourcefile ${APP_SOU... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "CMake", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "physics/CMakeLists.txt", "license": "mit", "size": 744} |
### File: physics/ground_to_ground_projectile_motion.cpp
/**
* @file
* @brief Ground to ground [projectile
* motion](https://en.wikipedia.org/wiki/Projectile_motion) equation
* implementations
* @details Ground to ground projectile motion is when a projectile's trajectory
* starts at the ground, reaches the... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "physics/ground_to_ground_projectile_motion.cpp", "license": "mit", "size": 5813} |
### File: probability/CMakeLists.txt
# If necessary, use the RELATIVE flag, otherwise each source file may be listed
# with full pathname. RELATIVE may makes it easier to extract an executable name
# automatically.
file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp )
# file( GLOB APP_SOURCES ${CMAKE_SOUR... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "CMake", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "probability/CMakeLists.txt", "license": "mit", "size": 846} |
### File: probability/addition_rule.cpp
/**
* @file
* @brief Addition rule of probabilities
*/
#include <iostream>
/**
* calculates the probability of the independent events A or B for independent
* events
* \parama [in] A probability of event A
* \parama [in] B probability of event B
* \returns probability of... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "probability/addition_rule.cpp", "license": "mit", "size": 1164} |
### File: probability/bayes_theorem.cpp
/**
* @file
* @brief [Bayes' theorem](https://en.wikipedia.org/wiki/Bayes%27_theorem)
*
* Bayes' theorem allows one to find \f$P(A|B)\f$ given \f$P(B|A)\f$ or
* \f$P(B|A)\f$ given \f$P(A|B)\f$ and \f$P(A)\f$ and \f$P(B)\f$.\n
* Note that \f$P(A|B)\f$ is read 'The probabilit... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "probability/bayes_theorem.cpp", "license": "mit", "size": 886} |
### File: probability/binomial_dist.cpp
/**
* @file
* @brief [Binomial
* distribution](https://en.wikipedia.org/wiki/Binomial_distribution) example
*
* The binomial distribution models the number of
* successes in a sequence of n independent events
*
* Summary of variables used:
* * n : number of trials
* * p... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "probability/binomial_dist.cpp", "license": "mit", "size": 2885} |
### File: probability/exponential_dist.cpp
/**
* @file
* @brief [Exponential
* Distribution](https://en.wikipedia.org/wiki/Exponential_distribution)
*
* The exponential distribution is used to model
* events occuring between a Poisson process like radioactive decay.
*
* \f[P(x, \lambda) = \lambda e^{-\lambda x}... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "probability/exponential_dist.cpp", "license": "mit", "size": 4753} |
### File: probability/geometric_dist.cpp
/**
* @file
* @brief [Geometric
* Distribution](https://en.wikipedia.org/wiki/Geometric_distribution)
*
* @details
* The geometric distribution models the experiment of doing Bernoulli trials
* until a sucess was observed. There are two formulations of the geometric
* di... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "probability/geometric_dist.cpp", "license": "mit", "size": 9677} |
### File: probability/poisson_dist.cpp
/**
* @file
* @brief [Poisson
* statistics](https://en.wikipedia.org/wiki/Poisson_distribution)
*
* The Poisson distribution counts how many
* events occur over a set time interval.
*/
#include <cmath>
#include <iostream>
/**
* poisson rate:\n
* calculate the events per ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "probability/poisson_dist.cpp", "license": "mit", "size": 1929} |
### File: probability/windowed_median.cpp
/**
* @file
* @brief An implementation of a median calculation of a sliding window along a
* data stream
*
* @details
* Given a stream of integers, the algorithm calculates the median of a fixed
* size window at the back of the stream. The leading time complexity of this... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "probability/windowed_median.cpp", "license": "mit", "size": 9271} |
### File: range_queries/CMakeLists.txt
# If necessary, use the RELATIVE flag, otherwise each source file may be listed
# with full pathname. RELATIVE may makes it easier to extract an executable name
# automatically.
file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp )
# file( GLOB APP_SOURCES ${CMAKE_SO... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "CMake", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "range_queries/CMakeLists.txt", "license": "mit", "size": 848} |
### File: range_queries/fenwick_tree.cpp
/**
* @file
* @brief [Fenwick Tree](https://en.wikipedia.org/wiki/Fenwick_tree) algorithm
* implementation
* @details
* _From Wikipedia, the free encyclopedia._
*
* A Fenwick tree or binary indexed tree (BIT) is a clever implementation of a
* datastructure called bionoma... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "range_queries/fenwick_tree.cpp", "license": "mit", "size": 4001} |
### File: range_queries/heavy_light_decomposition.cpp
/**
* @file
* @brief [Heavy Light
* Decomposition](https://en.wikipedia.org/wiki/Heavy_path_decomposition)
* implementation
* @author [Aniruthan R](https://github.com/aneee004)
*
* @details
* Heavy-Light Decomposition is a technique on trees, that supports t... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "range_queries/heavy_light_decomposition.cpp", "license": "mit", "size": 19892} |
### File: range_queries/mo.cpp
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
const int N = 1e6 + 5;
int a[N], bucket[N], cnt[N];
int bucket_size;
struct query {
int l, r, i;
} q[N];
int ans = 0;
void add(int index) {
cnt[a[index]]++;
if (cnt[a[index]] == 1)
ans++;
... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "range_queries/mo.cpp", "license": "mit", "size": 1402} |
### File: range_queries/persistent_seg_tree_lazy_prop.cpp
/**
* @file
* @brief [Persistent segment tree with range updates (lazy
* propagation)](https://en.wikipedia.org/wiki/Persistent_data_structure)
*
* @details
* A normal segment tree facilitates making point updates and range queries in
* logarithmic time. ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "range_queries/persistent_seg_tree_lazy_prop.cpp", "license": "mit", "size": 12998} |
### File: range_queries/prefix_sum_array.cpp
/**
* @file
* @brief
* [Prefix Sum
* Array](https://en.wikipedia.org/wiki/Prefix_sum) data structure
* implementation.
*
* @details
* Prefix Sum Array is a data structure, that allows answering sum in some range
* queries. It can answer most sum range queri... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "range_queries/prefix_sum_array.cpp", "license": "mit", "size": 2388} |
### File: range_queries/segtree.cpp
/**
* @file
* @brief Implementation of [Segment Tree]
* (https://en.wikipedia.org/wiki/Segment_tree) data structure
*
* @details
* A segment tree, also known as a statistic tree, is a tree data structure used
* for storing information about intervals, or segments. I... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "range_queries/segtree.cpp", "license": "mit", "size": 6813} |
### File: range_queries/sparse_table_range_queries.cpp
/**
* @file sparse_table.cpp
* @brief Implementation of [Sparse
* Table](https://en.wikipedia.org/wiki/Range_minimum_query) data structure
*
* @details
* Sparse Table is a data structure, that allows answering range queries.
* It can answer most range querie... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "range_queries/sparse_table_range_queries.cpp", "license": "mit", "size": 3255} |
### File: scripts/file_linter.py
import os
import subprocess
import sys
print("Python {}.{}.{}".format(*sys.version_info)) # Python 3.8
with open("git_diff.txt") as in_file:
modified_files = sorted(in_file.read().splitlines())
print("{} files were modified.".format(len(modified_files)))
cpp_exts = tuple(... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "scripts/file_linter.py", "license": "mit", "size": 1720} |
### File: search/CMakeLists.txt
# If necessary, use the RELATIVE flag, otherwise each source file may be listed
# with full pathname. RELATIVE may makes it easier to extract an executable name
# automatically.
file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp )
# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DI... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "CMake", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/CMakeLists.txt", "license": "mit", "size": 841} |
### File: search/binary_search.cpp
/******************************************************************************
* @file
* @brief [Binary search
* algorithm](https://en.wikipedia.org/wiki/Binary_search_algorithm)
* @details
* Binary search is a search algorithm that finds the position of a target value
* within... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/binary_search.cpp", "license": "mit", "size": 6027} |
### File: search/exponential_search.cpp
/**
* \file
* \brief [Exponential search
* algorithm](https://en.wikipedia.org/wiki/Exponential_search)
* \copyright 2020 Divide-et-impera-11
*
* The algorithm try to search the range where the key should be.
* If it has been found we do a binary search there.
* The range... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/exponential_search.cpp", "license": "mit", "size": 2837} |
### File: search/fibonacci_search.cpp
/**
* @author sprintyaf
* @file fibonacci_search.cpp
* @brief [Fibonacci search
* algorithm](https://en.wikipedia.org/wiki/Fibonacci_search_technique)
*/
#include <iostream>
#include <vector> // for std::vector class
#include <cassert> // for assert
#include <cstdlib> // for ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/fibonacci_search.cpp", "license": "mit", "size": 3972} |
### File: search/floyd_cycle_detection_algo.cpp
/**
* @file
* @brief Implementation of [Floyd's Cycle
* Detection](https://en.wikipedia.org/wiki/Cycle_detection) algorithm
* @details
* Given an array of integers containing 'n + 1' integers, where each
* integer is in the range [1, n] inclusive. If there is only o... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/floyd_cycle_detection_algo.cpp", "license": "mit", "size": 3083} |
### File: search/hash_search.cpp
/**
* \file
* \brief Hash Search Algorithm - Best Time Complexity Ω(1)
*
* \copyright 2020 Arctic2333
*
* In this algorithm, we use the method of division and reservation remainder to
* construct the hash function, and use the method of chain address to solve the
* conflict, tha... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/hash_search.cpp", "license": "mit", "size": 3874} |
### File: search/interpolation_search.cpp
/******************************************************************************
* @file
* @brief [Interpolation search
* algorithm](https://en.wikipedia.org/wiki/interpolation_search)
*
* @details
* interpolation search resembles the method by which people search a telep... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/interpolation_search.cpp", "license": "mit", "size": 4783} |
### File: search/interpolation_search2.cpp
/**
* \file
* \brief [Interpolation
* search](https://en.wikipedia.org/wiki/Interpolation_search) algorithm
*/
#include <iostream>
/** function to search the value in an array using interpolation search
* \param [in] arr array to search in
* \param [in] value v... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/interpolation_search2.cpp", "license": "mit", "size": 1420} |
### File: search/jump_search.cpp
/**
* \file
* \brief C++ program to implement [Jump
* Search](https://en.wikipedia.org/wiki/Jump_search)
*/
#include <algorithm>
#include <cmath>
#include <iostream>
/** jump search implementation
*/
int jumpSearch(int arr[], int x, int n) {
// Finding block size to be jumped
... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/jump_search.cpp", "license": "mit", "size": 1320} |
### File: search/linear_search.cpp
/**
* \file
* \brief [Linear search
* algorithm](https://en.wikipedia.org/wiki/Linear_search)
*
* @author Unknown author
* @author [Ritika Mukherjee](https://github.com/ritikaa17)
*/
#include <cassert> /// for assert
#include <iostream> /// for IO operations
/**
* \brief ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/linear_search.cpp", "license": "mit", "size": 2736} |
### File: search/longest_increasing_subsequence_using_binary_search.cpp
/**
* @file
* @brief find the length of the Longest Increasing Subsequence (LIS)
* using [Binary Search](https://en.wikipedia.org/wiki/Longest_increasing_subsequence)
* @details
* Given an integer array nums, return the length of the longest s... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/longest_increasing_subsequence_using_binary_search.cpp", "license": "mit", "size": 4367} |
### File: search/median_search.cpp
/**
* @file median_search.cpp
* @brief Implementation of [Median search](https://en.wikipedia.org/wiki/Median_of_medians) algorithm.
* @cases from [here](https://brilliant.org/wiki/median-finding-algorithm/)
*
* @details
* Given an array A[1,...,n] of n numbers and an index i, w... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/median_search.cpp", "license": "mit", "size": 4435} |
### File: search/median_search2.cpp
/**
* @file
* @brief Given a linked list L[0,....,n] of n numbers, find the middle node.
*
* @details The technique utilized in this implementation is the ["Floyd's
* tortoise and
* hare"](https://en.wikipedia.org/wiki/Cycle_detection#Floyd's_tortoise_and_hare)
* approach. Thi... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/median_search2.cpp", "license": "mit", "size": 3981} |
### File: search/saddleback_search.cpp
/**
* @file
* @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 ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/saddleback_search.cpp", "license": "mit", "size": 4346} |
### File: search/sublist_search.cpp
/**
* @file
* @brief Implementation of the [Sublist Search
* Algorithm](https://www.geeksforgeeks.org/sublist-search-search-a-linked-list-in-another-list)
* @details
*
* ### Algorithm
*
* * Sublist search is used to detect a presence of one list in another list.
* * Suppos... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/sublist_search.cpp", "license": "mit", "size": 12459} |
### File: search/ternary_search.cpp
/**
* \file
* \brief [Ternary search](https://en.wikipedia.org/wiki/Ternary_search)
* algorithm
*
* This is a divide and conquer algorithm.
* It does this by dividing the search space by 3 parts and
* using its property (usually monotonic property) to find
* the desired index... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/ternary_search.cpp", "license": "mit", "size": 4035} |
### File: search/text_search.cpp
/**
* \file
* \brief Search for words in a long textual paragraph.
*/
#include <cassert>
#include <cstdlib>
#include <iostream>
#ifdef _MSC_VER
#include <string> // required for MS Visual C++
#else
#include <cstring>
#endif
/**
* @brief function to convert a C++ stri... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "search/text_search.cpp", "license": "mit", "size": 3352} |
### File: sorting/CMakeLists.txt
# If necessary, use the RELATIVE flag, otherwise each source file may be listed
# with full pathname. RELATIVE may makes it easier to extract an executable name
# automatically.
file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp )
# file( GLOB APP_SOURCES ${CMAKE_SOURCE_D... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "CMake", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/CMakeLists.txt", "license": "mit", "size": 874} |
### File: sorting/bead_sort.cpp
// C++ program to implement gravity/bead sort
#include <cstdio>
#include <cstring>
#define BEAD(i, j) beads[i * max + j]
// function to perform the above algorithm
void beadSort(int *a, int len) {
// Find the maximum element
int max = a[0];
for (int i = 1; i < len; i++)
... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/bead_sort.cpp", "license": "mit", "size": 1331} |
### File: sorting/binary_insertion_sort.cpp
/**
* \file
* \brief [Binary Insertion Sort Algorithm
* (Insertion Sort)](https://en.wikipedia.org/wiki/Insertion_sort)
*
* \details
* If the cost of comparisons exceeds the cost of swaps, as is the case for
* example with string keys stored by reference or with... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/binary_insertion_sort.cpp", "license": "mit", "size": 5417} |
### File: sorting/bitonic_sort.cpp
// Source : https://www.geeksforgeeks.org/bitonic-sort/
/* C++ Program for Bitonic Sort. Note that this program
works only when size of input is a power of 2. */
#include <algorithm>
#include <iostream>
/*The parameter dir indicates the sorting direction, ASCENDING
or DESCEND... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/bitonic_sort.cpp", "license": "mit", "size": 2047} |
### File: sorting/bogo_sort.cpp
/**
* @file
* @brief Implementation of [Bogosort algorithm](https://en.wikipedia.org/wiki/Bogosort)
*
* @details
* In computer science, bogosort (also known as permutation sort, stupid sort, slowsort,
* shotgun sort, random sort, monkey sort, bobosort or shuffle sort) is... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/bogo_sort.cpp", "license": "mit", "size": 3474} |
### File: sorting/bubble_sort.cpp
/**
* @file
* @brief Bubble sort algorithm
*
* @details
* Bubble sort algorithm is the bubble sorting algorithm. The most important reason
* for calling the bubble is that the largest number is thrown at the end of this
* algorithm. This is all about the logic. In each iteration... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/bubble_sort.cpp", "license": "mit", "size": 4518} |
### File: sorting/bucket_sort.cpp
// C++ program to sort an array using bucket sort
#include <algorithm>
#include <iostream>
#include <vector>
// Function to sort arr[] of size n using bucket sort
void bucketSort(float arr[], int n) {
// 1) Create n empty buckets
std::vector<float> *b = new std::vector<float>[... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/bucket_sort.cpp", "license": "mit", "size": 1055} |
### File: sorting/cocktail_selection_sort.cpp
// Returns Sorted elements after performing Cocktail Selection Sort
// It is a Sorting algorithm which chooses the minimum and maximum element in an
// array simultaneously, and swaps it with the lowest and highest available
// position iteratively or recursively
#include ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/cocktail_selection_sort.cpp", "license": "mit", "size": 2759} |
### File: sorting/comb_sort.cpp
/**
*
* \file
* \brief [Comb Sort Algorithm
* (Comb Sort)](https://en.wikipedia.org/wiki/Comb_sort)
*
* \author
*
* \details
* - A better version of bubble sort algorithm
* - Bubble sort compares adjacent values whereas comb sort uses gap larger
* than 1
* - Best case Time ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/comb_sort.cpp", "license": "mit", "size": 2363} |
### File: sorting/count_inversions.cpp
/**
* @file
* @brief Counting Inversions using [Merge
Sort](https://en.wikipedia.org/wiki/Merge_sort)
*
* @details
* Program to count the number of inversions in an array
* using merge-sort.
*
* The count of inversions help to determine how close the array
* is to be sor... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/count_inversions.cpp", "license": "mit", "size": 8936} |
### File: sorting/counting_sort.cpp
#include <iostream>
using namespace std;
int Max(int Arr[], int N) {
int max = Arr[0];
for (int i = 1; i < N; i++)
if (Arr[i] > max)
max = Arr[i];
return max;
}
int Min(int Arr[], int N) {
int min = Arr[0];
for (int i = 1; i < N; i++)
... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/counting_sort.cpp", "license": "mit", "size": 1371} |
### File: sorting/counting_sort_string.cpp
// C++ Program for counting sort
#include <iostream>
using namespace std;
void countSort(string arr) {
string output;
int count[256], i;
for (int i = 0; i < 256; i++) count[i] = 0;
for (i = 0; arr[i]; ++i) ++count[arr[i]];
for (i = 1; i < 256; ++i) cou... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/counting_sort_string.cpp", "license": "mit", "size": 593} |
### File: sorting/cycle_sort.cpp
/**
* @file
* @brief Implementation of [Cycle
* sort](https://en.wikipedia.org/wiki/Cycle_sort) algorithm
* @details
* Cycle Sort is a sorting algorithm that works in \f$O(n^2)\f$ time in the best
* case and works in \f$O(n^2)\f$ in worst case. If a element is already at its
* co... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/cycle_sort.cpp", "license": "mit", "size": 4082} |
### File: sorting/dnf_sort.cpp
/**
* @file
* @brief Implementation of the [DNF
* sort](https://www.geeksforgeeks.org/sort-an-array-of-0s-1s-and-2s/)
* implementation
* @details
* C++ program to sort an array with 0, 1 and 2 in a single pass(DNF sort).
* Since one traversal of the array is there hence it works in... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/dnf_sort.cpp", "license": "mit", "size": 3274} |
### File: sorting/gnome_sort.cpp
/**
* @file
* @brief Implementation of [gnome
* sort](https://en.wikipedia.org/wiki/Gnome_sort) algorithm.
* @author [beqakd](https://github.com/beqakd)
* @author [Krishna Vedala](https://github.com/kvedala)
* @details
* Gnome sort algorithm is not the best one but it is widely u... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/gnome_sort.cpp", "license": "mit", "size": 4090} |
### File: sorting/heap_sort.cpp
/**
* \file
* \brief [Heap Sort Algorithm
* (heap sort)](https://en.wikipedia.org/wiki/Heapsort) implementation
*
* \author [Ayaan Khan](http://github.com/ayaankhan98)
*
* \details
* Heap-sort is a comparison-based sorting algorithm.
* Heap-sort can be thought of as an improve... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/heap_sort.cpp", "license": "mit", "size": 3124} |
### File: sorting/insertion_sort.cpp
/**
*
* \file
* \brief [Insertion Sort Algorithm
* (Insertion Sort)](https://en.wikipedia.org/wiki/Insertion_sort)
*
* \details
* Insertion sort is a simple sorting algorithm that builds the final
* sorted array one at a time. It is much less efficient compared to
* other s... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/insertion_sort.cpp", "license": "mit", "size": 5125} |
### File: sorting/insertion_sort_recursive.cpp
/**
* @file
* @brief Insertion Sort Algorithm
* @author [Dhanush S](https://github.com/Fandroid745)
*
* @details
* Insertion sort is a simple sorting algorithm that builds the final
* sorted array one element at a time. It is much less efficient compared
* to othe... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/insertion_sort_recursive.cpp", "license": "mit", "size": 4276} |
### File: sorting/library_sort.cpp
#include <algorithm>
#include <iostream>
void librarySort(int *index, int n) {
int lib_size, index_pos,
*gaps, // gaps
*library[2]; // libraries
bool target_lib, *numbered;
for (int i = 0; i < 2; i++) library[i] = new int[n];
gaps = new int[... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/library_sort.cpp", "license": "mit", "size": 2557} |
### File: sorting/merge_insertion_sort.cpp
/**
* @file
* @author [@sinkyoungdeok](https://github.com/sinkyoungdeok)
* @author [Krishna Vedala](https://github.com/kvedala)
* @brief Algorithm that combines insertion sort and merge sort. [Wiki
* link](https://en.wikipedia.org/wiki/Merge-insertion_sort)
*
* @see Ind... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/merge_insertion_sort.cpp", "license": "mit", "size": 4457} |
### File: sorting/merge_sort.cpp
/**
* \addtogroup sorting Sorting Algorithms
* @{
* \file
* \brief [Merge Sort Algorithm
* (MERGE SORT)](https://en.wikipedia.org/wiki/Merge_sort) implementation
*
* \author [Ayaan Khan](http://github.com/ayaankhan98)
*
* \details
* Merge Sort is an efficient, general ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/merge_sort.cpp", "license": "mit", "size": 2999} |
### File: sorting/non_recursive_merge_sort.cpp
/**
* Copyright 2020 @author Albirair
* @file
*
* A generic implementation of non-recursive merge sort.
*/
#include <cstddef> // for size_t
#include <iostream>
#include <utility> // for std::move & std::remove_reference_t
namespace sorting {
template <class Iterato... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/non_recursive_merge_sort.cpp", "license": "mit", "size": 4180} |
### File: sorting/numeric_string_sort.cpp
// Using general algorithms to sort a collection of strings results in
// alphanumeric sort. If it is a numeric string, it leads to unnatural sorting
// eg, an array of strings 1,10,100,2,20,200,3,30,300
// would be sorted in that same order by using conventional sorting,
// e... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/numeric_string_sort.cpp", "license": "mit", "size": 1449} |
### File: sorting/odd_even_sort.cpp
/* C++ implementation Odd Even Sort */
#include <iostream>
#include <vector>
using namespace std;
void oddEven(vector<int> &arr, int size) {
bool sorted = false;
while (!sorted) {
sorted = true;
for (int i = 1; i < size - 1; i += 2) // Odd
{
... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/odd_even_sort.cpp", "license": "mit", "size": 1089} |
### File: sorting/pancake_sort.cpp
/**
* @file
* @brief pancake sort sorts a disordered stack of pancakes by flipping any
* number of pancakes using a spatula using minimum number of flips.
*
* @details
* Unlike a traditional sorting algorithm, which attempts to sort with the
* fewest comparisons possible, the g... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/pancake_sort.cpp", "license": "mit", "size": 4028} |
### File: sorting/pigeonhole_sort.cpp
/**
* @file
* @brief Implementation of [Pigeonhole Sort algorithm]
* (https://en.wikipedia.org/wiki/Pigeonhole_sort)
* @author [Lownish](https://github.com/Lownish)
* @details
* Pigeonhole sorting is a sorting algorithm that is suitable for sorting lists
* of elements where ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/pigeonhole_sort.cpp", "license": "mit", "size": 3407} |
### File: sorting/quick_sort.cpp
/**
* @file
* @brief [Quick sort implementation](https://en.wikipedia.org/wiki/Quicksort)
* in C++
* @details
* Quick Sort is a [divide and conquer
* algorithm](https://en.wikipedia.org/wiki/Category:Divide-and-conquer_algorithms).
* It picks an element as pivot and par... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/quick_sort.cpp", "license": "mit", "size": 8190} |
### File: sorting/quick_sort_3.cpp
/**
* @file
* @brief Implementation Details
* @details Quick sort 3 works on Dutch National Flag Algorithm
* The major difference between simple quicksort and quick sort 3 comes in the
* function partition3 In quick_sort_partition3 we divide the vector/array into
* 3 parts. quic... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/quick_sort_3.cpp", "license": "mit", "size": 5726} |
### File: sorting/quick_sort_iterative.cpp
/**
* @file
* @brief Quick Sort without recursion. This method uses the stack instead.
* Both recursive and iterative implementations have O(n log n) best case
* and O(n^2) worst case.
* @details
* https://stackoverflow.com/questions/12553238/quicksort-iterative-or-recur... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/quick_sort_iterative.cpp", "license": "mit", "size": 3331} |
### File: sorting/radix_sort.cpp
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
void radixsort(int a[], int n) {
int count[10];
int* output = new int[n];
memset(output, 0, n * sizeof(*output));
memset(count, 0, sizeof(count));
int max = 0;
for (int i = 0; i < n; ++i)... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/radix_sort.cpp", "license": "mit", "size": 1347} |
### File: sorting/radix_sort2.cpp
/**
* @file
* @brief Algorithm of [Radix sort](https://en.wikipedia.org/wiki/Radix_sort)
* @author [Suyash Jaiswal](https://github.com/Suyashjaiswal)
* @details
* Sort the vector of unsigned integers using radix sort i.e. sorting digit by
* digit using [Counting Sort](https://en.... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/radix_sort2.cpp", "license": "mit", "size": 3878} |
### File: sorting/random_pivot_quick_sort.cpp
/**
* @file
* @brief Implementation of the [Random Pivot Quick
* Sort](https://www.sanfoundry.com/cpp-program-implement-quick-sort-using-randomisation)
* algorithm.
* @details
* * A random pivot quick sort algorithm is pretty much same as quick
* sort with a... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/random_pivot_quick_sort.cpp", "license": "mit", "size": 11901} |
### File: sorting/recursive_bubble_sort.cpp
/**
* @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/)
*
* @details
* The working principle of the Bubble sort alg... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/recursive_bubble_sort.cpp", "license": "mit", "size": 4784} |
### File: sorting/selection_sort_iterative.cpp
/******************************************************************************
* @file
* @brief Implementation of the [Selection
* sort](https://en.wikipedia.org/wiki/Selection_sort) implementation using
* swapping
* @details
* The selection sort algorithm divides t... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/selection_sort_iterative.cpp", "license": "mit", "size": 5553} |
### File: sorting/selection_sort_recursive.cpp
/**
* @file
* @brief Implementation of the [Selection
* sort](https://en.wikipedia.org/wiki/Selection_sort)
* implementation using recursion
* @details
* The selection sort algorithm divides the input list into two parts: a sorted
* sublist of items which is built u... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/selection_sort_recursive.cpp", "license": "mit", "size": 5000} |
### File: sorting/shell_sort.cpp
#include <iostream>
int main() {
int size = 10;
int* array = new int[size];
// Input
std::cout << "\nHow many numbers do want to enter in unsorted array : ";
std::cin >> size;
std::cout << "\nEnter the numbers for unsorted array : ";
for (int i = 0; i < size... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/shell_sort.cpp", "license": "mit", "size": 935} |
### File: sorting/shell_sort2.cpp
/**
* \file
* \brief [Shell sort](https://en.wikipedia.org/wiki/Shell_sort) algorithm
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <utility> // for std::swap
#include <vector... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/shell_sort2.cpp", "license": "mit", "size": 7034} |
### File: sorting/slow_sort.cpp
// Returns the sorted vector after performing SlowSort
// It is a sorting algorithm that is of humorous nature and not useful.
// It's based on the principle of multiply and surrender, a tongue-in-cheek joke
// of divide and conquer. It was published in 1986 by Andrei Broder and Jorge
//... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/slow_sort.cpp", "license": "mit", "size": 1582} |
### File: sorting/stooge_sort.cpp
/**
* @file
* @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:
* - sort first two thirds of the array
* - sort last two thirds ... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/stooge_sort.cpp", "license": "mit", "size": 2182} |
### File: sorting/strand_sort.cpp
/**
* @file strand_sort.cpp
* @brief Implementation of [Strand Sort](https://en.wikipedia.org/wiki/Strand_sort) algorithm.
*
* @details
* Strand Sort is a sorting algorithm that works in \f$O(n)\f$ time if list is already sorted and works in \f$O(n^2)\f$ in worst case.
*
* It i... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/strand_sort.cpp", "license": "mit", "size": 3274} |
### File: sorting/swap_sort.cpp
// C++ program to find minimum number of swaps required to sort an array
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
// Function returns the minimum number of swaps
// required to sort the array
int minSwaps(int arr[], int n) {
// Create an array of... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/swap_sort.cpp", "license": "mit", "size": 1765} |
### File: sorting/tim_sort.cpp
// C++ program to perform TimSort.
#include <algorithm>
#include <cassert>
#include <iostream>
#include <numeric>
const int RUN = 32;
// this function sorts array from left index to to right index which is of size
// atmost RUN
void insertionSort(int arr[], int left, int right) {
fo... | {"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/TheAlgorithms-c-plus-plus", "path": "sorting/tim_sort.cpp", "license": "mit", "size": 3414} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.