From aaa08b0150acc987a47f87b26d64dbbdf96945ac Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Fri, 19 Jun 2020 12:04:56 -0400 Subject: [PATCH] Major rework to improve code quality and add automation checks (#805) * delete secant method - it is identical to regula falsi * document + improvize root finding algorithms * attempt to document gaussian elimination * added file brief * commented doxygen-mainpage, added files-list link * corrected files list link path * files-list link correction - this time works :) * document successive approximations * cleaner equation * updating DIRECTORY.md * documented kmp string search * document brute force string search * document rabin-karp string search * fixed mainpage readme * doxygen v1.8.18 will suppress out the #minipage in the markdown * cpplint correction for header guard style * github action to auto format source code per cpplint standard * updated setting to add 1 space before `private` and `public` keywords * auto rename files and auto format code * added missing "run" for step * corrected asignmemt operation * fixed trim and assign syntax * added git move for renaming bad filenames * added missing pipe for trim * added missing space * use old and new fnames * store old fname using echo * move files only if there is a change in filename * put old filenames in quotes * use double quote for old filename * escape double quotes * remove old_fname * try escape characters and echo" * add file-type to find * cleanup echo * ensure all trim variables are also in quotes * try escape -quote again * remove second escpe quote * use single quote for first check * use carets instead of quotes * put variables in brackets * remove -e from echo * add debug echos * try print0 flag * find command with while instead of for-loop * find command using IFS instead * :tada: IFS fix worked - escaped quotes for git mv * protetc each word in git mv .. * filename exists in lower cases - renamed * :tada: git push enabled * updating DIRECTORY.md * git pull & then push * formatting filenames d7af6fdc8cb08578de6980d412e6e1caca1a1bcf * formatting source-code for d7af6fdc8cb08578de6980d412e6e1caca1a1bcf * remove allman break before braces * updating DIRECTORY.md * added missing comma lost in previous commit * orchestrate all workflows * fix yml indentation * force push format changes, add title to DIRECTORY.md * pull before proceeding * reorganize pull commands * use master branches for actions * rename .cc files to .cpp * added class destructor to clean up dynamic memory allocation * rename to awesome workflow * commented whole repo cpplint - added modified files lint check * removed need for cpplint * attempt to use actions/checkout@master * temporary: no dependency on cpplint * formatting filenames 153fb7b8a572aaf4561ac3d22d47e89480f11318 * formatting source-code for 153fb7b8a572aaf4561ac3d22d47e89480f11318 * updating DIRECTORY.md * fix diff filename * added comments to the code * added test case * formatting source-code for a850308fbada18c0d4b6f9a9cac5c34fc064cbae * updating DIRECTORY.md * added machine learning folder * added adaline algorithm * updating DIRECTORY.md * fixed issue [LWG2192](https://cplusplus.github.io/LWG/issue2192) for std::abs on MacOS * add cmath for same bug: [LWG2192](https://cplusplus.github.io/LWG/issue2192) for std::abs on MacOS * formatting source-code for f8925e482216aecd152bc898653ee9ab82213cf3 * use STL's inner_product * formatting source-code for f94a3305943d4cf00e4531857279b8032d0e9489 * added range comments * define activation function * use equal initial weights * change test2 function to predict * activation function not friend * previous commit correction * added option for predict function to return value before applying activation function as optional argument * added test case to classify points lying within a sphere * improve documentation for adaline * formatting source-code for 15ec4c3aba4fb41b81ed2b44b7154a4f7b45a898 * added cmake to geometry folder * added algorithm include for std::max * add namespace - machine_learning * add namespace - statistics * add namespace - sorting * added sorting algos to namespace sorting * added namespace string_search * formatting source-code for fd695305150777981dc2a1f256aa2be444e4f108 * added documentation to string_search namespace * feat: Add BFS and DFS algorithms to check for cycle in a directed graph * Remove const references for input of simple types Reason: overhead on access * fix bad code sorry for force push * Use pointer instead of the non-const reference because apparently google says so. * Remove a useless and possibly bad Graph constuctor overload * Explicitely specify type of vector during graph instantiation * updating DIRECTORY.md * find openMP before adding subdirectories * added kohonen self organizing map * updating DIRECTORY.md * remove older files and folders from gh-pages before adding new files * remove chronos library due to inacceptability by cpplint * use c++ specific static_cast instead * initialize radom number generator * updated image links with those from CPP repository * rename computer.... folder to numerical methods * added durand kerner method for root computation for arbitrarily large polynomials * fixed additional comma * fix cpplint errors * updating DIRECTORY.md * convert to function module * update documentation * move openmp to main loop * added two test cases * use INT16_MAX * remove return statement from omp-for loop and use "break" * run tests when no input is provided and skip tests when input polynomial is provided * while loop cannot have break - replaced with continue and check is present in the main while condition * (1) break while loop (2) skip runs on break_loop instead of hard-break * add documentation images * use long double for errors and tolerance checks * make iterator variable i local to threads * add critical secions to omp threads * bugfix: move file writing outside of the parallel loop othersie, there is no gurantee of the order of roots written to file * rename folder to data_structures * updating DIRECTORY.md * fix ambiguous symbol `size` * add data_structures to cmake * docs: enable tree view, add timestamp in footer, try clang assistaed parsing * doxygen - open links in external window * remove invalid parameter from function docs * use HTML5 img tag to resize images * move file to proper folder * fix documentations and cpplint * formatting source-code for aacaf9828c61bb0246fe0933ab8ade82128b8346 * updating DIRECTORY.md * cpplint: add braces for multiple statement if * add explicit link to badges * remove duplicate line Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * remove namespace indentation * remove file associations in settings * add author name * enable cmake in subfolders of data_structures * create and link object file * cpp lint fixes and instantiate template classes * cpp lint fixes and instantiate template classes Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * cpplint - ignore `build/include` Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * disable redundant gcc compilation in cpplint workflow Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * template header files contain function codes as well and removed redundant subfolders Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * updating DIRECTORY.md * remove semicolons after functions in a class Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * cpplint header guard style Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * remove semilon Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * added LU decomposition algorithm Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * added QR decomposition algorithm Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * use QR decomposition to find eigen values Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * updating DIRECTORY.md * use std::rand for thread safety Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * move srand to main() Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * cpplint braces correction Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * updated eigen value documentation Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * fix matrix shift doc Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> * rename CONTRIBUTION.md to CONTRIBUTING.md #836 * remove 'sort alphabetical order' check * added documentation check * remove extra paranthesis * added gitpod * added gitpod link from README * attempt to add vscode gitpod extensions * update gitpod extensions * add gitpod extensions cmake-tools and git-graph * remove gitpod init and add commands * use init to one time install doxygen, graphviz, cpplint * use gitpod dockerfile * add ninja build system to docker * remove configure task * add github prebuild specs to gitpod * disable gitpod addcommit * update documentation for kohonen_som * added ode solve using forward euler method * added mid-point euler ode solver * fixed itegration step equation * added semi-implicit euler ODE solver * updating DIRECTORY.md * fix cpplint issues - lines 117 and 124 * added documentation to ode group * corrected semi-implicit euler function * updated docs and test cases better structure * replace `free` with `delete` operator * formatting source-code for f55ab50cf26d176fe56bdaffa6f0ce8023c03c18 * updating DIRECTORY.md * main function must return * added machine learning group * added kohonen som topology algorithm * fix graph image path * updating DIRECTORY.md * fix braces * use snprintf instead of sprintf * use static_cast * hardcode character buffer size * fix machine learning groups in documentation * fix missing namespace function * replace kvedala fork references to TheAlgorithms * fix bug in counting_sort Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Anmol3299 --- .github/pull_request_template.md | 8 +- .github/workflows/awesome_forkflow.yml | 211 + .github/workflows/cpplint.yml | 13 - .github/workflows/cpplint_modified_files.yml | 64 - .github/workflows/gh-pages.yml | 36 + .../sorting_non_recursive_merge_sort.yml | 24 - .github/workflows/update_directory_md.yml | 68 - .gitignore | 2 + .gitpod.dockerfile | 9 + .gitpod.yml | 17 + .vscode/settings.json | 69 +- CMakeLists.txt | 81 + CONTRIBUTION.md => CONTRIBUTING.md | 0 DIRECTORY.md | 244 +- README.md | 16 +- backtracking/graph_coloring.cpp | 29 +- backtracking/knight_tour.cpp | 84 +- backtracking/minimax.cpp | 2 +- backtracking/n_queens.cpp | 36 +- .../n_queens_all_solution_optimised.cpp | 26 +- backtracking/rat_maze.cpp | 109 +- backtracking/sudoku_solve.cpp | 98 +- .../Bisection_method.CPP | 53 - .../Gaussian_elimination.cpp | 63 - .../Newton_Raphson.CPP | 53 - .../Secant_method.CPP | 49 - .../false-position.cpp | 35 - .../ordinary_least_squares_regressor.cpp | 349 - .../successive_approximation.CPP | 37 - data_structure/AVLtree.cpp | 176 - data_structure/Binary Search Tree.cpp | 218 - data_structure/Binaryheap.cpp | 158 - data_structure/List Array.cpp | 188 - data_structure/MorrisInorder.cpp | 108 - data_structure/Queue Using Array.cpp | 75 - data_structure/Stack Using Array.cpp | 79 - data_structure/Stack Using Linked List.cpp | 73 - data_structure/cll/cll.h | 45 - data_structure/cll/main_cll.cpp | 44 - data_structure/cll/makefile | 11 - data_structure/disjoint_set.cpp | 64 - data_structure/doubly_linked_list.cpp | 138 - .../linkedList_implentation_usingArray.cpp | 106 - data_structure/linked_list.cpp | 135 - data_structure/queue/makefile | 11 - data_structure/queue/queue.cpp | 90 - data_structure/queue/queue.h | 34 - data_structure/queue/test_queue.cpp | 38 - data_structure/queue_using_linkedlist.cpp | 98 - data_structure/stk/makefile | 13 - data_structure/stk/stack.cpp | 114 - data_structure/stk/stack.h | 35 - data_structure/stk/test_stack.cpp | 54 - data_structure/trie_tree.cpp | 90 - data_structures/CMakeLists.txt | 20 + data_structures/avltree.cpp | 148 + data_structures/binary_search_tree.cpp | 174 + data_structures/binaryheap.cpp | 144 + .../circular_queue_using_linked_list.cpp | 42 +- data_structures/cll/CMakeLists.txt | 5 + .../cll/cll.cpp | 65 +- data_structures/cll/cll.h | 43 + data_structures/cll/main_cll.cpp | 43 + data_structures/disjoint_set.cpp | 62 + data_structures/doubly_linked_list.cpp | 136 + data_structures/linked_list.cpp | 134 + .../linkedlist_implentation_usingarray.cpp | 114 + data_structures/list_array.cpp | 153 + data_structures/morrisinorder.cpp | 92 + data_structures/queue.h | 88 + .../queue_using_array.cpp | 3 +- data_structures/queue_using_array2.cpp | 57 + .../queue_using_linked_list.cpp | 49 +- data_structures/queue_using_linkedlist.cpp | 86 + data_structures/stack.h | 111 + data_structures/stack_using_array.cpp | 55 + data_structures/stack_using_linked_list.cpp | 57 + .../stk => data_structures}/student.txt | 0 data_structures/test_queue.cpp | 41 + data_structures/test_stack.cpp | 59 + .../test_stack_students.cpp | 31 +- .../Tree.cpp => data_structures/tree.cpp | 71 +- .../trie_modern.cpp | 9 +- data_structures/trie_tree.cpp | 87 + doc/cppreference-doxygen-web.tag.xml | 35489 ++++++++++++++++ dynamic_programming/0-1 Knapsack.cpp | 71 - dynamic_programming/0_1_knapsack.cpp | 66 + dynamic_programming/Bellman-Ford.cpp | 128 - dynamic_programming/Coin-Change.cpp | 50 - dynamic_programming/Cut Rod.cpp | 28 - dynamic_programming/Fibonacci_Bottom_Up.cpp | 24 - dynamic_programming/Fibonacci_Top_Down.cpp | 26 - dynamic_programming/Floyd-Warshall.cpp | 112 - .../Longest Common Subsequence.cpp | 82 - ...Longest Increasing Subsequence (nlogn).cpp | 46 - .../Longest Increasing Subsequence.cpp | 39 - .../Matrix-Chain-Multiplication.cpp | 62 - dynamic_programming/armstrong_number.cpp | 28 +- dynamic_programming/bellman_ford.cpp | 116 + ...atalan-Numbers.cpp => catalan_numbers.cpp} | 16 +- dynamic_programming/coin_change.cpp | 48 + dynamic_programming/cut_rod.cpp | 25 + .../{Edit Distance.cpp => edit_distance.cpp} | 49 +- ...ing-Puzzle.cpp => egg_dropping_puzzle.cpp} | 31 +- dynamic_programming/fibonacci_bottom_up.cpp | 21 + dynamic_programming/fibonacci_top_down.cpp | 22 + dynamic_programming/floyd_warshall.cpp | 107 + dynamic_programming/kadane.cpp | 5 +- dynamic_programming/longest_common_string.cpp | 82 +- .../longest_common_subsequence.cpp | 65 + .../longest_increasing_subsequence.cpp | 32 + ...longest_increasing_subsequence_(nlogn).cpp | 41 + .../matrix_chain_multiplication.cpp | 61 + .../searching_of_element_in_dynamic_array.cpp | 68 +- dynamic_programming/tree_height.cpp | 26 +- geometry/CMakeLists.txt | 18 + geometry/line_segment_intersection.cpp | 61 +- graph/BFS.cpp | 73 - graph/DFS.cpp | 31 - graph/Kruskal.cpp | 135 - graph/Topological-Sort.cpp | 53 - graph/bfs.cpp | 62 + .../bridge_finding_with_tarjan_algorithm.cpp | 34 +- graph/connected_components.cpp | 49 +- graph/connected_components_with_dsu.cpp | 5 +- graph/cycle_check_directed_graph.cpp | 302 + graph/dfs.cpp | 26 + .../{DFS_with_stack.cc => dfs_with_stack.cpp} | 20 +- graph/{Dijkstra.cpp => dijkstra.cpp} | 33 +- graph/kosaraju.cpp | 165 +- graph/kruskal.cpp | 115 + graph/lca.cpp | 76 +- ...th_ford_fulkerson_and_edmond_karp_algo.cpp | 45 +- graph/prim.cpp | 18 +- graph/topological_sort.cpp | 47 + graph/topological_sort_by_kahns_algo.cpp | 16 +- greedy_algorithms/Knapsack.cpp | 92 - .../Kruskals Minimum Spanning Tree.cpp | 37 - .../Prims Minimum Spanning Tree.cpp | 79 - .../{Dijkstra.cpp => dijkstra.cpp} | 93 +- greedy_algorithms/huffman.cpp | 207 +- greedy_algorithms/knapsack.cpp | 78 + .../kruskals_minimum_spanning_tree.cpp | 31 + .../prims_minimum_spanning_tree.cpp | 64 + hashing/Chaining.cpp | 140 - hashing/chaining.cpp | 116 + hashing/double_hash_hash_table.cpp | 44 +- hashing/linear_probing_hash_table.cpp | 33 +- hashing/quadratic_probing_hash_table.cpp | 47 +- machine_learning/CMakeLists.txt | 18 + machine_learning/adaline_learning.cpp | 351 + machine_learning/kohonen_som_topology.cpp | 595 + machine_learning/kohonen_som_trace.cpp | 474 + math/CMakeLists.txt | 18 + math/README.md | 1 + math/binary_exponent.cpp | 59 +- math/check_prime.cpp | 35 +- math/double_factorial.cpp | 49 +- math/eulers_totient_function.cpp | 65 +- math/extended_euclid_algorithm.cpp | 102 +- math/factorial.cpp | 11 +- math/fast_power.cpp | 74 +- math/fibonacci.cpp | 26 +- math/fibonacci_fast.cpp | 53 + math/fibonacci_large.cpp | 85 + ...lidean.cpp => gcd_iterative_euclidean.cpp} | 18 +- math/gcd_of_n_numbers.cpp | 41 + math/gcd_recursive_euclidean.cpp | 52 + math/greatest_common_divisor.cpp | 27 - math/large_factorial.cpp | 118 + math/large_number.h | 288 + .../modular_inverse_fermat_little_theorem.cpp | 81 +- math/number_of_positive_divisors.cpp | 46 +- math/power_for_huge_numbers.cpp | 147 +- math/prime_factorization.cpp | 73 +- math/prime_numbers.cpp | 15 +- ...p_to_10^8.cpp => primes_up_to_billion.cpp} | 17 +- math/realtime_stats.cpp | 193 + math/sieve_of_eratosthenes.cpp | 74 +- math/sqrt_double.cpp | 50 +- math/string_fibonacci.cpp | 89 + numerical_methods/CMakeLists.txt | 18 + numerical_methods/bisection_method.cpp | 75 + numerical_methods/durand_kerner_roots.cpp | 339 + numerical_methods/false_position.cpp | 74 + numerical_methods/gaussian_elimination.cpp | 76 + numerical_methods/lu_decompose.cpp | 126 + numerical_methods/newton_raphson_method.cpp | 59 + numerical_methods/ode_forward_euler.cpp | 210 + numerical_methods/ode_midpoint_euler.cpp | 214 + numerical_methods/ode_semi_implicit_euler.cpp | 211 + .../ordinary_least_squares_regressor.cpp | 406 + numerical_methods/qr_decompose.h | 210 + numerical_methods/qr_decomposition.cpp | 58 + numerical_methods/qr_eigen_values.cpp | 284 + .../successive_approximation.cpp | 40 + .../Array Left Rotation.cpp | 39 - .../Circular Linked List.cpp | 114 - .../Circular Queue Using Array.cpp | 74 - .../Intersection_of_2_arrays.cpp | 31 - .../Reverse a Linked List using Recusion.cpp | 76 - .../Union_of_2_arrays.cpp | 34 - .../array_left_rotation.cpp | 31 + ... Rotation.cpp => array_right_rotation.cpp} | 22 +- .../circular_linked_list.cpp | 97 + .../circular_queue_using_array.cpp | 57 + .../intersection_of_2_arrays.cpp | 26 + .../reverse_a_linked_list_using_recusion.cpp | 63 + .../selectionSortLinkedList.cpp | 159 - .../selectionsortlinkedlist.cpp | 172 + .../union_of_2_arrays.cpp | 27 + others/Buzz_number.cpp | 17 - others/CMakeLists.txt | 18 + others/Decimal To Binary.cpp | 25 - others/Decimal To Hexadecimal .cpp | 28 - others/GCD_of_n_numbers.cpp | 23 - others/Palindromeofnumber.cpp | 23 - others/Paranthesis Matching.cpp | 76 - others/Primality Test.cpp | 32 - others/Sparse matrix.cpp | 41 - others/Strassen Matrix Multiplication.cpp | 56 - others/String Fibonacci.cpp | 83 - others/Tower of Hanoi.cpp | 73 - others/buzz_number.cpp | 20 + others/decimal_to_binary.cpp | 55 + others/decimal_to_hexadecimal.cpp | 34 + ...meral.cpp => decimal_to_roman_numeral.cpp} | 69 +- others/fast_interger_input.cpp | 20 +- others/fibonacci.cpp | 42 - others/happy_number.cpp | 57 +- others/matrix_exponentiation.cpp | 76 +- others/measure_time_elapsed.cpp | 19 - others/palindrome_of_number.cpp | 35 + others/paranthesis_matching.cpp | 75 + others/pascal_triangle.cpp | 128 +- others/primality_test.cpp | 42 + others/sieve_of_Eratosthenes.cpp | 60 - others/smallest-circle.cpp | 121 - others/smallest_circle.cpp | 205 + others/sparse_matrix.cpp | 48 + others/spiral_print.cpp | 83 +- others/stairs_pattern.cpp | 60 +- others/tower_of_hanoi.cpp | 85 + others/vector_important_functions.cpp | 60 +- probability/CMakeLists.txt | 18 + probability/addition_rule.cpp | 30 +- probability/bayes_theorem.cpp | 26 +- probability/binomial_dist.cpp | 107 +- probability/poisson_dist.cpp | 61 +- range_queries/MO.cpp | 77 - range_queries/bit.cpp | 52 +- .../{FenwickTree.cpp => fenwicktree.cpp} | 20 +- range_queries/mo.cpp | 64 + range_queries/segTree.cpp | 92 - range_queries/segtree.cpp | 79 + search/CMakeLists.txt | 18 + search/Interpolation Search.cpp | 31 - search/Linear Search.cpp | 47 - search/binary_search.cpp | 58 +- search/exponential_search.cpp | 126 +- search/hash_search.cpp | 147 +- search/interpolation_search.cpp | 91 +- search/interpolation_search2.cpp | 46 + search/jump_search.cpp | 39 +- search/linear_search.cpp | 53 + search/median_search.cpp | 126 +- search/searching.cpp | 40 - search/ternary_search.cpp | 206 +- search/text_search.cpp | 42 + sorting/BeadSort.cpp | 63 - sorting/BitonicSort.cpp | 76 - sorting/Bubble Sort.cpp | 83 - sorting/CMakeLists.txt | 20 + sorting/CocktailSelectionSort.cpp | 109 - sorting/Counting_Sort.cpp | 66 - sorting/Insertion Sort.cpp | 40 - sorting/Merge Sort.cpp | 93 - sorting/NumericStringSort.cpp | 62 - sorting/OddEven Sort.cpp | 61 - sorting/Radix Sort.cpp | 68 - sorting/Selection Sort.cpp | 39 - sorting/Shell Sort.cpp | 45 - sorting/Slow Sort.cpp | 57 - sorting/bead_sort.cpp | 56 + sorting/bitonic_sort.cpp | 64 + sorting/bubble_sort.cpp | 83 + sorting/bucketSort.cpp | 42 - sorting/bucket_sort.cpp | 36 + sorting/cocktail_selection_sort.cpp | 102 + sorting/comb_sort.cpp | 49 + sorting/combsort.cpp | 59 - sorting/counting_sort.cpp | 57 + ...ortString.cpp => counting_sort_string.cpp} | 22 +- sorting/doxy.txt | 374 - sorting/insertion_sort.cpp | 36 + sorting/library_sort.cpp | 6 +- sorting/makefile | 11 - sorting/merge_sort.cpp | 81 + sorting/non_recursive_merge_sort.cpp | 65 +- sorting/numeric_string_sort.cpp | 55 + sorting/odd_even_sort.cpp | 53 + sorting/quick_sort.cpp | 57 +- sorting/radix_sort.cpp | 58 + sorting/selection_sort.cpp | 33 + sorting/shell_sort.cpp | 37 + sorting/shell_sort2.cpp | 234 + sorting/slow_sort.cpp | 56 + sorting/swap_sort.cpp | 4 +- sorting/{Tim Sort.cpp => tim_sort.cpp} | 110 +- strings/CMakeLists.txt | 18 + strings/brute_force_string_searching.cpp | 91 +- strings/knuth_morris_pratt.cpp | 127 +- strings/rabin_karp.cpp | 113 +- 313 files changed, 49346 insertions(+), 9847 deletions(-) create mode 100644 .github/workflows/awesome_forkflow.yml delete mode 100644 .github/workflows/cpplint.yml delete mode 100644 .github/workflows/cpplint_modified_files.yml create mode 100644 .github/workflows/gh-pages.yml delete mode 100644 .github/workflows/sorting_non_recursive_merge_sort.yml delete mode 100644 .github/workflows/update_directory_md.yml create mode 100644 .gitpod.dockerfile create mode 100644 .gitpod.yml create mode 100644 CMakeLists.txt rename CONTRIBUTION.md => CONTRIBUTING.md (100%) delete mode 100644 computer_oriented_statistical_methods/Bisection_method.CPP delete mode 100644 computer_oriented_statistical_methods/Gaussian_elimination.cpp delete mode 100644 computer_oriented_statistical_methods/Newton_Raphson.CPP delete mode 100644 computer_oriented_statistical_methods/Secant_method.CPP delete mode 100644 computer_oriented_statistical_methods/false-position.cpp delete mode 100644 computer_oriented_statistical_methods/ordinary_least_squares_regressor.cpp delete mode 100644 computer_oriented_statistical_methods/successive_approximation.CPP delete mode 100644 data_structure/AVLtree.cpp delete mode 100644 data_structure/Binary Search Tree.cpp delete mode 100644 data_structure/Binaryheap.cpp delete mode 100644 data_structure/List Array.cpp delete mode 100644 data_structure/MorrisInorder.cpp delete mode 100644 data_structure/Queue Using Array.cpp delete mode 100644 data_structure/Stack Using Array.cpp delete mode 100644 data_structure/Stack Using Linked List.cpp delete mode 100644 data_structure/cll/cll.h delete mode 100644 data_structure/cll/main_cll.cpp delete mode 100644 data_structure/cll/makefile delete mode 100644 data_structure/disjoint_set.cpp delete mode 100644 data_structure/doubly_linked_list.cpp delete mode 100644 data_structure/linkedList_implentation_usingArray.cpp delete mode 100644 data_structure/linked_list.cpp delete mode 100644 data_structure/queue/makefile delete mode 100644 data_structure/queue/queue.cpp delete mode 100644 data_structure/queue/queue.h delete mode 100644 data_structure/queue/test_queue.cpp delete mode 100644 data_structure/queue_using_linkedlist.cpp delete mode 100644 data_structure/stk/makefile delete mode 100644 data_structure/stk/stack.cpp delete mode 100644 data_structure/stk/stack.h delete mode 100644 data_structure/stk/test_stack.cpp delete mode 100644 data_structure/trie_tree.cpp create mode 100644 data_structures/CMakeLists.txt create mode 100644 data_structures/avltree.cpp create mode 100644 data_structures/binary_search_tree.cpp create mode 100644 data_structures/binaryheap.cpp rename data_structure/circular_Queue_using_Linked_List.cpp => data_structures/circular_queue_using_linked_list.cpp (70%) create mode 100644 data_structures/cll/CMakeLists.txt rename {data_structure => data_structures}/cll/cll.cpp (68%) create mode 100644 data_structures/cll/cll.h create mode 100644 data_structures/cll/main_cll.cpp create mode 100644 data_structures/disjoint_set.cpp create mode 100644 data_structures/doubly_linked_list.cpp create mode 100644 data_structures/linked_list.cpp create mode 100644 data_structures/linkedlist_implentation_usingarray.cpp create mode 100644 data_structures/list_array.cpp create mode 100644 data_structures/morrisinorder.cpp create mode 100644 data_structures/queue.h rename {data_structure => data_structures}/queue_using_array.cpp (95%) create mode 100644 data_structures/queue_using_array2.cpp rename data_structure/Queue Using Linked List.cpp => data_structures/queue_using_linked_list.cpp (69%) create mode 100644 data_structures/queue_using_linkedlist.cpp create mode 100644 data_structures/stack.h create mode 100644 data_structures/stack_using_array.cpp create mode 100644 data_structures/stack_using_linked_list.cpp rename {data_structure/stk => data_structures}/student.txt (100%) create mode 100644 data_structures/test_queue.cpp create mode 100644 data_structures/test_stack.cpp rename data_structure/stk/main.cpp => data_structures/test_stack_students.cpp (67%) rename data_structure/Tree.cpp => data_structures/tree.cpp (72%) rename {data_structure => data_structures}/trie_modern.cpp (96%) create mode 100644 data_structures/trie_tree.cpp create mode 100644 doc/cppreference-doxygen-web.tag.xml delete mode 100644 dynamic_programming/0-1 Knapsack.cpp create mode 100644 dynamic_programming/0_1_knapsack.cpp delete mode 100644 dynamic_programming/Bellman-Ford.cpp delete mode 100644 dynamic_programming/Coin-Change.cpp delete mode 100644 dynamic_programming/Cut Rod.cpp delete mode 100644 dynamic_programming/Fibonacci_Bottom_Up.cpp delete mode 100644 dynamic_programming/Fibonacci_Top_Down.cpp delete mode 100644 dynamic_programming/Floyd-Warshall.cpp delete mode 100644 dynamic_programming/Longest Common Subsequence.cpp delete mode 100644 dynamic_programming/Longest Increasing Subsequence (nlogn).cpp delete mode 100644 dynamic_programming/Longest Increasing Subsequence.cpp delete mode 100644 dynamic_programming/Matrix-Chain-Multiplication.cpp create mode 100644 dynamic_programming/bellman_ford.cpp rename dynamic_programming/{Catalan-Numbers.cpp => catalan_numbers.cpp} (85%) create mode 100644 dynamic_programming/coin_change.cpp create mode 100644 dynamic_programming/cut_rod.cpp rename dynamic_programming/{Edit Distance.cpp => edit_distance.cpp} (60%) rename dynamic_programming/{Egg-Dropping-Puzzle.cpp => egg_dropping_puzzle.cpp} (63%) create mode 100644 dynamic_programming/fibonacci_bottom_up.cpp create mode 100644 dynamic_programming/fibonacci_top_down.cpp create mode 100644 dynamic_programming/floyd_warshall.cpp create mode 100644 dynamic_programming/longest_common_subsequence.cpp create mode 100644 dynamic_programming/longest_increasing_subsequence.cpp create mode 100644 dynamic_programming/longest_increasing_subsequence_(nlogn).cpp create mode 100644 dynamic_programming/matrix_chain_multiplication.cpp create mode 100644 geometry/CMakeLists.txt delete mode 100644 graph/BFS.cpp delete mode 100644 graph/DFS.cpp delete mode 100644 graph/Kruskal.cpp delete mode 100644 graph/Topological-Sort.cpp create mode 100644 graph/bfs.cpp create mode 100644 graph/cycle_check_directed_graph.cpp create mode 100644 graph/dfs.cpp rename graph/{DFS_with_stack.cc => dfs_with_stack.cpp} (74%) rename graph/{Dijkstra.cpp => dijkstra.cpp} (67%) create mode 100644 graph/kruskal.cpp create mode 100644 graph/topological_sort.cpp delete mode 100644 greedy_algorithms/Knapsack.cpp delete mode 100644 greedy_algorithms/Kruskals Minimum Spanning Tree.cpp delete mode 100644 greedy_algorithms/Prims Minimum Spanning Tree.cpp rename greedy_algorithms/{Dijkstra.cpp => dijkstra.cpp} (53%) create mode 100644 greedy_algorithms/knapsack.cpp create mode 100644 greedy_algorithms/kruskals_minimum_spanning_tree.cpp create mode 100644 greedy_algorithms/prims_minimum_spanning_tree.cpp delete mode 100644 hashing/Chaining.cpp create mode 100644 hashing/chaining.cpp create mode 100644 machine_learning/CMakeLists.txt create mode 100644 machine_learning/adaline_learning.cpp create mode 100644 machine_learning/kohonen_som_topology.cpp create mode 100644 machine_learning/kohonen_som_trace.cpp create mode 100644 math/CMakeLists.txt create mode 100644 math/fibonacci_fast.cpp create mode 100644 math/fibonacci_large.cpp rename math/{greatest_common_divisor_euclidean.cpp => gcd_iterative_euclidean.cpp} (79%) create mode 100644 math/gcd_of_n_numbers.cpp create mode 100644 math/gcd_recursive_euclidean.cpp delete mode 100644 math/greatest_common_divisor.cpp create mode 100644 math/large_factorial.cpp create mode 100644 math/large_number.h rename math/{primes_up_to_10^8.cpp => primes_up_to_billion.cpp} (59%) create mode 100644 math/realtime_stats.cpp create mode 100644 math/string_fibonacci.cpp create mode 100644 numerical_methods/CMakeLists.txt create mode 100644 numerical_methods/bisection_method.cpp create mode 100644 numerical_methods/durand_kerner_roots.cpp create mode 100644 numerical_methods/false_position.cpp create mode 100644 numerical_methods/gaussian_elimination.cpp create mode 100644 numerical_methods/lu_decompose.cpp create mode 100644 numerical_methods/newton_raphson_method.cpp create mode 100644 numerical_methods/ode_forward_euler.cpp create mode 100644 numerical_methods/ode_midpoint_euler.cpp create mode 100644 numerical_methods/ode_semi_implicit_euler.cpp create mode 100644 numerical_methods/ordinary_least_squares_regressor.cpp create mode 100644 numerical_methods/qr_decompose.h create mode 100644 numerical_methods/qr_decomposition.cpp create mode 100644 numerical_methods/qr_eigen_values.cpp create mode 100644 numerical_methods/successive_approximation.cpp delete mode 100644 operations_on_datastructures/Array Left Rotation.cpp delete mode 100644 operations_on_datastructures/Circular Linked List.cpp delete mode 100644 operations_on_datastructures/Circular Queue Using Array.cpp delete mode 100644 operations_on_datastructures/Intersection_of_2_arrays.cpp delete mode 100644 operations_on_datastructures/Reverse a Linked List using Recusion.cpp delete mode 100644 operations_on_datastructures/Union_of_2_arrays.cpp create mode 100644 operations_on_datastructures/array_left_rotation.cpp rename operations_on_datastructures/{Array Right Rotation.cpp => array_right_rotation.cpp} (62%) create mode 100644 operations_on_datastructures/circular_linked_list.cpp create mode 100644 operations_on_datastructures/circular_queue_using_array.cpp create mode 100644 operations_on_datastructures/intersection_of_2_arrays.cpp create mode 100644 operations_on_datastructures/reverse_a_linked_list_using_recusion.cpp delete mode 100644 operations_on_datastructures/selectionSortLinkedList.cpp create mode 100644 operations_on_datastructures/selectionsortlinkedlist.cpp create mode 100644 operations_on_datastructures/union_of_2_arrays.cpp delete mode 100644 others/Buzz_number.cpp create mode 100644 others/CMakeLists.txt delete mode 100644 others/Decimal To Binary.cpp delete mode 100644 others/Decimal To Hexadecimal .cpp delete mode 100644 others/GCD_of_n_numbers.cpp delete mode 100644 others/Palindromeofnumber.cpp delete mode 100644 others/Paranthesis Matching.cpp delete mode 100644 others/Primality Test.cpp delete mode 100644 others/Sparse matrix.cpp delete mode 100644 others/Strassen Matrix Multiplication.cpp delete mode 100644 others/String Fibonacci.cpp delete mode 100644 others/Tower of Hanoi.cpp create mode 100644 others/buzz_number.cpp create mode 100644 others/decimal_to_binary.cpp create mode 100644 others/decimal_to_hexadecimal.cpp rename others/{Decimal to Roman Numeral.cpp => decimal_to_roman_numeral.cpp} (54%) delete mode 100644 others/fibonacci.cpp delete mode 100644 others/measure_time_elapsed.cpp create mode 100644 others/palindrome_of_number.cpp create mode 100644 others/paranthesis_matching.cpp create mode 100644 others/primality_test.cpp delete mode 100644 others/sieve_of_Eratosthenes.cpp delete mode 100644 others/smallest-circle.cpp create mode 100644 others/smallest_circle.cpp create mode 100644 others/sparse_matrix.cpp create mode 100644 others/tower_of_hanoi.cpp create mode 100644 probability/CMakeLists.txt delete mode 100644 range_queries/MO.cpp rename range_queries/{FenwickTree.cpp => fenwicktree.cpp} (70%) create mode 100644 range_queries/mo.cpp delete mode 100644 range_queries/segTree.cpp create mode 100644 range_queries/segtree.cpp create mode 100644 search/CMakeLists.txt delete mode 100644 search/Interpolation Search.cpp delete mode 100644 search/Linear Search.cpp create mode 100644 search/interpolation_search2.cpp create mode 100644 search/linear_search.cpp delete mode 100644 search/searching.cpp create mode 100644 search/text_search.cpp delete mode 100644 sorting/BeadSort.cpp delete mode 100644 sorting/BitonicSort.cpp delete mode 100644 sorting/Bubble Sort.cpp create mode 100644 sorting/CMakeLists.txt delete mode 100644 sorting/CocktailSelectionSort.cpp delete mode 100644 sorting/Counting_Sort.cpp delete mode 100644 sorting/Insertion Sort.cpp delete mode 100644 sorting/Merge Sort.cpp delete mode 100644 sorting/NumericStringSort.cpp delete mode 100644 sorting/OddEven Sort.cpp delete mode 100644 sorting/Radix Sort.cpp delete mode 100644 sorting/Selection Sort.cpp delete mode 100644 sorting/Shell Sort.cpp delete mode 100644 sorting/Slow Sort.cpp create mode 100644 sorting/bead_sort.cpp create mode 100644 sorting/bitonic_sort.cpp create mode 100644 sorting/bubble_sort.cpp delete mode 100644 sorting/bucketSort.cpp create mode 100644 sorting/bucket_sort.cpp create mode 100644 sorting/cocktail_selection_sort.cpp create mode 100644 sorting/comb_sort.cpp delete mode 100644 sorting/combsort.cpp create mode 100644 sorting/counting_sort.cpp rename sorting/{CountingSortString.cpp => counting_sort_string.cpp} (50%) delete mode 100644 sorting/doxy.txt create mode 100644 sorting/insertion_sort.cpp delete mode 100644 sorting/makefile create mode 100644 sorting/merge_sort.cpp create mode 100644 sorting/numeric_string_sort.cpp create mode 100644 sorting/odd_even_sort.cpp create mode 100644 sorting/radix_sort.cpp create mode 100644 sorting/selection_sort.cpp create mode 100644 sorting/shell_sort.cpp create mode 100644 sorting/shell_sort2.cpp create mode 100644 sorting/slow_sort.cpp rename sorting/{Tim Sort.cpp => tim_sort.cpp} (55%) create mode 100644 strings/CMakeLists.txt diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index efaaf3765d4..f8135639907 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -3,19 +3,19 @@ Thank you for your Pull Request. Please provide a description above and review the requirements below. -Contributors guide: https://github.com/TheAlgorithms/C-Plus-Plus/CONTRIBUTION.md +Contributors guide: https://github.com/TheAlgorithms/C-Plus-Plus/CONTRIBUTING.md --> #### Checklist - [ ] Added description of change -- [ ] Added file name matches [File name guidelines](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/CONTRIBUTION.md#New-File-Name-guidelines) +- [ ] Added file name matches [File name guidelines](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/CONTRIBUTING.md#New-File-Name-guidelines) - [ ] Added tests and example, test must pass +- [ ] Added documentation so that the program is self-explanatory and educational - [Doxygen guidelines](https://www.doxygen.nl/manual/docblocks.html) - [ ] Relevant documentation/comments is changed or added -- [ ] PR title follows semantic [commit guidelines](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/CONTRIBUTION.md#Commit-Guidelines) +- [ ] PR title follows semantic [commit guidelines](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/CONTRIBUTING.md#Commit-Guidelines) - [ ] Search previous suggestions before making a new one, as yours may be a duplicate. -- [ ] Sort by alphabetical order - [ ] I acknowledge that all my contributions will be made under the project's license. Notes: \ No newline at end of file diff --git a/.github/workflows/awesome_forkflow.yml b/.github/workflows/awesome_forkflow.yml new file mode 100644 index 00000000000..93b630d056d --- /dev/null +++ b/.github/workflows/awesome_forkflow.yml @@ -0,0 +1,211 @@ +name: Awesome CI Workflow + +on: [push] +# push: +# branches: [ master ] +# pull_request: +# branches: [ master ] + +jobs: + code_format: + name: Code Formatter + runs-on: ubuntu-latest + steps: + - name: requirements + run: | + sudo apt -qq -y update + sudo apt -qq install clang-format + - uses: actions/checkout@master + with: + submodules: true + - name: Setup Git Specs + run: | + git config --global user.name github-actions + git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com' + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY + - name: Filename Formatter + run: | + IFS=$'\n' + for fname in `find . -type f -name '*.cpp' -o -name '*.cc' -o -name '*.h'` + do + echo "${fname}" + new_fname=`echo ${fname} | tr ' ' '_'` + echo " ${new_fname}" + new_fname=`echo ${new_fname} | tr 'A-Z' 'a-z'` + echo " ${new_fname}" + new_fname=`echo ${new_fname} | tr '-' '_'` + echo " ${new_fname}" + new_fname=${new_fname/.cc/.cpp} + echo " ${new_fname}" + if [ ${fname} != ${new_fname} ] + then + echo " ${fname} --> ${new_fname}" + git "mv" "${fname}" ${new_fname} + fi + done + git commit -am "formatting filenames $GITHUB_SHA" || true + - name: Clang Formatter + run: | + for fname in $(find . -name '*.cpp' -o -name '*.h') + do + clang-format --verbose -i --style="$line1 $line2 $line3 $line4" "$fname" + done + git commit -am "formatting source-code for $GITHUB_SHA" || true + env: + line1: "{ BasedOnStyle: Google, UseTab: Never," + line2: "IndentWidth: 4, TabWidth: 4, " + line3: "AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false," + line4: "ColumnLimit: 80, AccessModifierOffset: -3 }" + - name: Git Push + run: git push --force origin HEAD:$GITHUB_REF || true + + update_directory_md: + name: Update Directory.md + needs: code_format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v1 + - name: pull latest commit + run: git pull + - name: Update DIRECTORY.md + shell: python + run: | + import os + from typing import Iterator + + URL_BASE = "https://github.com/TheAlgorithms/C-Plus-Plus/blob/master" + g_output = [] + + def good_filepaths(top_dir: str = ".") -> Iterator[str]: + cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split()) + for dirpath, dirnames, filenames in os.walk(top_dir): + dirnames[:] = [d for d in dirnames if d[0] not in "._"] + for filename in filenames: + if os.path.splitext(filename)[1].lower() in cpp_exts: + yield os.path.join(dirpath, filename).lstrip("./") + + def md_prefix(i): + return f"{i * ' '}*" if i else "\n##" + + def print_path(old_path: str, new_path: str) -> str: + global g_output + old_parts = old_path.split(os.sep) + for i, new_part in enumerate(new_path.split(os.sep)): + if i + 1 > len(old_parts) or old_parts[i] != new_part: + if new_part: + g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}") + return new_path + + def build_directory_md(top_dir: str = ".") -> str: + global g_output + old_path = "" + for filepath in sorted(good_filepaths(), key=str.lower): + filepath, filename = os.path.split(filepath) + if filepath != old_path: + old_path = print_path(old_path, filepath) + indent = (filepath.count(os.sep) + 1) if filepath else 0 + url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20") + filename = os.path.splitext(filename.replace("_", " ").title())[0] + g_output.append(f"{md_prefix(indent)} [{filename}]({url})") + return "# List of all files\n" + "\n".join(g_output) + + with open("DIRECTORY.md", "w") as out_file: + out_file.write(build_directory_md(".") + "\n") + - name: Update DIRECTORY.md + run: | + cat DIRECTORY.md + git config --global user.name github-actions + git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com' + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY + git add DIRECTORY.md + git commit -am "updating DIRECTORY.md" || true + git push --force origin HEAD:$GITHUB_REF || true + + # cpplint: + # name: CPPLINT + # needs: code_format + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@master + # - uses: actions/setup-python@master + # - run: pip install cpplint + # - run: git pull + # - run: cpplint --filter=-legal --recursive . + + cpplint_modified_files: + runs-on: ubuntu-latest + needs: code_format + name: CPPLINT + steps: + - uses: actions/checkout@master # v2 is broken for git diff + - uses: actions/setup-python@master + - run: python -m pip install cpplint + - run: git remote -v + - run: git branch + - run: git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY + - run: git pull + - run: git diff --diff-filter=dr --name-only origin/master > git_diff.txt + - run: echo "Files changed-- `cat git_diff.txt`" + - name: cpplint_modified_files + shell: python + run: | + 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(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split()) + cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)] + print(f"{len(cpp_files)} C++ files were modified.") + if not cpp_files: + sys.exit(0) + + print("cpplint:") + for cpp_file in cpp_files: + subprocess.run(["cpplint", "--filter=-legal/copyright,-build/include", cpp_file], check=True, text=True) + + # print("g++:") + # compile_exts = tuple(".c .c++ .cc .cpp .cu .cxx".split()) + # compile_files = [file for file in cpp_files if file.lower().endswith(compile_exts)] + # for cpp_file in cpp_files: + # subprocess.run(["g++", cpp_file], check=True, text=True) + + upper_files = [file for file in cpp_files if file != file.lower()] + if upper_files: + print(f"{len(upper_files)} files contain uppercase characters:") + print("\n".join(upper_files) + "\n") + + space_files = [file for file in cpp_files if " " in file or "-" in file] + if space_files: + print(f"{len(space_files)} files contain space or dash characters:") + print("\n".join(space_files) + "\n") + + nodir_files = [file for file in cpp_files if file.count(os.sep) != 1] + if nodir_files: + print(f"{len(nodir_files)} files are not in one and only one directory:") + print("\n".join(nodir_files) + "\n") + + bad_files = len(upper_files + space_files + nodir_files) + if bad_files: + sys.exit(bad_files) + + build: + name: Compile checks + runs-on: ${{ matrix.os }} + # needs: [cpplint, update_directory_md, cpplint_modified_files] + needs: [update_directory_md] + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + steps: + - uses: actions/checkout@master + with: + submodules: true + - run: git pull + - run: cmake -B ./build -S . + - run: cmake --build build diff --git a/.github/workflows/cpplint.yml b/.github/workflows/cpplint.yml deleted file mode 100644 index a6999e1f25c..00000000000 --- a/.github/workflows/cpplint.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: cpplint -on: [push, pull_request] -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-python@v1 - - run: pip install cpplint - # - run: cpplint --filter= # print out all cpplint rules - - run: cpplint --recursive . || true # all issues to be fixed - # TODO: Remove each filter one at a time and fix those failures - - run: cpplint --filter=-build,-legal,-readability,-runtime,-whitespace --recursive . diff --git a/.github/workflows/cpplint_modified_files.yml b/.github/workflows/cpplint_modified_files.yml deleted file mode 100644 index 07a32ece97d..00000000000 --- a/.github/workflows/cpplint_modified_files.yml +++ /dev/null @@ -1,64 +0,0 @@ -# GitHub Action that enables a repo to achieve gradual compliance with cpplint by -# linting only those files that have been added or modified (vs. origin/master). -# 1. runs cpplint only on those files that have been modified vs. origin/master. -# 2. compiles with g++ only those files that have been modified vs. origin/master. -# 3. other optional filepath verifications may be commented out at the end of this file. -# From: https://github.com/cpplint/GitHub-Action-for-cpplint - -name: cpplint_modified_files -on: [push, pull_request] -jobs: - cpplint_modified_files: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 # v2 is broken for git diff - - uses: actions/setup-python@v1 - - run: python -m pip install cpplint - - run: git remote -v - - run: git branch - - run: git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY - - run: git diff --diff-filter=dr --name-only origin/master > git_diff.txt - - name: cpplint_modified_files - shell: python - run: | - 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(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split()) - cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)] - print(f"{len(cpp_files)} C++ files were modified.") - if not cpp_files: - sys.exit(0) - - print("cpplint:") - subprocess.run(["cpplint", "--filter=-legal/copyright"] + cpp_files, check=True, text=True) - - print("g++:") - # compile_exts = tuple(".c .c++ .cc .cpp .cu .cxx".split()) - # compile_files = [file for file in cpp_files if file.lower().endswith(compile_exts)] - subprocess.run(["g++"] + cpp_files, check=True, text=True) - - upper_files = [file for file in cpp_files if file != file.lower()] - if upper_files: - print(f"{len(upper_files)} files contain uppercase characters:") - print("\n".join(upper_files) + "\n") - - space_files = [file for file in cpp_files if " " in file or "-" in file] - if space_files: - print(f"{len(space_files)} files contain space or dash characters:") - print("\n".join(space_files) + "\n") - - nodir_files = [file for file in cpp_files if file.count(os.sep) != 1] - if nodir_files: - print(f"{len(nodir_files)} files are not in one and only one directory:") - print("\n".join(nodir_files) + "\n") - - bad_files = len(upper_files + space_files + nodir_files) - if bad_files: - sys.exit(bad_files) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml new file mode 100644 index 00000000000..881ea1c3375 --- /dev/null +++ b/.github/workflows/gh-pages.yml @@ -0,0 +1,36 @@ +name: Doxygen CI + +on: + push: + branches: [master] + +jobs: + build: + runs-on: macos-latest + steps: + - uses: actions/checkout@master + with: + submodules: true + - name: Install requirements + run: | + brew install graphviz ninja doxygen + - name: configure + run: cmake -G Ninja -B ./build -S . + - name: build + run: cmake --build build -t doc + - name: gh-pages + uses: actions/checkout@master + with: + ref: "gh-pages" + clean: false + - name: Move & Commit files + run: | + git config --global user.name github-actions + git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com' + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY + rm -rf d* && rm *.html && rm *.svg && rm *.map && rm *.md5 && rm *.png && rm *.js && rm *.css + git add . + cp -rp ./build/html/* . && rm -rf ./build && ls -lah + git add . + git commit -m "Documentation for $GITHUB_SHA" || true + git push --force || true diff --git a/.github/workflows/sorting_non_recursive_merge_sort.yml b/.github/workflows/sorting_non_recursive_merge_sort.yml deleted file mode 100644 index add9efd5d67..00000000000 --- a/.github/workflows/sorting_non_recursive_merge_sort.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: sorting_non_recursive_merge_sort -on: - pull_request: - push: - # branches: [master] -jobs: - sorting_non_recursive_merge_sort: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - uses: mattnotmitt/doxygen-action@master - with: - working-directory: 'sorting/' - doxyfile-path: 'doxy.txt' - #- uses: peaceiris/actions-gh-pages@v3 - # with: - # github_token: ${{ secrets.GITHUB_TOKEN }} - # publish_dir: ./sorting - # external_repository: TheAlgorithms/C-Plus-Plus - # publish_branch: master - # enable_jekyll: true - - run: | - cd sorting - make test diff --git a/.github/workflows/update_directory_md.yml b/.github/workflows/update_directory_md.yml deleted file mode 100644 index 1d63374b0a8..00000000000 --- a/.github/workflows/update_directory_md.yml +++ /dev/null @@ -1,68 +0,0 @@ -# This GitHub Action updates the DIRECTORY.md file (if needed) when doing a git push -name: update_directory_md -on: [push] -jobs: - update_directory_md: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v1 - - name: update_directory_md - shell: python - run: | - import os - from typing import Iterator - - URL_BASE = "https://github.com/TheAlgorithms/C-Plus-Plus/blob/master" - g_output = [] - - - def good_filepaths(top_dir: str = ".") -> Iterator[str]: - cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split()) - for dirpath, dirnames, filenames in os.walk(top_dir): - dirnames[:] = [d for d in dirnames if d[0] not in "._"] - for filename in filenames: - if os.path.splitext(filename)[1].lower() in cpp_exts: - yield os.path.join(dirpath, filename).lstrip("./") - - - def md_prefix(i): - return f"{i * ' '}*" if i else "\n##" - - - def print_path(old_path: str, new_path: str) -> str: - global g_output - old_parts = old_path.split(os.sep) - for i, new_part in enumerate(new_path.split(os.sep)): - if i + 1 > len(old_parts) or old_parts[i] != new_part: - if new_part: - g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}") - return new_path - - - def build_directory_md(top_dir: str = ".") -> str: - global g_output - old_path = "" - for filepath in sorted(good_filepaths(), key=str.lower): - filepath, filename = os.path.split(filepath) - if filepath != old_path: - old_path = print_path(old_path, filepath) - indent = (filepath.count(os.sep) + 1) if filepath else 0 - url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20") - filename = os.path.splitext(filename.replace("_", " ").title())[0] - g_output.append(f"{md_prefix(indent)} [{filename}]({url})") - return "\n".join(g_output) - - - with open("DIRECTORY.md", "w") as out_file: - out_file.write(build_directory_md(".") + "\n") - - - name: Update DIRECTORY.md - run: | - cat DIRECTORY.md - git config --global user.name github-actions - git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com' - git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY - git add DIRECTORY.md - git commit -am "updating DIRECTORY.md" || true - git push --force origin HEAD:$GITHUB_REF || true diff --git a/.gitignore b/.gitignore index ed3934e45be..5275088d0f4 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ a.out *.out *.app + +build/ diff --git a/.gitpod.dockerfile b/.gitpod.dockerfile new file mode 100644 index 00000000000..6d6a4e895f4 --- /dev/null +++ b/.gitpod.dockerfile @@ -0,0 +1,9 @@ +FROM gitpod/workspace-full + +RUN sudo apt-get update \ + && sudo apt-get install -y \ + doxygen \ + graphviz \ + ninja-build \ + && pip install cpplint \ + && sudo rm -rf /var/lib/apt/lists/* diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 00000000000..40750258c2a --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,17 @@ +image: + file: .gitpod.dockerfile + +github: + prebuilds: + addBadge: true + addComment: false + addCheck: false + master: true + pullRequestsFromForks: true + +vscode: + extensions: + - ms-vscode.cpptools@0.28.3:mjRj37VUK0nY2ZeDXzxOJA== + - twxs.cmake@0.0.17:9s7m9CWOr6i6NZ7CNNF4kw== + - ms-vscode.cmake-tools@1.4.0:eP3hU/MFme+CcSL21Klk1w== + - mhutchie.git-graph@1.23.0:TM9ShNmBn94aUJMJusCJlg== diff --git a/.vscode/settings.json b/.vscode/settings.json index 0ab2708d0fd..6d75a13905d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,71 +1,6 @@ { - "files.associations": { - "array": "cpp", - "atomic": "cpp", - "*.tcc": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "cfenv": "cpp", - "chrono": "cpp", - "cinttypes": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "codecvt": "cpp", - "complex": "cpp", - "condition_variable": "cpp", - "csetjmp": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cuchar": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "forward_list": "cpp", - "list": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "vector": "cpp", - "exception": "cpp", - "fstream": "cpp", - "functional": "cpp", - "future": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "memory": "cpp", - "mutex": "cpp", - "new": "cpp", - "numeric": "cpp", - "optional": "cpp", - "ostream": "cpp", - "ratio": "cpp", - "scoped_allocator": "cpp", - "shared_mutex": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "thread": "cpp", - "type_traits": "cpp", - "tuple": "cpp", - "typeindex": "cpp", - "typeinfo": "cpp", - "utility": "cpp", - "valarray": "cpp", - "algorithm": "cpp" - }, - "C_Cpp.clang_format_style": "{BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 80, UseTab: Never}", + "C_Cpp.clang_format_style": "{ BasedOnStyle: Google, UseTab: Never, IndentWidth: 4, TabWidth: 4, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: true, ColumnLimit: 80, AccessModifierOffset: -3 }", "editor.formatOnSave": true, "editor.formatOnType": true, "editor.formatOnPaste": true -} +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000000..957be35f588 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,81 @@ +cmake_minimum_required(VERSION 3.9) +project(Algorithms_in_C++ + LANGUAGES CXX + VERSION 1.0.0 + DESCRIPTION "Set of algorithms implemented in C++." +) + +# set(CMAKE_CXX_CPPLINT "~/anaconda3/bin/cpplint --filter=-legal/copyright --std=c++11") +# find_program(CLANG_FORMAT "clang-format") + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if(MSVC) + # set(CMAKE_CXX_STANDARD 14) + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) +endif(MSVC) + +option(USE_OPENMP "flag to use OpenMP for multithreading" ON) + +cmake_policy(SET CMP0054 NEW) +cmake_policy(SET CMP0057 NEW) +find_package(Doxygen OPTIONAL_COMPONENTS dot dia) +if(DOXYGEN_FOUND) + set(DOXYGEN_GENERATE_MAN NO) + set(DOXYGEN_USE_MATHJAX YES) + set(DOXYGEN_GENERATE_HTML YES) + set(DOXYGEN_HTML_TIMESTAMP YES) + set(DOXYGEN_EXTRACT_STATIC YES) + set(DOXYGEN_INLINE_SOURCES YES) + set(DOXYGEN_CREATE_SUBDIRS YES) + set(DOXYGEN_EXTRACT_PRIVATE YES) + set(DOXYGEN_GENERATE_TREEVIEW YES) + set(DOXYGEN_STRIP_CODE_COMMENTS NO) + set(DOXYGEN_EXT_LINKS_IN_WINDOW YES) + set(DOXYGEN_BUILTIN_STL_SUPPORT YES) + set(DOXYGEN_CLANG_ASSISTED_PARSING YES) + set(DOXYGEN_FILE_PATTERNS *.cpp *.h *.hpp *.md) + set(DOXYGEN_MATHJAX_EXTENSIONS TeX/AMSmath TeX/AMSsymbols) + set(DOXYGEN_TAGFILES "doc/cppreference-doxygen-web.tag.xml=http://en.cppreference.com/w/") + if(MSVC) + set(DOXYGEN_CPP_CLI_SUPPORT YES) + endif() + set(DOXYGEN_MATHJAX_RELPATH "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML") + if(Doxygen_dot_FOUND) + set(DOXYGEN_HAVE_DOT YES) + set(DOXYGEN_CALL_GRAPH YES) + set(DOXYGEN_INTERACTIVE_SVG YES) + set(DOXYGEN_DOT_IMAGE_FORMAT "svg") + endif() + + doxygen_add_docs( + doc + ${PROJECT_SOURCE_DIR} + COMMENT "Generate documentation" + ) +endif() + +if(USE_OPENMP) + find_package(OpenMP) + if (OpenMP_CXX_FOUND) + message(STATUS "Building with OpenMP Multithreading.") + else() + message(STATUS "No OpenMP found, no multithreading.") + endif() +endif() + +add_subdirectory(math) +add_subdirectory(others) +add_subdirectory(search) +add_subdirectory(strings) +add_subdirectory(sorting) +add_subdirectory(geometry) +add_subdirectory(probability) +add_subdirectory(data_structures) +add_subdirectory(machine_learning) +add_subdirectory(numerical_methods) + +set(CPACK_PROJECT_NAME ${PROJECT_NAME}) +set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) +include(CPack) diff --git a/CONTRIBUTION.md b/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTION.md rename to CONTRIBUTING.md diff --git a/DIRECTORY.md b/DIRECTORY.md index 1575561b88d..071ee8b9594 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -1,3 +1,4 @@ +# List of all files ## Backtracking * [Graph Coloring](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/backtracking/graph_coloring.cpp) @@ -9,67 +10,54 @@ * [Rat Maze](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/backtracking/rat_maze.cpp) * [Sudoku Solve](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/backtracking/sudoku_solve.cpp) -## Computer Oriented Statistical Methods - * [Bisection Method](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/computer_oriented_statistical_methods/Bisection_method.CPP) - * [False-Position](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/computer_oriented_statistical_methods/false-position.cpp) - * [Gaussian Elimination](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/computer_oriented_statistical_methods/Gaussian_elimination.cpp) - * [Newton Raphson](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/computer_oriented_statistical_methods/Newton_Raphson.CPP) - * [Ordinary Least Squares Regressor](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/computer_oriented_statistical_methods/ordinary_least_squares_regressor.cpp) - * [Secant Method](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/computer_oriented_statistical_methods/Secant_method.CPP) - * [Successive Approximation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/computer_oriented_statistical_methods/successive_approximation.CPP) - -## Data Structure - * [Avltree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/AVLtree.cpp) - * [Binary Search Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/Binary%20Search%20Tree.cpp) - * [Binaryheap](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/Binaryheap.cpp) - * [Circular Queue Using Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/circular_Queue_using_Linked_List.cpp) +## Data Structures + * [Avltree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/avltree.cpp) + * [Binary Search Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/binary_search_tree.cpp) + * [Binaryheap](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/binaryheap.cpp) + * [Circular Queue Using Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/circular_queue_using_linked_list.cpp) * Cll - * [Cll](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/cll/cll.cpp) - * [Cll](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/cll/cll.h) - * [Main Cll](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/cll/main_cll.cpp) - * [Disjoint Set](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/disjoint_set.cpp) - * [Doubly Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/doubly_linked_list.cpp) - * [Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/linked_list.cpp) - * [Linkedlist Implentation Usingarray](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/linkedList_implentation_usingArray.cpp) - * [List Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/List%20Array.cpp) - * [Morrisinorder](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/MorrisInorder.cpp) - * [Queue Using Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/Queue%20Using%20Array.cpp) - * [Queue Using Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/Queue%20Using%20Linked%20List.cpp) - * Queue - * [Queue](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/queue/queue.cpp) - * [Queue](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/queue/queue.h) - * [Test Queue](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/queue/test_queue.cpp) - * [Queue Using Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/queue_using_array.cpp) - * [Queue Using Linkedlist](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/queue_using_linkedlist.cpp) - * [Stack Using Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/Stack%20Using%20Array.cpp) - * [Stack Using Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/Stack%20Using%20Linked%20List.cpp) - * Stk - * [Main](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/stk/main.cpp) - * [Stack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/stk/stack.cpp) - * [Stack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/stk/stack.h) - * [Test Stack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/stk/test_stack.cpp) - * [Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/Tree.cpp) - * [Trie Modern](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/trie_modern.cpp) - * [Trie Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structure/trie_tree.cpp) + * [Cll](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/cll/cll.cpp) + * [Cll](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/cll/cll.h) + * [Main Cll](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/cll/main_cll.cpp) + * [Disjoint Set](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/disjoint_set.cpp) + * [Doubly Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/doubly_linked_list.cpp) + * [Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/linked_list.cpp) + * [Linkedlist Implentation Usingarray](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/linkedlist_implentation_usingarray.cpp) + * [List Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/list_array.cpp) + * [Morrisinorder](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/morrisinorder.cpp) + * [Queue](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue.h) + * [Queue Using Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue_using_array.cpp) + * [Queue Using Array2](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue_using_array2.cpp) + * [Queue Using Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue_using_linked_list.cpp) + * [Queue Using Linkedlist](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue_using_linkedlist.cpp) + * [Stack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/stack.h) + * [Stack Using Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/stack_using_array.cpp) + * [Stack Using Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/stack_using_linked_list.cpp) + * [Test Queue](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/test_queue.cpp) + * [Test Stack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/test_stack.cpp) + * [Test Stack Students](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/test_stack_students.cpp) + * [Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/tree.cpp) + * [Trie Modern](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/trie_modern.cpp) + * [Trie Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/trie_tree.cpp) ## Dynamic Programming - * [0-1 Knapsack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/0-1%20Knapsack.cpp) + * [0 1 Knapsack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/0_1_knapsack.cpp) * [Armstrong Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/armstrong_number.cpp) - * [Bellman-Ford](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Bellman-Ford.cpp) - * [Catalan-Numbers](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Catalan-Numbers.cpp) - * [Coin-Change](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Coin-Change.cpp) - * [Cut Rod](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Cut%20Rod.cpp) - * [Edit Distance](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Edit%20Distance.cpp) - * [Egg-Dropping-Puzzle](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Egg-Dropping-Puzzle.cpp) - * [Fibonacci Bottom Up](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Fibonacci_Bottom_Up.cpp) - * [Fibonacci Top Down](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Fibonacci_Top_Down.cpp) - * [Floyd-Warshall](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Floyd-Warshall.cpp) + * [Bellman Ford](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/bellman_ford.cpp) + * [Catalan Numbers](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/catalan_numbers.cpp) + * [Coin Change](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/coin_change.cpp) + * [Cut Rod](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/cut_rod.cpp) + * [Edit Distance](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/edit_distance.cpp) + * [Egg Dropping Puzzle](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/egg_dropping_puzzle.cpp) + * [Fibonacci Bottom Up](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/fibonacci_bottom_up.cpp) + * [Fibonacci Top Down](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/fibonacci_top_down.cpp) + * [Floyd Warshall](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/floyd_warshall.cpp) * [Kadane](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/kadane.cpp) - * [Longest Common Subsequence](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Longest%20Common%20Subsequence.cpp) - * [Longest Increasing Subsequence (Nlogn)](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Longest%20Increasing%20Subsequence%20(nlogn).cpp) - * [Longest Increasing Subsequence](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Longest%20Increasing%20Subsequence.cpp) * [Longest Common String](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/longest_common_string.cpp) - * [Matrix-Chain-Multiplication](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/Matrix-Chain-Multiplication.cpp) + * [Longest Common Subsequence](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/longest_common_subsequence.cpp) + * [Longest Increasing Subsequence](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/longest_increasing_subsequence.cpp) + * [Longest Increasing Subsequence (Nlogn)](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/longest_increasing_subsequence_(nlogn).cpp) + * [Matrix Chain Multiplication](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/matrix_chain_multiplication.cpp) * [Searching Of Element In Dynamic Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/searching_of_element_in_dynamic_array.cpp) * [Tree Height](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/tree_height.cpp) @@ -77,34 +65,40 @@ * [Line Segment Intersection](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/geometry/line_segment_intersection.cpp) ## Graph - * [Bfs](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/BFS.cpp) + * [Bfs](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/bfs.cpp) * [Bridge Finding With Tarjan Algorithm](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/bridge_finding_with_tarjan_algorithm.cpp) * [Connected Components](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/connected_components.cpp) * [Connected Components With Dsu](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/connected_components_with_dsu.cpp) - * [Dfs](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/DFS.cpp) - * [Dfs With Stack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/DFS_with_stack.cc) - * [Dijkstra](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/Dijkstra.cpp) + * [Cycle Check Directed Graph](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/cycle_check_directed_graph.cpp) + * [Dfs](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/dfs.cpp) + * [Dfs With Stack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/dfs_with_stack.cpp) + * [Dijkstra](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/dijkstra.cpp) * [Kosaraju](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/kosaraju.cpp) - * [Kruskal](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/Kruskal.cpp) + * [Kruskal](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/kruskal.cpp) * [Lca](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/lca.cpp) * [Max Flow With Ford Fulkerson And Edmond Karp Algo](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp) * [Prim](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/prim.cpp) - * [Topological-Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/Topological-Sort.cpp) + * [Topological Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/topological_sort.cpp) * [Topological Sort By Kahns Algo](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/graph/topological_sort_by_kahns_algo.cpp) ## Greedy Algorithms - * [Dijkstra](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/greedy_algorithms/Dijkstra.cpp) + * [Dijkstra](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/greedy_algorithms/dijkstra.cpp) * [Huffman](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/greedy_algorithms/huffman.cpp) - * [Knapsack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/greedy_algorithms/Knapsack.cpp) - * [Kruskals Minimum Spanning Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/greedy_algorithms/Kruskals%20Minimum%20Spanning%20Tree.cpp) - * [Prims Minimum Spanning Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/greedy_algorithms/Prims%20Minimum%20Spanning%20Tree.cpp) + * [Knapsack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/greedy_algorithms/knapsack.cpp) + * [Kruskals Minimum Spanning Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/greedy_algorithms/kruskals_minimum_spanning_tree.cpp) + * [Prims Minimum Spanning Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/greedy_algorithms/prims_minimum_spanning_tree.cpp) ## Hashing - * [Chaining](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/hashing/Chaining.cpp) + * [Chaining](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/hashing/chaining.cpp) * [Double Hash Hash Table](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/hashing/double_hash_hash_table.cpp) * [Linear Probing Hash Table](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/hashing/linear_probing_hash_table.cpp) * [Quadratic Probing Hash Table](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/hashing/quadratic_probing_hash_table.cpp) +## Machine Learning + * [Adaline Learning](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/machine_learning/adaline_learning.cpp) + * [Kohonen Som Topology](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/machine_learning/kohonen_som_topology.cpp) + * [Kohonen Som Trace](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/machine_learning/kohonen_som_trace.cpp) + ## Math * [Binary Exponent](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/binary_exponent.cpp) * [Check Prime](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/check_prime.cpp) @@ -114,52 +108,69 @@ * [Factorial](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/factorial.cpp) * [Fast Power](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/fast_power.cpp) * [Fibonacci](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/fibonacci.cpp) - * [Greatest Common Divisor](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/greatest_common_divisor.cpp) - * [Greatest Common Divisor Euclidean](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/greatest_common_divisor_euclidean.cpp) + * [Fibonacci Fast](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/fibonacci_fast.cpp) + * [Fibonacci Large](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/fibonacci_large.cpp) + * [Gcd Iterative Euclidean](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/gcd_iterative_euclidean.cpp) + * [Gcd Of N Numbers](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/gcd_of_n_numbers.cpp) + * [Gcd Recursive Euclidean](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/gcd_recursive_euclidean.cpp) + * [Large Factorial](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/large_factorial.cpp) + * [Large Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/large_number.h) * [Least Common Multiple](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/least_common_multiple.cpp) * [Modular Inverse Fermat Little Theorem](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/modular_inverse_fermat_little_theorem.cpp) * [Number Of Positive Divisors](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/number_of_positive_divisors.cpp) * [Power For Huge Numbers](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/power_for_huge_numbers.cpp) * [Prime Factorization](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/prime_factorization.cpp) * [Prime Numbers](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/prime_numbers.cpp) - * [Primes Up To 10^8](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/primes_up_to_10^8.cpp) + * [Primes Up To Billion](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/primes_up_to_billion.cpp) + * [Realtime Stats](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/realtime_stats.cpp) * [Sieve Of Eratosthenes](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/sieve_of_eratosthenes.cpp) * [Sqrt Double](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/sqrt_double.cpp) + * [String Fibonacci](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/string_fibonacci.cpp) + +## Numerical Methods + * [Bisection Method](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/bisection_method.cpp) + * [Durand Kerner Roots](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/durand_kerner_roots.cpp) + * [False Position](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/false_position.cpp) + * [Gaussian Elimination](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/gaussian_elimination.cpp) + * [Lu Decompose](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/lu_decompose.cpp) + * [Newton Raphson Method](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/newton_raphson_method.cpp) + * [Ode Forward Euler](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/ode_forward_euler.cpp) + * [Ode Midpoint Euler](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/ode_midpoint_euler.cpp) + * [Ode Semi Implicit Euler](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/ode_semi_implicit_euler.cpp) + * [Ordinary Least Squares Regressor](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/ordinary_least_squares_regressor.cpp) + * [Qr Decompose](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/qr_decompose.h) + * [Qr Decomposition](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/qr_decomposition.cpp) + * [Qr Eigen Values](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/qr_eigen_values.cpp) + * [Successive Approximation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/numerical_methods/successive_approximation.cpp) ## Operations On Datastructures - * [Array Left Rotation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/Array%20Left%20Rotation.cpp) - * [Array Right Rotation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/Array%20Right%20Rotation.cpp) - * [Circular Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/Circular%20Linked%20List.cpp) - * [Circular Queue Using Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/Circular%20Queue%20Using%20Array.cpp) + * [Array Left Rotation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/array_left_rotation.cpp) + * [Array Right Rotation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/array_right_rotation.cpp) + * [Circular Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/circular_linked_list.cpp) + * [Circular Queue Using Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/circular_queue_using_array.cpp) * [Get Size Of Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/get_size_of_linked_list.cpp) - * [Intersection Of 2 Arrays](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/Intersection_of_2_arrays.cpp) - * [Reverse A Linked List Using Recusion](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/Reverse%20a%20Linked%20List%20using%20Recusion.cpp) - * [Selectionsortlinkedlist](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/selectionSortLinkedList.cpp) - * [Union Of 2 Arrays](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/Union_of_2_arrays.cpp) + * [Intersection Of 2 Arrays](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/intersection_of_2_arrays.cpp) + * [Reverse A Linked List Using Recusion](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/reverse_a_linked_list_using_recusion.cpp) + * [Selectionsortlinkedlist](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/selectionsortlinkedlist.cpp) + * [Union Of 2 Arrays](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/operations_on_datastructures/union_of_2_arrays.cpp) ## Others - * [Buzz Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/Buzz_number.cpp) - * [Decimal To Binary](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/Decimal%20To%20Binary.cpp) - * [Decimal To Hexadecimal ](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/Decimal%20To%20Hexadecimal%20.cpp) - * [Decimal To Roman Numeral](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/Decimal%20to%20Roman%20Numeral.cpp) + * [Buzz Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/buzz_number.cpp) + * [Decimal To Binary](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/decimal_to_binary.cpp) + * [Decimal To Hexadecimal](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/decimal_to_hexadecimal.cpp) + * [Decimal To Roman Numeral](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/decimal_to_roman_numeral.cpp) * [Fast Interger Input](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/fast_interger_input.cpp) - * [Fibonacci](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/fibonacci.cpp) - * [Gcd Of N Numbers](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/GCD_of_n_numbers.cpp) * [Happy Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/happy_number.cpp) * [Matrix Exponentiation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/matrix_exponentiation.cpp) - * [Measure Time Elapsed](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/measure_time_elapsed.cpp) - * [Palindromeofnumber](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/Palindromeofnumber.cpp) - * [Paranthesis Matching](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/Paranthesis%20Matching.cpp) + * [Palindrome Of Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/palindrome_of_number.cpp) + * [Paranthesis Matching](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/paranthesis_matching.cpp) * [Pascal Triangle](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/pascal_triangle.cpp) - * [Primality Test](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/Primality%20Test.cpp) - * [Sieve Of Eratosthenes](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/sieve_of_Eratosthenes.cpp) - * [Smallest-Circle](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/smallest-circle.cpp) - * [Sparse Matrix](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/Sparse%20matrix.cpp) + * [Primality Test](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/primality_test.cpp) + * [Smallest Circle](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/smallest_circle.cpp) + * [Sparse Matrix](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/sparse_matrix.cpp) * [Spiral Print](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/spiral_print.cpp) * [Stairs Pattern](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/stairs_pattern.cpp) - * [Strassen Matrix Multiplication](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/Strassen%20Matrix%20Multiplication.cpp) - * [String Fibonacci](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/String%20Fibonacci.cpp) - * [Tower Of Hanoi](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/Tower%20of%20Hanoi.cpp) + * [Tower Of Hanoi](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/tower_of_hanoi.cpp) * [Vector Important Functions](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/vector_important_functions.cpp) ## Probability @@ -170,45 +181,46 @@ ## Range Queries * [Bit](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/range_queries/bit.cpp) - * [Fenwicktree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/range_queries/FenwickTree.cpp) - * [Mo](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/range_queries/MO.cpp) - * [Segtree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/range_queries/segTree.cpp) + * [Fenwicktree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/range_queries/fenwicktree.cpp) + * [Mo](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/range_queries/mo.cpp) + * [Segtree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/range_queries/segtree.cpp) ## Search * [Binary Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/binary_search.cpp) * [Exponential Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/exponential_search.cpp) * [Hash Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/hash_search.cpp) - * [Interpolation Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/Interpolation%20Search.cpp) * [Interpolation Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/interpolation_search.cpp) + * [Interpolation Search2](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/interpolation_search2.cpp) * [Jump Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/jump_search.cpp) - * [Linear Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/Linear%20Search.cpp) + * [Linear Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/linear_search.cpp) * [Median Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/median_search.cpp) - * [Searching](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/searching.cpp) * [Ternary Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/ternary_search.cpp) + * [Text Search](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/text_search.cpp) ## Sorting - * [Beadsort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/BeadSort.cpp) - * [Bitonicsort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/BitonicSort.cpp) - * [Bubble Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/Bubble%20Sort.cpp) - * [Bucketsort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/bucketSort.cpp) - * [Cocktailselectionsort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/CocktailSelectionSort.cpp) - * [Combsort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/combsort.cpp) - * [Counting Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/Counting_Sort.cpp) - * [Countingsortstring](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/CountingSortString.cpp) + * [Bead Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/bead_sort.cpp) + * [Bitonic Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/bitonic_sort.cpp) + * [Bubble Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/bubble_sort.cpp) + * [Bucket Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/bucket_sort.cpp) + * [Cocktail Selection Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/cocktail_selection_sort.cpp) + * [Comb Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/comb_sort.cpp) + * [Counting Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/counting_sort.cpp) + * [Counting Sort String](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/counting_sort_string.cpp) * [Heap Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/heap_sort.cpp) - * [Insertion Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/Insertion%20Sort.cpp) + * [Insertion Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/insertion_sort.cpp) * [Library Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/library_sort.cpp) - * [Merge Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/Merge%20Sort.cpp) + * [Merge Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/merge_sort.cpp) * [Non Recursive Merge Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/non_recursive_merge_sort.cpp) - * [Numericstringsort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/NumericStringSort.cpp) - * [Oddeven Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/OddEven%20Sort.cpp) + * [Numeric String Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/numeric_string_sort.cpp) + * [Odd Even Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/odd_even_sort.cpp) * [Quick Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/quick_sort.cpp) - * [Radix Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/Radix%20Sort.cpp) - * [Selection Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/Selection%20Sort.cpp) - * [Shell Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/Shell%20Sort.cpp) - * [Slow Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/Slow%20Sort.cpp) + * [Radix Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/radix_sort.cpp) + * [Selection Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/selection_sort.cpp) + * [Shell Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/shell_sort.cpp) + * [Shell Sort2](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/shell_sort2.cpp) + * [Slow Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/slow_sort.cpp) * [Swap Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/swap_sort.cpp) - * [Tim Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/Tim%20Sort.cpp) + * [Tim Sort](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/tim_sort.cpp) ## Strings * [Brute Force String Searching](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/strings/brute_force_string_searching.cpp) diff --git a/README.md b/README.md index a3077cdc5b8..8734158b7d7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,18 @@ -# The Algorithms - C++ -[![contributions welcome](https://img.shields.io/static/v1.svg?label=Contributions&message=Welcome&color=0059b3&style=flat-square)](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/CONTRIBUTION.md)  +# The Algorithms - C++ # {#mainpage} +[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/TheAlgorithms/C-Plus-Plus) +[![Gitter chat](https://img.shields.io/badge/Chat-Gitter-ff69b4.svg?label=Chat&logo=gitter&style=flat-square)](https://gitter.im/TheAlgorithms) +![contributions welcome](https://img.shields.io/static/v1.svg?label=Contributions&message=Welcome&color=0059b3&style=flat-square) ![GitHub repo size](https://img.shields.io/github/repo-size/TheAlgorithms/C-Plus-Plus?color=red&style=flat-square) ![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed/TheAlgorithms/C-Plus-Plus?color=green&style=flat-square) +![Doxygen CI](https://github.com/TheAlgorithms/C-Plus-Plus/workflows/Doxygen%20CI/badge.svg) +![Awesome CI](https://github.com/TheAlgorithms/C-Plus-Plus/workflows/Awesome%20CI%20Workflow/badge.svg) -### All algorithms implemented in C++ (for education) +[Online Documentation](https://TheAlgorithms.github.io/C-Plus-Plus). + +Click on [Files menu](https://TheAlgorithms.github.io/C-Plus-Plus/files.html) to see the list of all the files documented with the code. + +### Algorithms implemented in C++ (for education) The implementations are for learning purpose. They may be less efficient than the implementation in the standard library. ### Contribute Guidelines -Read our [Contribution Guidelines](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/CONTRIBUTION.md) before you contribute. +Read our [Contribution Guidelines](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/CONTRIBUTING.md) before you contribute. diff --git a/backtracking/graph_coloring.cpp b/backtracking/graph_coloring.cpp index cadc6d5ec3d..19a983019e6 100644 --- a/backtracking/graph_coloring.cpp +++ b/backtracking/graph_coloring.cpp @@ -7,8 +7,7 @@ void printSolution(int color[]); /* A utility function to check if the current color assignment is safe for vertex v */ -bool isSafe(int v, bool graph[V][V], int color[], int c) -{ +bool isSafe(int v, bool graph[V][V], int color[], int c) { for (int i = 0; i < V; i++) if (graph[v][i] && c == color[i]) return false; @@ -16,22 +15,18 @@ bool isSafe(int v, bool graph[V][V], int color[], int c) } /* A recursive utility function to solve m coloring problem */ -void graphColoring(bool graph[V][V], int m, int color[], int v) -{ +void graphColoring(bool graph[V][V], int m, int color[], int v) { /* base case: If all vertices are assigned a color then return true */ - if (v == V) - { + if (v == V) { printSolution(color); return; } /* Consider this vertex v and try different colors */ - for (int c = 1; c <= m; c++) - { + for (int c = 1; c <= m; c++) { /* Check if assignment of color c to v is fine*/ - if (isSafe(v, graph, color, c)) - { + if (isSafe(v, graph, color, c)) { color[v] = c; /* recur to assign colors to rest of the vertices */ @@ -45,17 +40,14 @@ void graphColoring(bool graph[V][V], int m, int color[], int v) } /* A utility function to print solution */ -void printSolution(int color[]) -{ +void printSolution(int color[]) { printf(" Following are the assigned colors \n"); - for (int i = 0; i < V; i++) - printf(" %d ", color[i]); + for (int i = 0; i < V; i++) printf(" %d ", color[i]); printf("\n"); } // driver program to test above function -int main() -{ +int main() { /* Create following graph and test whether it is 3 colorable (3)---(2) | / | @@ -69,12 +61,11 @@ int main() {1, 1, 0, 1}, {1, 0, 1, 0}, }; - int m = 3; // Number of colors + int m = 3; // Number of colors int color[V]; - for (int i = 0; i < V; i++) - color[i] = 0; + for (int i = 0; i < V; i++) color[i] = 0; graphColoring(graph, m, color, 0); return 0; diff --git a/backtracking/knight_tour.cpp b/backtracking/knight_tour.cpp index fbb8a6f963b..c97523be77f 100644 --- a/backtracking/knight_tour.cpp +++ b/backtracking/knight_tour.cpp @@ -1,68 +1,60 @@ #include -# define n 8 +#define n 8 /** A knight's tour is a sequence of moves of a knight on a chessboard -such that the knight visits every square only once. If the knight -ends on a square that is one knight's move from the beginning -square (so that it could tour the board again immediately, following +such that the knight visits every square only once. If the knight +ends on a square that is one knight's move from the beginning +square (so that it could tour the board again immediately, following the same path), the tour is closed; otherwise, it is open. **/ -using namespace std; -bool issafe(int x,int y,int sol[n][n]) -{ - return (x=0 && y=0 && sol[x][y]==-1); +using std::cin; +using std::cout; +bool issafe(int x, int y, int sol[n][n]) { + return (x < n && x >= 0 && y < n && y >= 0 && sol[x][y] == -1); } -bool solve(int x,int y, int mov, int sol[n][n], int xmov[n], int ymov[n]) -{ - int k,xnext,ynext; +bool solve(int x, int y, int mov, int sol[n][n], int xmov[n], int ymov[n]) { + int k, xnext, ynext; - if(mov == n*n) + if (mov == n * n) return true; - for(k=0;k<8;k++) - { - xnext=x+xmov[k]; - ynext=y+ymov[k]; + for (k = 0; k < 8; k++) { + xnext = x + xmov[k]; + ynext = y + ymov[k]; - if(issafe(xnext,ynext,sol)) - { - sol[xnext][ynext]=mov; + if (issafe(xnext, ynext, sol)) { + sol[xnext][ynext] = mov; - if(solve(xnext,ynext,mov+1,sol,xmov,ymov)==true) - return true; - else - sol[xnext][ynext]=-1; - } + if (solve(xnext, ynext, mov + 1, sol, xmov, ymov) == true) + return true; + else + sol[xnext][ynext] = -1; + } } return false; } -int main() -{ - //initialize(); +int main() { + // initialize(); int sol[n][n]; - int i,j; - for(i=0;i scores, } int main() { - vector scores = { 90, 23, 6, 33, 21, 65, 123, 34423 }; + vector scores = {90, 23, 6, 33, 21, 65, 123, 34423}; int height = log2(scores.size()); cout << "Optimal value: " << minimax(0, 0, true, scores, height) << endl; diff --git a/backtracking/n_queens.cpp b/backtracking/n_queens.cpp index 472aaa2fe1c..8aab5df7b9c 100644 --- a/backtracking/n_queens.cpp +++ b/backtracking/n_queens.cpp @@ -2,19 +2,15 @@ #define N 4 using namespace std; -void printSolution(int board[N][N]) -{ +void printSolution(int board[N][N]) { cout << "\n"; - for (int i = 0; i < N; i++) - { - for (int j = 0; j < N; j++) - cout << "" << board[i][j]; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) cout << "" << board[i][j]; cout << "\n"; } } -bool isSafe(int board[N][N], int row, int col) -{ +bool isSafe(int board[N][N], int row, int col) { int i, j; /* Check this row on left side */ @@ -35,23 +31,18 @@ bool isSafe(int board[N][N], int row, int col) return true; } -void solveNQ(int board[N][N], int col) -{ - - if (col >= N) - { +void solveNQ(int board[N][N], int col) { + if (col >= N) { printSolution(board); return; } /* Consider this column and try placing this queen in all rows one by one */ - for (int i = 0; i < N; i++) - { + for (int i = 0; i < N; i++) { /* Check if queen can be placed on board[i][col] */ - if (isSafe(board, i, col)) - { + if (isSafe(board, i, col)) { /* Place this queen in board[i][col] */ // cout<<"\n"< #define n 4 -#define inc_loop(var, start, stop) for (int var=start; var <= stop; var++) -#define dec_loop(var, start, stop) for (int var=start; var >= stop; var--) +#define inc_loop(var, start, stop) for (int var = start; var <= stop; var++) +#define dec_loop(var, start, stop) for (int var = start; var >= stop; var--) void PrintSol(int Board[n][n]) { - inc_loop(i, 0, n-1) { - inc_loop(j, 0, n-1) - std::cout << Board[i][j] << " "; + inc_loop(i, 0, n - 1) { + inc_loop(j, 0, n - 1) std::cout << Board[i][j] << " "; std::cout << std::endl; } std::cout << std::endl; - if (n%2 == 0 || (n%2 == 1 && Board[n/2+1][0] != 1)) { - inc_loop(i, 0, n-1) { - dec_loop(j, n-1, 0) - std::cout << Board[i][j] << " "; + if (n % 2 == 0 || (n % 2 == 1 && Board[n / 2 + 1][0] != 1)) { + inc_loop(i, 0, n - 1) { + dec_loop(j, n - 1, 0) std::cout << Board[i][j] << " "; std::cout << std::endl; } std::cout << std::endl; @@ -21,7 +19,7 @@ void PrintSol(int Board[n][n]) { bool CanIMove(int Board[n][n], int row, int col) { /// check in the row - inc_loop(i, 0, col-1) { + inc_loop(i, 0, col - 1) { if (Board[row][i] == 1) return false; } @@ -43,7 +41,7 @@ void NQueenSol(int Board[n][n], int col) { PrintSol(Board); return; } - inc_loop(i, 0, n-1) { + inc_loop(i, 0, n - 1) { if (CanIMove(Board, i, col)) { Board[i][col] = 1; NQueenSol(Board, col + 1); @@ -54,8 +52,8 @@ void NQueenSol(int Board[n][n], int col) { int main() { int Board[n][n] = {0}; - if (n%2 == 0) { - inc_loop(i, 0, n/2-1) { + if (n % 2 == 0) { + inc_loop(i, 0, n / 2 - 1) { if (CanIMove(Board, i, 0)) { Board[i][0] = 1; NQueenSol(Board, 1); @@ -63,7 +61,7 @@ int main() { } } } else { - inc_loop(i, 0, n/2) { + inc_loop(i, 0, n / 2) { if (CanIMove(Board, i, 0)) { Board[i][0] = 1; NQueenSol(Board, 1); diff --git a/backtracking/rat_maze.cpp b/backtracking/rat_maze.cpp index 307b5c7b0c9..fb3be4451d3 100644 --- a/backtracking/rat_maze.cpp +++ b/backtracking/rat_maze.cpp @@ -1,73 +1,62 @@ /* - A Maze is given as N*N binary matrix of blocks where source block is the upper - left most block i.e., maze[0][0] and destination block is lower rightmost - block i.e., maze[N-1][N-1]. A rat starts from source and has to reach destination. - The rat can move only in two directions: forward and down. In the maze matrix, - 0 means the block is dead end and 1 means the block can be used in the path - from source to destination. + A Maze is given as N*N binary matrix of blocks where source block is the + upper left most block i.e., maze[0][0] and destination block is lower + rightmost block i.e., maze[N-1][N-1]. A rat starts from source and has to + reach destination. The rat can move only in two directions: forward and down. + In the maze matrix, 0 means the block is dead end and 1 means the block can + be used in the path from source to destination. */ #include #define size 4 using namespace std; -int solveMaze(int currposrow, int currposcol, int maze[size][size], int soln[size][size]) -{ - if ((currposrow == size - 1) && (currposcol == size - 1)) - { - soln[currposrow][currposcol] = 1; - for (int i = 0; i < size; ++i) - { - for (int j = 0; j < size; ++j) - { - cout << soln[i][j]; - } - cout << endl; - } - return 1; - } - else - { - soln[currposrow][currposcol] = 1; - - // if there exist a solution by moving one step ahead in a collumn - if ((currposcol < size - 1) && maze[currposrow][currposcol + 1] == 1 && solveMaze(currposrow, currposcol + 1, maze, soln)) - { - return 1; - } - - // if there exists a solution by moving one step ahead in a row - if ((currposrow < size - 1) && maze[currposrow + 1][currposcol] == 1 && solveMaze(currposrow + 1, currposcol, maze, soln)) - { - return 1; - } - - // the backtracking part - soln[currposrow][currposcol] = 0; - return 0; - } +int solveMaze(int currposrow, int currposcol, int maze[size][size], + int soln[size][size]) { + if ((currposrow == size - 1) && (currposcol == size - 1)) { + soln[currposrow][currposcol] = 1; + for (int i = 0; i < size; ++i) { + for (int j = 0; j < size; ++j) { + cout << soln[i][j]; + } + cout << endl; + } + return 1; + } else { + soln[currposrow][currposcol] = 1; + + // if there exist a solution by moving one step ahead in a collumn + if ((currposcol < size - 1) && maze[currposrow][currposcol + 1] == 1 && + solveMaze(currposrow, currposcol + 1, maze, soln)) { + return 1; + } + + // if there exists a solution by moving one step ahead in a row + if ((currposrow < size - 1) && maze[currposrow + 1][currposcol] == 1 && + solveMaze(currposrow + 1, currposcol, maze, soln)) { + return 1; + } + + // the backtracking part + soln[currposrow][currposcol] = 0; + return 0; + } } -int main(int argc, char const *argv[]) -{ - int maze[size][size] = { - {1, 0, 1, 0}, - {1, 0, 1, 1}, - {1, 0, 0, 1}, - {1, 1, 1, 1}}; +int main(int argc, char const *argv[]) { + int maze[size][size] = { + {1, 0, 1, 0}, {1, 0, 1, 1}, {1, 0, 0, 1}, {1, 1, 1, 1}}; - int soln[size][size]; + int soln[size][size]; - for (int i = 0; i < size; ++i) - { - for (int j = 0; j < size; ++j) - { - soln[i][j] = 0; - } - } + for (int i = 0; i < size; ++i) { + for (int j = 0; j < size; ++j) { + soln[i][j] = 0; + } + } - int currposrow = 0; - int currposcol = 0; - solveMaze(currposrow, currposcol, maze, soln); - return 0; + int currposrow = 0; + int currposcol = 0; + solveMaze(currposrow, currposcol, maze, soln); + return 0; } diff --git a/backtracking/sudoku_solve.cpp b/backtracking/sudoku_solve.cpp index 6a01fd395ea..b712b6ec7a4 100644 --- a/backtracking/sudoku_solve.cpp +++ b/backtracking/sudoku_solve.cpp @@ -1,15 +1,12 @@ #include using namespace std; -///N=9; +/// N=9; int n = 9; -bool isPossible(int mat[][9], int i, int j, int no) -{ - ///Row or col nahin hona chahiye - for (int x = 0; x < n; x++) - { - if (mat[x][j] == no || mat[i][x] == no) - { +bool isPossible(int mat[][9], int i, int j, int no) { + /// Row or col nahin hona chahiye + for (int x = 0; x < n; x++) { + if (mat[x][j] == no || mat[i][x] == no) { return false; } } @@ -18,12 +15,9 @@ bool isPossible(int mat[][9], int i, int j, int no) int sx = (i / 3) * 3; int sy = (j / 3) * 3; - for (int x = sx; x < sx + 3; x++) - { - for (int y = sy; y < sy + 3; y++) - { - if (mat[x][y] == no) - { + for (int x = sx; x < sx + 3; x++) { + for (int y = sy; y < sy + 3; y++) { + if (mat[x][y] == no) { return false; } } @@ -31,83 +25,63 @@ bool isPossible(int mat[][9], int i, int j, int no) return true; } -void printMat(int mat[][9]) -{ - - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { +void printMat(int mat[][9]) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cout << mat[i][j] << " "; - if ((j + 1) % 3 == 0) - { + if ((j + 1) % 3 == 0) { cout << '\t'; } } - if ((i + 1) % 3 == 0) - { + if ((i + 1) % 3 == 0) { cout << endl; } cout << endl; } } -bool solveSudoku(int mat[][9], int i, int j) -{ - ///Base Case - if (i == 9) - { - ///Solve kr chuke hain for 9 rows already +bool solveSudoku(int mat[][9], int i, int j) { + /// Base Case + if (i == 9) { + /// Solve kr chuke hain for 9 rows already printMat(mat); return true; } - ///Crossed the last Cell in the row - if (j == 9) - { + /// Crossed the last Cell in the row + if (j == 9) { return solveSudoku(mat, i + 1, 0); } - ///Blue Cell - Skip - if (mat[i][j] != 0) - { + /// Blue Cell - Skip + if (mat[i][j] != 0) { return solveSudoku(mat, i, j + 1); } - ///White Cell - ///Try to place every possible no - for (int no = 1; no <= 9; no++) - { - if (isPossible(mat, i, j, no)) - { - ///Place the no - assuming solution aa jayega + /// White Cell + /// Try to place every possible no + for (int no = 1; no <= 9; no++) { + if (isPossible(mat, i, j, no)) { + /// Place the no - assuming solution aa jayega mat[i][j] = no; bool aageKiSolveHui = solveSudoku(mat, i, j + 1); - if (aageKiSolveHui) - { + if (aageKiSolveHui) { return true; } - ///Nahin solve hui - ///loop will place the next no. + /// Nahin solve hui + /// loop will place the next no. } } - ///Sare no try kr liey, kisi se bhi solve nahi hui + /// Sare no try kr liey, kisi se bhi solve nahi hui mat[i][j] = 0; return false; } -int main() -{ - - int mat[9][9] = - {{5, 3, 0, 0, 7, 0, 0, 0, 0}, - {6, 0, 0, 1, 9, 5, 0, 0, 0}, - {0, 9, 8, 0, 0, 0, 0, 6, 0}, - {8, 0, 0, 0, 6, 0, 0, 0, 3}, - {4, 0, 0, 8, 0, 3, 0, 0, 1}, - {7, 0, 0, 0, 2, 0, 0, 0, 6}, - {0, 6, 0, 0, 0, 0, 2, 8, 0}, - {0, 0, 0, 4, 1, 9, 0, 0, 5}, - {0, 0, 0, 0, 8, 0, 0, 7, 9}}; +int main() { + int mat[9][9] = {{5, 3, 0, 0, 7, 0, 0, 0, 0}, {6, 0, 0, 1, 9, 5, 0, 0, 0}, + {0, 9, 8, 0, 0, 0, 0, 6, 0}, {8, 0, 0, 0, 6, 0, 0, 0, 3}, + {4, 0, 0, 8, 0, 3, 0, 0, 1}, {7, 0, 0, 0, 2, 0, 0, 0, 6}, + {0, 6, 0, 0, 0, 0, 2, 8, 0}, {0, 0, 0, 4, 1, 9, 0, 0, 5}, + {0, 0, 0, 0, 8, 0, 0, 7, 9}}; printMat(mat); cout << "Solution " << endl; diff --git a/computer_oriented_statistical_methods/Bisection_method.CPP b/computer_oriented_statistical_methods/Bisection_method.CPP deleted file mode 100644 index 717987321cd..00000000000 --- a/computer_oriented_statistical_methods/Bisection_method.CPP +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include - -float eq(float i) -{ - return (pow(i, 3) - (4 * i) - 9); // original equation -} - -void main() -{ - float a, b, x, z; - clrscr(); - for (int i = 0; i < 100; i++) - { - z = eq(i); - if (z >= 0) - { - b = i; - a = --i; - goto START; - } - } - -START: - - cout << "\nFirst initial: " << a; - cout << "\nSecond initial: " << b; - for (i = 0; i < 100; i++) - { - x = (a + b) / 2; - z = eq(x); - cout << "\n\nz: " << z << "\t[" << a << " , " << b << " | Bisect: " << x << "]"; - - if (z < 0) - { - a = x; - } - else - { - b = x; - } - - if (z > 0 && z < 0.0009) // stoping criteria - { - goto END; - } - } - -END: - cout << "\n\nRoot: " << x; - getch(); -} diff --git a/computer_oriented_statistical_methods/Gaussian_elimination.cpp b/computer_oriented_statistical_methods/Gaussian_elimination.cpp deleted file mode 100644 index 58e634505af..00000000000 --- a/computer_oriented_statistical_methods/Gaussian_elimination.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -using namespace std; - -int main() -{ - int mat_size, i, j, step; - - cout << "Matrix size: "; - cin >> mat_size; - - double mat[mat_size + 1][mat_size + 1], x[mat_size][mat_size + 1]; - - cout << endl - << "Enter value of the matrix: " << endl; - for (i = 0; i < mat_size; i++) - { - for (j = 0; j <= mat_size; j++) - { - cin >> mat[i][j]; //Enter (mat_size*mat_size) value of the matrix. - } - } - - for (step = 0; step < mat_size - 1; step++) - { - for (i = step; i < mat_size - 1; i++) - { - double a = (mat[i + 1][step] / mat[step][step]); - - for (j = step; j <= mat_size; j++) - mat[i + 1][j] = mat[i + 1][j] - (a * mat[step][j]); - } - } - - cout << endl - << "Matrix using Gaussian Elimination method: " << endl; - for (i = 0; i < mat_size; i++) - { - for (j = 0; j <= mat_size; j++) - { - x[i][j] = mat[i][j]; - cout << mat[i][j] << " "; - } - cout << endl; - } - cout << endl - << "Value of the Gaussian Elimination method: " << endl; - for (i = mat_size - 1; i >= 0; i--) - { - double sum = 0; - for (j = mat_size - 1; j > i; j--) - { - x[i][j] = x[j][j] * x[i][j]; - sum = x[i][j] + sum; - } - if (x[i][i] == 0) - x[i][i] = 0; - else - x[i][i] = (x[i][mat_size] - sum) / (x[i][i]); - - cout << "x" << i << "= " << x[i][i] << endl; - } - return 0; -} diff --git a/computer_oriented_statistical_methods/Newton_Raphson.CPP b/computer_oriented_statistical_methods/Newton_Raphson.CPP deleted file mode 100644 index 183a78daf8a..00000000000 --- a/computer_oriented_statistical_methods/Newton_Raphson.CPP +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include - -float eq(float i) -{ - return (pow(i, 3) - (4 * i) - 9); // original equation -} -float eq_der(float i) -{ - return ((3 * pow(i, 2)) - 4); // derivative of equation -} - -void main() -{ - float a, b, z, c, m, n; - clrscr(); - for (int i = 0; i < 100; i++) - { - z = eq(i); - if (z >= 0) - { - b = i; - a = --i; - goto START; - } - } - -START: - - cout << "\nFirst initial: " << a; - cout << "\nSecond initial: " << b; - c = (a + b) / 2; - - for (i = 0; i < 100; i++) - { - float h; - m = eq(c); - n = eq_der(c); - - z = c - (m / n); - c = z; - - if (m > 0 && m < 0.009) // stoping criteria - { - goto END; - } - } - -END: - cout << "\n\nRoot: " << z; - getch(); -} diff --git a/computer_oriented_statistical_methods/Secant_method.CPP b/computer_oriented_statistical_methods/Secant_method.CPP deleted file mode 100644 index b897e9184f4..00000000000 --- a/computer_oriented_statistical_methods/Secant_method.CPP +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -#include - -float eq(float i) -{ - return (pow(i, 3) - (4 * i) - 9); // original equation -} - -void main() -{ - float a, b, z, c, m, n; - clrscr(); - for (int i = 0; i < 100; i++) - { - z = eq(i); - if (z >= 0) - { - b = i; - a = --i; - goto START; - } - } - -START: - - cout << "\nFirst initial: " << a; - cout << "\nSecond initial: " << b; - for (i = 0; i < 100; i++) - { - float h, d; - m = eq(a); - n = eq(b); - - c = ((a * n) - (b * m)) / (n - m); - a = b; - b = c; - - z = eq(c); - if (z > 0 && z < 0.09) // stoping criteria - { - goto END; - } - } - -END: - cout << "\n\nRoot: " << c; - getch(); -} diff --git a/computer_oriented_statistical_methods/false-position.cpp b/computer_oriented_statistical_methods/false-position.cpp deleted file mode 100644 index 5e15e92cc4c..00000000000 --- a/computer_oriented_statistical_methods/false-position.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -float eq(float i) { - return (pow(i, 3) - (4 * i) - 9); // origial equation -} -int main() { - float a, b, z, c, m, n; - system("clear"); - for (int i = 0; i < 100; i++) { - z = eq(i); - if (z >= 0) { - b = i; - a = --i; - goto START; - } - } - START: - std::cout << "\nFirst initial: " << a; - std::cout << "\nSecond initial: " << b; - for (int i = 0; i < 100; i++) { - float h, d; - m = eq(a); - n = eq(b); - c = ((a * n) - (b * m)) / (n - m); - a = c; - z = eq(c); - if (z > 0 && z < 0.09) { // stoping criteria - goto END; - } - } - END: - std::cout << "\n\nRoot: " << c; - system("pause"); -} diff --git a/computer_oriented_statistical_methods/ordinary_least_squares_regressor.cpp b/computer_oriented_statistical_methods/ordinary_least_squares_regressor.cpp deleted file mode 100644 index f50ccf1b1d7..00000000000 --- a/computer_oriented_statistical_methods/ordinary_least_squares_regressor.cpp +++ /dev/null @@ -1,349 +0,0 @@ -/** - * Program that gets the number of data samples and number of features per - * sample along with output per sample. It applies OLS regression to compute - * the regression output for additional test data samples. - **/ -#include -#include -#include - -template -std::ostream &operator<<(std::ostream &out, - std::vector> const &v) { - const int width = 10; - const char separator = ' '; - - for (size_t row = 0; row < v.size(); row++) { - for (size_t col = 0; col < v[row].size(); col++) - out << std::left << std::setw(width) << std::setfill(separator) - << v[row][col]; - out << std::endl; - } - - return out; -} - -template -std::ostream &operator<<(std::ostream &out, std::vector const &v) { - const int width = 15; - const char separator = ' '; - - for (size_t row = 0; row < v.size(); row++) - out << std::left << std::setw(width) << std::setfill(separator) << v[row]; - - return out; -} - -template -inline bool is_square(std::vector> const &A) { - // Assuming A is square matrix - size_t N = A.size(); - for (size_t i = 0; i < N; i++) - if (A[i].size() != N) - return false; - return true; -} - -/** - * matrix multiplication - **/ -template -std::vector> operator*(std::vector> const &A, - std::vector> const &B) { - // Number of rows in A - size_t N_A = A.size(); - // Number of columns in B - size_t N_B = B[0].size(); - - std::vector> result(N_A); - - if (A[0].size() != B.size()) { - std::cerr << "Number of columns in A != Number of rows in B (" - << A[0].size() << ", " << B.size() << ")" << std::endl; - return result; - } - - for (size_t row = 0; row < N_A; row++) { - std::vector v(N_B); - for (size_t col = 0; col < N_B; col++) { - v[col] = static_cast(0); - for (size_t j = 0; j < B.size(); j++) - v[col] += A[row][j] * B[j][col]; - } - result[row] = v; - } - - return result; -} - -template -std::vector operator*(std::vector> const &A, - std::vector const &B) { - // Number of rows in A - size_t N_A = A.size(); - - std::vector result(N_A); - - if (A[0].size() != B.size()) { - std::cerr << "Number of columns in A != Number of rows in B (" - << A[0].size() << ", " << B.size() << ")" << std::endl; - return result; - } - - for (size_t row = 0; row < N_A; row++) { - result[row] = static_cast(0); - for (size_t j = 0; j < B.size(); j++) - result[row] += A[row][j] * B[j]; - } - - return result; -} - -template -std::vector operator*(float const scalar, std::vector const &A) { - // Number of rows in A - size_t N_A = A.size(); - - std::vector result(N_A); - - for (size_t row = 0; row < N_A; row++) { - result[row] += A[row] * static_cast(scalar); - } - - return result; -} - -template -std::vector operator*(std::vector const &A, float const scalar) { - // Number of rows in A - size_t N_A = A.size(); - - std::vector result(N_A); - - for (size_t row = 0; row < N_A; row++) - result[row] = A[row] * static_cast(scalar); - - return result; -} - -template -std::vector operator/(std::vector const &A, float const scalar) { - return (1.f / scalar) * A; -} - -template -std::vector operator-(std::vector const &A, std::vector const &B) { - // Number of rows in A - size_t N = A.size(); - - std::vector result(N); - - if (B.size() != N) { - std::cerr << "Vector dimensions shouldbe identical!" << std::endl; - return A; - } - - for (size_t row = 0; row < N; row++) - result[row] = A[row] - B[row]; - - return result; -} - -template -std::vector operator+(std::vector const &A, std::vector const &B) { - // Number of rows in A - size_t N = A.size(); - - std::vector result(N); - - if (B.size() != N) { - std::cerr << "Vector dimensions shouldbe identical!" << std::endl; - return A; - } - - for (size_t row = 0; row < N; row++) - result[row] = A[row] + B[row]; - - return result; -} - -/** - * Get matrix inverse using Row-trasnformations - **/ -template -std::vector> -get_inverse(std::vector> const &A) { - // Assuming A is square matrix - size_t N = A.size(); - - std::vector> inverse(N); - for (size_t row = 0; row < N; row++) { - // preallocatae a resultant identity matrix - inverse[row] = std::vector(N); - for (size_t col = 0; col < N; col++) - inverse[row][col] = (row == col) ? 1.f : 0.f; - } - - if (!is_square(A)) { - std::cerr << "A must be a square matrix!" << std::endl; - return inverse; - } - - // preallocatae a temporary matrix identical to A - std::vector> temp(N); - for (size_t row = 0; row < N; row++) { - std::vector v(N); - for (size_t col = 0; col < N; col++) - v[col] = static_cast(A[row][col]); - temp[row] = v; - } - - // start transformations - for (size_t row = 0; row < N; row++) { - for (size_t row2 = row; row2 < N && temp[row][row] == 0; row2++) { - // this to ensure diagonal elements are not 0 - temp[row] = temp[row] + temp[row2]; - inverse[row] = inverse[row] + inverse[row2]; - } - - for (size_t col2 = row; col2 < N && temp[row][row] == 0; col2++) { - // this to further ensure diagonal elements are not 0 - for (size_t row2 = 0; row2 < N; row2++) { - temp[row2][row] = temp[row2][row] + temp[row2][col2]; - inverse[row2][row] = inverse[row2][row] + inverse[row2][col2]; - } - } - - if (temp[row][row] == 0) { - // Probably a low-rank matrix and hence singular - std::cerr << "Low-rank matrix, no inverse!" << std::endl; - return inverse; - } - - // set diagonal to 1 - float divisor = static_cast(temp[row][row]); - temp[row] = temp[row] / divisor; - inverse[row] = inverse[row] / divisor; - // Row transformations - for (size_t row2 = 0; row2 < N; row2++) { - if (row2 == row) - continue; - float factor = temp[row2][row]; - temp[row2] = temp[row2] - factor * temp[row]; - inverse[row2] = inverse[row2] - factor * inverse[row]; - } - } - - return inverse; -} - -/** - * matrix transpose - **/ -template -std::vector> -get_transpose(std::vector> const &A) { - std::vector> result(A[0].size()); - - for (size_t row = 0; row < A[0].size(); row++) { - std::vector v(A.size()); - for (size_t col = 0; col < A.size(); col++) - v[col] = A[col][row]; - - result[row] = v; - } - return result; -} - -template -std::vector fit_OLS_regressor(std::vector> const &X, - std::vector const &Y) { - // NxF - std::vector> X2 = X; - for (size_t i = 0; i < X2.size(); i++) - // add Y-intercept -> Nx(F+1) - X2[i].push_back(1); - // (F+1)xN - std::vector> Xt = get_transpose(X2); - // (F+1)x(F+1) - std::vector> tmp = get_inverse(Xt * X2); - // (F+1)xN - std::vector> out = tmp * Xt; - // cout << endl - // << "Projection matrix: " << X2 * out << endl; - - // Fx1,1 -> (F+1)^th element is the independent constant - return out * Y; -} - -/** - * Given data and OLS model coeffficients, predict - * regression estimates - **/ -template -std::vector predict_OLS_regressor(std::vector> const &X, - std::vector const &beta) { - std::vector result(X.size()); - - for (size_t rows = 0; rows < X.size(); rows++) { - // -> start with constant term - result[rows] = beta[X[0].size()]; - for (size_t cols = 0; cols < X[0].size(); cols++) - result[rows] += beta[cols] * X[rows][cols]; - } - // Nx1 - return result; -} - -int main() { - size_t N, F; - - std::cout << "Enter number of features: "; - // number of features = columns - std::cin >> F; - std::cout << "Enter number of samples: "; - // number of samples = rows - std::cin >> N; - - std::vector> data(N); - std::vector Y(N); - - std::cout - << "Enter training data. Per sample, provide features ad one output." - << std::endl; - - for (size_t rows = 0; rows < N; rows++) { - std::vector v(F); - std::cout << "Sample# " << rows + 1 << ": "; - for (size_t cols = 0; cols < F; cols++) - // get the F features - std::cin >> v[cols]; - data[rows] = v; - // get the corresponding output - std::cin >> Y[rows]; - } - - std::vector beta = fit_OLS_regressor(data, Y); - std::cout << std::endl << std::endl << "beta:" << beta << std::endl; - - size_t T; - std::cout << "Enter number of test samples: "; - // number of test sample inputs - std::cin >> T; - std::vector> data2(T); - // vector Y2(T); - - for (size_t rows = 0; rows < T; rows++) { - std::cout << "Sample# " << rows + 1 << ": "; - std::vector v(F); - for (size_t cols = 0; cols < F; cols++) - std::cin >> v[cols]; - data2[rows] = v; - } - - std::vector out = predict_OLS_regressor(data2, beta); - for (size_t rows = 0; rows < T; rows++) - std::cout << out[rows] << std::endl; - - return 0; -} diff --git a/computer_oriented_statistical_methods/successive_approximation.CPP b/computer_oriented_statistical_methods/successive_approximation.CPP deleted file mode 100644 index b42ab8f8c11..00000000000 --- a/computer_oriented_statistical_methods/successive_approximation.CPP +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -#include -float eq(float y) -{ - return ((3 * y) - (cos(y)) - 2); -} -float eqd(float y) -{ - return ((0.5) * ((cos(y)) + 2)); -} - -void main() -{ - float y, x1, x2, x3, sum, s, a, f1, f2, gd; - int i, n; - - clrscr(); - for (i = 0; i < 10; i++) - { - sum = eq(y); - cout << "value of equation at " << i << " " << sum << "\n"; - y++; - } - cout << "enter the x1->"; - cin >> x1; - cout << "enter the no iteration to perform->\n"; - cin >> n; - - for (i = 0; i <= n; i++) - { - x2 = eqd(x1); - cout << "\nenter the x2->" << x2; - x1 = x2; - } - getch(); -} \ No newline at end of file diff --git a/data_structure/AVLtree.cpp b/data_structure/AVLtree.cpp deleted file mode 100644 index db6b9e0d449..00000000000 --- a/data_structure/AVLtree.cpp +++ /dev/null @@ -1,176 +0,0 @@ -#include -#include - -using namespace std; - -typedef struct node -{ - int data; - int height; - struct node *left; - struct node *right; -} node; - -int max(int a, int b) -{ - return a > b ? a : b; -} - -// Returns a new Node - -node *createNode(int data) -{ - node *nn = new node(); - nn->data = data; - nn->height = 0; - nn->left = NULL; - nn->right = NULL; - return nn; -} - -// Returns height of tree - -int height(node *root) -{ - if (root == NULL) - return 0; - return 1 + max(height(root->left), height(root->right)); -} - -// Returns difference between height of left and right subtree - -int getBalance(node *root) -{ - return height(root->left) - height(root->right); -} - -// Returns Node after Right Rotation - -node *rightRotate(node *root) -{ - node *t = root->left; - node *u = t->right; - t->right = root; - root->left = u; - return t; -} - -// Returns Node after Left Rotation - -node *leftRotate(node *root) -{ - node *t = root->right; - node *u = t->left; - t->left = root; - root->right = u; - return t; -} - -// Returns node with minimum value in the tree - -node *minValue(node *root) -{ - if (root->left == NULL) - return root; - return minValue(root->left); -} - -// Balanced Insertion - -node *insert(node *root, int item) -{ - node *nn = createNode(item); - if (root == NULL) - return nn; - if (item < root->data) - root->left = insert(root->left, item); - else - root->right = insert(root->right, item); - int b = getBalance(root); - if (b > 1) - { - if (getBalance(root->left) < 0) - root->left = leftRotate(root->left); // Left-Right Case - return rightRotate(root); // Left-Left Case - } - else if (b < -1) - { - if (getBalance(root->right) > 0) - root->right = rightRotate(root->right); // Right-Left Case - return leftRotate(root); // Right-Right Case - } - return root; -} - -// Balanced Deletion - -node *deleteNode(node *root, int key) -{ - if (root == NULL) - return root; - if (key < root->data) - root->left = deleteNode(root->left, key); - else if (key > root->data) - root->right = deleteNode(root->right, key); - - else - { - // Node to be deleted is leaf node or have only one Child - if (!root->right) - { - node *temp = root->left; - delete (root); - root = NULL; - return temp; - } - else if (!root->left) - { - node *temp = root->right; - delete (root); - root = NULL; - return temp; - } - // Node to be deleted have both left and right subtrees - node *temp = minValue(root->right); - root->data = temp->data; - root->right = deleteNode(root->right, temp->data); - } - // Balancing Tree after deletion - return root; -} - -// LevelOrder (Breadth First Search) - -void levelOrder(node *root) -{ - queue q; - q.push(root); - while (!q.empty()) - { - root = q.front(); - cout << root->data << " "; - q.pop(); - if (root->left) - q.push(root->left); - if (root->right) - q.push(root->right); - } -} - -int main() -{ - // Testing AVL Tree - node *root = NULL; - int i; - for (i = 1; i <= 7; i++) - root = insert(root, i); - cout << "LevelOrder: "; - levelOrder(root); - root = deleteNode(root, 1); // Deleting key with value 1 - cout << "\nLevelOrder: "; - levelOrder(root); - root = deleteNode(root, 4); // Deletin key with value 4 - cout << "\nLevelOrder: "; - levelOrder(root); - return 0; -} diff --git a/data_structure/Binary Search Tree.cpp b/data_structure/Binary Search Tree.cpp deleted file mode 100644 index 32a65517cdd..00000000000 --- a/data_structure/Binary Search Tree.cpp +++ /dev/null @@ -1,218 +0,0 @@ -#include -using namespace std; - -struct node -{ - int val; - node *left; - node *right; -}; - -struct queue -{ - node *t[100]; - int front; - int rear; -}; - -queue q; - -void enqueue(node *n) -{ - q.t[q.rear++] = n; -} - -node *dequeue() -{ - return (q.t[q.front++]); -} - -void Insert(node *n, int x) -{ - if (x < n->val) - { - if (n->left == NULL) - { - node *temp = new node; - temp->val = x; - temp->left = NULL; - temp->right = NULL; - n->left = temp; - } - else - { - Insert(n->left, x); - } - } - else - { - if (n->right == NULL) - { - node *temp = new node; - temp->val = x; - temp->left = NULL; - temp->right = NULL; - n->left = temp; - } - else - { - Insert(n->right, x); - } - } -} - -int findMaxInLeftST(node *n) -{ - while (n->right != NULL) - { - n = n->right; - } - return n->val; -} - -void Remove(node *p, node *n, int x) -{ - if (n->val == x) - { - if (n->right == NULL && n->left == NULL) - { - if (x < p->val) - { - p->right = NULL; - } - else - { - p->left = NULL; - } - } - else if (n->right == NULL) - { - if (x < p->val) - { - p->right = n->left; - } - else - { - p->left = n->left; - } - } - else if (n->left == NULL) - { - if (x < p->val) - { - p->right = n->right; - } - else - { - p->left = n->right; - } - } - else - { - int y = findMaxInLeftST(n->left); - n->val = y; - Remove(n, n->right, y); - } - } - else if (x < n->val) - { - Remove(n, n->left, x); - } - else - { - Remove(n, n->right, x); - } -} - -void BFT(node *n) -{ - if (n != NULL) - { - cout << n->val << " "; - enqueue(n->left); - enqueue(n->right); - BFT(dequeue()); - } -} - -void Pre(node *n) -{ - if (n != NULL) - { - cout << n->val << " "; - Pre(n->left); - Pre(n->right); - } -} - -void In(node *n) -{ - if (n != NULL) - { - In(n->left); - cout << n->val << " "; - In(n->right); - } -} - -void Post(node *n) -{ - if (n != NULL) - { - Post(n->left); - Post(n->right); - cout << n->val << " "; - } -} - -int main() -{ - q.front = 0; - q.rear = 0; - int value; - int ch; - node *root = new node; - cout << "\nEnter the value of root node :"; - cin >> value; - root->val = value; - root->left = NULL; - root->right = NULL; - do - { - cout << "\n1. Insert"; - cout << "\n2. Delete"; - cout << "\n3. Breadth First"; - cout << "\n4. Preorder Depth First"; - cout << "\n5. Inorder Depth First"; - cout << "\n6. Postorder Depth First"; - - cout << "\nEnter Your Choice : "; - cin >> ch; - int x; - switch (ch) - { - case 1: - cout << "\nEnter the value to be Inserted : "; - cin >> x; - Insert(root, x); - break; - case 2: - cout << "\nEnter the value to be Deleted : "; - 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_structure/Binaryheap.cpp b/data_structure/Binaryheap.cpp deleted file mode 100644 index 31129a82375..00000000000 --- a/data_structure/Binaryheap.cpp +++ /dev/null @@ -1,158 +0,0 @@ -// A C++ program to demonstrate common Binary Heap Operations -#include -#include -using namespace std; - -// Prototype of a utility function to swap two integers -void swap(int *x, int *y); - -// A class for Min Heap -class MinHeap -{ - int *harr; // pointer to array of elements in heap - int capacity; // maximum possible size of min heap - int heap_size; // Current number of elements in min heap -public: - // Constructor - MinHeap(int capacity); - - // to heapify a subtree with the root at given index - void MinHeapify(int); - - int parent(int i) { return (i - 1) / 2; } - - // to get index of left child of node at index i - int left(int i) { return (2 * i + 1); } - - // to get index of right child of node at index i - int right(int i) { return (2 * i + 2); } - - // to extract the root which is the minimum element - int extractMin(); - - // Decreases key value of key at index i to new_val - void decreaseKey(int i, int new_val); - - // Returns the minimum key (key at root) from min heap - int getMin() { return harr[0]; } - - // Deletes a key stored at index i - void deleteKey(int i); - - // Inserts a new key 'k' - void insertKey(int k); -}; - -// Constructor: Builds a heap from a given array a[] of given size -MinHeap::MinHeap(int cap) -{ - heap_size = 0; - capacity = cap; - harr = new int[cap]; -} - -// Inserts a new key 'k' -void MinHeap::insertKey(int k) -{ - if (heap_size == capacity) - { - cout << "\nOverflow: Could not insertKey\n"; - return; - } - - // First insert the new key at the end - heap_size++; - int i = heap_size - 1; - harr[i] = k; - - // Fix the min heap property if it is violated - while (i != 0 && harr[parent(i)] > harr[i]) - { - swap(&harr[i], &harr[parent(i)]); - i = parent(i); - } -} - -// Decreases value of key at index 'i' to new_val. It is assumed that -// new_val is smaller than harr[i]. -void MinHeap::decreaseKey(int i, int new_val) -{ - harr[i] = new_val; - while (i != 0 && harr[parent(i)] > harr[i]) - { - swap(&harr[i], &harr[parent(i)]); - i = parent(i); - } -} - -// Method to remove minimum element (or root) from min heap -int MinHeap::extractMin() -{ - if (heap_size <= 0) - return INT_MAX; - if (heap_size == 1) - { - heap_size--; - return harr[0]; - } - - // Store the minimum value, and remove it from heap - int root = harr[0]; - harr[0] = harr[heap_size - 1]; - heap_size--; - MinHeapify(0); - - return root; -} - -// This function deletes key at index i. It first reduced value to minus -// infinite, then calls extractMin() -void MinHeap::deleteKey(int i) -{ - decreaseKey(i, INT_MIN); - extractMin(); -} - -// A recursive method to heapify a subtree with the root at given index -// This method assumes that the subtrees are already heapified -void MinHeap::MinHeapify(int i) -{ - int l = left(i); - int r = right(i); - int smallest = i; - if (l < heap_size && harr[l] < harr[i]) - smallest = l; - if (r < heap_size && harr[r] < harr[smallest]) - smallest = r; - if (smallest != i) - { - swap(&harr[i], &harr[smallest]); - MinHeapify(smallest); - } -} - -// A utility function to swap two elements -void swap(int *x, int *y) -{ - int temp = *x; - *x = *y; - *y = temp; -} - -// Driver program to test above functions -int main() -{ - MinHeap h(11); - h.insertKey(3); - h.insertKey(2); - h.deleteKey(1); - h.insertKey(15); - h.insertKey(5); - h.insertKey(4); - h.insertKey(45); - cout << h.extractMin() << " "; - cout << h.getMin() << " "; - h.decreaseKey(2, 1); - cout << h.getMin(); - return 0; -} diff --git a/data_structure/List Array.cpp b/data_structure/List Array.cpp deleted file mode 100644 index de984876b09..00000000000 --- a/data_structure/List Array.cpp +++ /dev/null @@ -1,188 +0,0 @@ -#include -using namespace std; - -struct list -{ - int data[50]; - int top = 0; - bool isSorted = false; - - int BinarySearch(int *array, int first, int last, int x) - { - if (last < first) - { - return -1; - } - int mid = (first + last) / 2; - if (array[mid] == x) - return mid; - else if (x < array[mid]) - return (BinarySearch(array, first, mid - 1, x)); - else if (x > array[mid]) - return (BinarySearch(array, mid + 1, last, x)); - } - - int LinarSearch(int *array, int x) - { - for (int i = 0; i < top; i++) - { - if (array[i] == x) - { - return i; - } - } - - return -1; - } - - int Search(int x) - { - int pos = -1; - - if (isSorted) - { - pos = BinarySearch(data, 0, top - 1, x); - } - - else - { - pos = LinarSearch(data, x); - } - - if (pos != -1) - { - cout << "\nElement found at position : " << pos; - } - else - { - cout << "\nElement not found"; - } - return pos; - } - - void Sort() - { - int i, j, pos; - for (i = 0; i < top; i++) - { - int min = data[i]; - for (j = i + 1; j < top; j++) - { - if (data[j] < min) - { - pos = j; - min = data[pos]; - } - } - - int temp = data[i]; - data[i] = data[pos]; - data[pos] = temp; - } - isSorted = true; - } - - void insert(int x) - { - if (!isSorted) - { - - if (top == 49) - { - cout << "\nOverflow"; - } - else - { - data[top] = x; - top++; - } - } - - else - { - int pos = 0; - - for (int i = 0; i < top - 1; i++) - { - if (data[i] <= x && x <= data[i + 1]) - { - pos = i + 1; - break; - } - } - if (pos == 0) - { - pos = top - 1; - } - - for (int i = top; i > pos; i--) - { - data[i] = data[i - 1]; - } - top++; - data[pos] = x; - } - } - - void Remove(int x) - { - int pos = Search(x); - cout << "\n" - << data[pos] << " deleted"; - for (int i = pos; i < top; i++) - { - data[i] = data[i + 1]; - } - top--; - } - - void Show() - { - for (int i = 0; i < top; i++) - { - cout << data[i] << "\t"; - } - } -}; - -int main() -{ - list L; - int choice; - int x; - do - { - cout << "\n1.Insert"; - cout << "\n2.Delete"; - cout << "\n3.Search"; - cout << "\n4.Sort"; - cout << "\n5.Print"; - cout << "\n\nEnter Your Choice : "; - cin >> choice; - switch (choice) - { - case 1: - cout << "\nEnter the element to be inserted : "; - cin >> x; - L.insert(x); - break; - case 2: - cout << "\nEnter the element to be removed : "; - cin >> x; - L.Remove(x); - break; - case 3: - cout << "\nEnter the element to be searched : "; - cin >> x; - L.Search(x); - break; - case 4: - L.Sort(); - break; - case 5: - L.Show(); - break; - } - } while (choice != 0); - return 0; -} diff --git a/data_structure/MorrisInorder.cpp b/data_structure/MorrisInorder.cpp deleted file mode 100644 index d3a2e9fd724..00000000000 --- a/data_structure/MorrisInorder.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include -#include - -/************************** - @author shrutisheoran -**************************/ - -using namespace std; - -struct Btree -{ - int data; - struct Btree *left; //Pointer to left subtree - struct Btree *right; //Pointer to right subtree -}; - -void insert(Btree **root, int d) -{ - Btree *nn = new Btree(); //Creating new node - nn->data = d; - nn->left = NULL; - nn->right = NULL; - if (*root == NULL) - { - *root = nn; - return; - } - else - { - queue q; - // Adding root node to queue - q.push(*root); - while (!q.empty()) - { - Btree *node = q.front(); - // Removing parent node from queue - q.pop(); - if (node->left) - // Adding left child of removed node to queue - q.push(node->left); - else - { - // Adding new node if no left child is present - node->left = nn; - return; - } - if (node->right) - // Adding right child of removed node to queue - q.push(node->right); - else - { - // Adding new node if no right child is present - node->right = nn; - return; - } - } - } -} - -void morrisInorder(Btree *root) -{ - Btree *curr = root; - Btree *temp; - while (curr) - { - if (curr->left == NULL) - { - cout << curr->data << " "; - // If left of current node is NULL then curr is shifted to right - curr = curr->right; - } - else - { - // Left of current node is stored in temp - temp = curr->left; - // Moving to extreme right of temp - while (temp->right && temp->right != curr) - temp = temp->right; - // If extreme right is null it is made to point to currrent node (will be used for backtracking) - if (temp->right == NULL) - { - temp->right = curr; - // current node is made to point its left subtree - curr = curr->left; - } - // If extreme right already points to currrent node it it set to null - else if (temp->right == curr) - { - cout << curr->data << " "; - temp->right = NULL; - // current node is made to point its right subtree - curr = curr->right; - } - } - } -} - -int main() -{ - // Testing morrisInorder funtion - Btree *root = NULL; - int i; - for (i = 1; i <= 7; i++) - insert(&root, i); - cout << "Morris Inorder: "; - morrisInorder(root); - return 0; -} diff --git a/data_structure/Queue Using Array.cpp b/data_structure/Queue Using Array.cpp deleted file mode 100644 index 3b79d06fc05..00000000000 --- a/data_structure/Queue Using Array.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include -using namespace std; - -int queue[10]; -int front = 0; -int rear = 0; - -void Enque(int x) -{ - if (rear == 10) - { - cout << "\nOverflow"; - } - else - { - queue[rear++] = x; - } -} - -void Deque() -{ - if (front == rear) - { - cout << "\nUnderflow"; - } - - else - { - cout << "\n" - << queue[front++] << " deleted"; - for (int i = front; i < rear; i++) - { - queue[i - front] = queue[i]; - } - rear = rear - front; - front = 0; - } -} - -void show() -{ - for (int i = front; i < rear; i++) - { - cout << queue[i] << "\t"; - } -} - -int main() -{ - int ch, x; - do - { - cout << "\n1. Enque"; - cout << "\n2. Deque"; - cout << "\n3. Print"; - cout << "\nEnter Your Choice : "; - cin >> ch; - if (ch == 1) - { - cout << "\nInsert : "; - cin >> x; - Enque(x); - } - else if (ch == 2) - { - Deque(); - } - else if (ch == 3) - { - show(); - } - } while (ch != 0); - - return 0; -} diff --git a/data_structure/Stack Using Array.cpp b/data_structure/Stack Using Array.cpp deleted file mode 100644 index af1d57c464f..00000000000 --- a/data_structure/Stack Using Array.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include -using namespace std; - -int *stack; -int top = 0, size; - -void push(int x) -{ - if (top == size) - { - cout << "\nOverflow"; - } - else - { - stack[top++] = x; - } -} - -void pop() -{ - if (top == 0) - { - cout << "\nUnderflow"; - } - else - { - cout << "\n" - << stack[--top] << " deleted"; - } -} - -void show() -{ - for (int i = 0; i < top; i++) - { - cout << stack[i] << "\n"; - } -} - -void topmost() -{ - cout << "\nTopmost element: " << stack[top - 1]; -} -int main() -{ - cout << "\nEnter Size of stack : "; - cin >> size; - stack = new int[size]; - int ch, x; - do - { - cout << "\n1. Push"; - cout << "\n2. Pop"; - cout << "\n3. Print"; - cout << "\n4. Print topmost element:"; - cout << "\nEnter Your Choice : "; - cin >> ch; - if (ch == 1) - { - cout << "\nInsert : "; - cin >> x; - push(x); - } - else if (ch == 2) - { - pop(); - } - else if (ch == 3) - { - show(); - } - else if (ch == 4) - { - topmost(); - } - } while (ch != 0); - - return 0; -} diff --git a/data_structure/Stack Using Linked List.cpp b/data_structure/Stack Using Linked List.cpp deleted file mode 100644 index 6925cf10cf4..00000000000 --- a/data_structure/Stack Using Linked List.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -using namespace std; - -struct node -{ - int val; - node *next; -}; - -node *top; - -void push(int x) -{ - node *n = new node; - n->val = x; - n->next = top; - top = n; -} - -void pop() -{ - if (top == NULL) - { - cout << "\nUnderflow"; - } - else - { - node *t = top; - cout << "\n" - << t->val << " deleted"; - top = top->next; - delete t; - } -} - -void show() -{ - node *t = top; - while (t != NULL) - { - cout << t->val << "\n"; - t = t->next; - } -} - -int main() -{ - int ch, x; - do - { - cout << "\n1. Push"; - cout << "\n2. Pop"; - cout << "\n3. Print"; - cout << "\nEnter Your Choice : "; - cin >> ch; - if (ch == 1) - { - cout << "\nInsert : "; - cin >> x; - push(x); - } - else if (ch == 2) - { - pop(); - } - else if (ch == 3) - { - show(); - } - } while (ch != 0); - - return 0; -} diff --git a/data_structure/cll/cll.h b/data_structure/cll/cll.h deleted file mode 100644 index ae71dcd01d2..00000000000 --- a/data_structure/cll/cll.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Simple data structure CLL (Cicular Linear Linked List) - * */ -#include -#include -#include -#include - -#ifndef CLL_H -#define CLL_H -/*The data structure is a linear linked list of integers */ -struct node -{ - int data; - node * next; -}; - -class cll -{ - public: - cll(); /* Construct without parameter */ - ~cll(); - void display(); /* Show the list */ - - /****************************************************** - * Useful method for list - *******************************************************/ - void insert_front(int new_data); /* Insert a new value at head */ - void insert_tail(int new_data); /* Insert a new value at tail */ - int get_size(); /* Get total element in list */ - bool find_item(int item_to_find); /* Find an item in list */ - - /****************************************************** - * Overloading method for list - *******************************************************/ - int operator*(); /* Returns the info contained in head */ - /* Overload the pre-increment operator. - The iterator is advanced to the next node. */ - void operator++(); - - protected: - node * head; - int total; /* Total element in a list */ -}; -#endif diff --git a/data_structure/cll/main_cll.cpp b/data_structure/cll/main_cll.cpp deleted file mode 100644 index 15388b8224d..00000000000 --- a/data_structure/cll/main_cll.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "cll.h" -using namespace std; - -int main() -{ - /* Test CLL */ - cout << "----------- Test construct -----------" << endl; - cll list1; - list1.display(); - cout << "----------- Test insert front -----------" << endl; - list1.insert_front(5); - cout << "After insert 5 at front: "< -#include - -using std::cout; -using std::endl; -using std::vector; - -vector root, rnk; - -void CreateSet(int n) { - root = vector (n+1); - rnk = vector (n+1, 1); - for (int i = 1; i <= n; ++i) { - root[i] = i; - } -} - -int Find(int x) { - if (root[x] == x) { - return x; - } - return root[x] = Find(root[x]); -} - -bool InSameUnion(int x, int y) { - return Find(x) == Find(y); -} - -void Union(int x, int y) { - int a = Find(x), b = Find(y); - if (a != b) { - if (rnk[a] < rnk[b]) { - root[a] = b; - } else if (rnk[a] > rnk[b]) { - root[b] = a; - } else { - root[a] = b; - ++rnk[b]; - } - } -} - -int main() { - // tests CreateSet & Find - int n = 100; - CreateSet(n); - for (int i = 1; i <= 100; ++i) { - if (root[i] != i) { - cout << "Fail" << endl; - break; - } - } - // tests InSameUnion & Union - cout << "1 and 2 are initially not in the same subset" << endl; - if (InSameUnion(1, 2)) { - cout << "Fail" << endl; - } - Union(1, 2); - cout << "1 and 2 are now in the same subset" << endl; - if (!InSameUnion(1, 2)) { - cout << "Fail" << endl; - } - return 0; -} diff --git a/data_structure/doubly_linked_list.cpp b/data_structure/doubly_linked_list.cpp deleted file mode 100644 index 4fc38abfc28..00000000000 --- a/data_structure/doubly_linked_list.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include -#include -#include - -struct node { - int val; - node *prev; - node *next; -}*start; - -class double_linked_list { - public: - double_linked_list() { - start = NULL; - } - void insert(int x); - void remove(int x); - void search(int x); - void show(); - void reverseShow(); -}; - -void double_linked_list::insert(int x) { - node *t = start; - if (start != NULL) { - while (t->next != NULL) { - t = t->next; - } - node *n = new node; - t->next = n; - n->prev = t; - n->val = x; - n->next = NULL; - } else { - node *n = new node; - n->val = x; - n->prev = NULL; - n->next = NULL; - start = n; - } -} - -void double_linked_list::remove(int x) { - node *t = start; - while (t != NULL && t->val != x) { - t = t-> next; - } - if (t == NULL) { - return; - } - if (t->prev == NULL) { - if (t->next == NULL) { - start = NULL; - } else { - start = t->next; - start->prev = NULL; - } - } else if (t->next == NULL) { - t->prev->next = NULL; - } else { - t->prev->next = t->next; - t->next->prev = t->prev; - } - delete t; -} - -void double_linked_list::search(int x) { - node *t = start; - int found = 0; - while (t != NULL) { - if (t->val == x) { - std::cout << "\nFound"; - found = 1; - break; - } - t = t->next; - } - if (found == 0) { - std::cout << "\nNot Found"; - } -} - -void double_linked_list::show() { - node *t = start; - while (t != NULL) { - std::cout << t->val << "\t"; - t = t->next; - } -} - -void double_linked_list::reverseShow() { - node *t = start; - while (t != NULL && t->next != NULL) { - t = t->next; - } - while (t != NULL) { - std::cout << t->val << "\t"; - t = t->prev; - } -} - -int main() { - int choice, x; - double_linked_list ob; - do { - std::cout << "\n1. Insert"; - std::cout << "\n2. Delete"; - std::cout << "\n3. Search"; - std::cout << "\n4. Forward print"; - std::cout << "\n5. Reverse print"; - std::cout << "\n\nEnter you choice : "; - std::cin >> choice; - switch (choice) { - case 1: - std::cout << "\nEnter the element to be inserted : "; - std::cin >> x; - ob.insert(x); - break; - case 2: - std::cout << "\nEnter the element to be removed : "; - std::cin >> x; - ob.remove(x); - break; - case 3: - std::cout << "\nEnter the element to be searched : "; - std::cin >> x; - ob.search(x); - break; - case 4: - ob.show(); - break; - case 5: - ob.reverseShow(); - break; - } - } while (choice != 0); - return 0; -} diff --git a/data_structure/linkedList_implentation_usingArray.cpp b/data_structure/linkedList_implentation_usingArray.cpp deleted file mode 100644 index 6f8205f27e2..00000000000 --- a/data_structure/linkedList_implentation_usingArray.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* The difference between the pointer implementation of linked list and array implementation of linked list: - 1. The NULL is represented by -1; - 2. Limited size. (in the following case it is 100 nodes at max). But we can reuse the nodes that are to be deleted by again linking it bacj to the list. -*/ - -#include -using namespace std; -struct Node -{ - int data; - int next; -}; -Node AvailArray[100]; //array that will act as nodes of a linked list. -int head = -1; -int avail = 0; -void initialise_list() -{ - for (int i = 0; i <= 98; i++) - { - AvailArray[i].next = i + 1; - } - AvailArray[99].next = -1; //indicating the end of the linked list. -} - -int getnode() //This will return the index of the first free node present in the avail list -{ - int NodeIndexToBeReturned = avail; - avail = AvailArray[avail].next; - return NodeIndexToBeReturned; -} - -void freeNode(int nodeToBeDeleted) //This function when called will delete the node with the index presented as an argument, and will put back that node into the array. -{ - AvailArray[nodeToBeDeleted].next = avail; - avail = nodeToBeDeleted; -} - -void insertAtTheBeginning(int data) //The function will insert the given data into the front of the linked list. -{ - int newNode = getnode(); - AvailArray[newNode].data = data; - AvailArray[newNode].next = head; - head = newNode; -} - -void insertAtTheEnd(int data) -{ - int newNode = getnode(); - int temp = head; - while (AvailArray[temp].next != -1) - { - temp = AvailArray[temp].next; - } - //temp is now pointing to the end node. - AvailArray[newNode].data = data; - AvailArray[newNode].next = -1; - AvailArray[temp].next = newNode; -} - -void display() -{ - int temp = head; - while (temp != -1) - { - cout << AvailArray[temp].data << "->"; - temp = AvailArray[temp].next; - } - cout << "-1" << endl; - ; -} - -int main() -{ - initialise_list(); - int x, y, z; - for (;;) - { - cout << "1. Insert At The Beginning" << endl; - cout << "2. Insert At The End" << endl; - cout << "3. Display" << endl; - cout << "4.Exit" << endl; - cout << "Enter Your choice" << endl; - cin >> z; - switch (z) - { - case 1: - cout << "Enter the number you want to enter" << endl; - cin >> x; - insertAtTheBeginning(x); - break; - case 2: - cout << "Enter the number you want to enter" << endl; - cin >> y; - insertAtTheEnd(y); - break; - case 3: - cout << "The linked list contains the following element in order" << endl; - display(); - break; - case 4: - exit(0); - default: - cout << "The entered choice is not correct" << endl; - } - } -} diff --git a/data_structure/linked_list.cpp b/data_structure/linked_list.cpp deleted file mode 100644 index 64cad14f9ea..00000000000 --- a/data_structure/linked_list.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#include - -struct node { - int val; - node *next; -}; - -node *start; - -void insert(int x) { - node *t = start; - node *n = new node; - n->val = x; - n->next = NULL; - if (start != NULL) { - while (t->next != NULL) { - t = t->next; - } - t->next = n; - } else { - start = n; - } - -} - -void remove(int x) { - if (start == NULL) { - std::cout << "\nLinked List is empty\n"; - return; - } else if (start->val == x) { - node *temp = start; - start = start->next; - delete temp; - return; - } - - node *temp = start, *parent = start; - - while (temp != NULL && temp->val != x) { - parent = temp; - temp = temp->next; - } - - if (temp == NULL) { - std::cout << std::endl << x << " not found in list\n"; - return; - } - - parent->next = temp->next; - delete temp; -} - -void search(int x) { - node *t = start; - int found = 0; - while (t != NULL) { - if (t->val == x) { - std::cout << "\nFound"; - found = 1; - break; - } - t = t->next; - } - if (found == 0) { - std::cout << "\nNot Found"; - } -} - -void show() { - node *t = start; - while (t != NULL) { - std::cout << t->val << "\t"; - t = t->next; - } -} - -void reverse() { - node *first = start; - if (first != NULL) { - node *second = first->next; - while (second != NULL) { - node *tem = second->next; - second->next = first; - first = second; - second = tem; - } - start->next = NULL; - start = first; - } else { - std::cout << "\nEmpty list"; - } -} - -int main() { - int choice, x; - do { - std::cout << "\n1. Insert"; - std::cout << "\n2. Delete"; - std::cout << "\n3. Search"; - std::cout << "\n4. Print"; - std::cout << "\n5. Reverse"; - std::cout << "\n0. Exit"; - std::cout << "\n\nEnter you choice : "; - std::cin >> choice; - switch (choice) { - case 1: - std::cout << "\nEnter the element to be inserted : "; - std::cin >> x; - insert(x); - break; - case 2: - std::cout << "\nEnter the element to be removed : "; - std::cin >> x; - remove(x); - break; - case 3: - std::cout << "\nEnter the element to be searched : "; - std::cin >> x; - search(x); - break; - case 4: - show(); - std::cout << "\n"; - break; - case 5: - std::cout << "The reversed list: \n"; - reverse(); - show(); - std::cout << "\n"; - break; - } - } while (choice != 0); - - return 0; -} diff --git a/data_structure/queue/makefile b/data_structure/queue/makefile deleted file mode 100644 index 42090980475..00000000000 --- a/data_structure/queue/makefile +++ /dev/null @@ -1,11 +0,0 @@ -CC= g++ -CFLAGS = -c -Wall - -all: test_queue -queue.o: queue.cpp - $(CC) $(CFLAGS) queue.cpp -test_queue: queue.o - $(CC) test_queue.cpp queue.o -o queue - -clean: - rm *o queue diff --git a/data_structure/queue/queue.cpp b/data_structure/queue/queue.cpp deleted file mode 100644 index 728adfc1837..00000000000 --- a/data_structure/queue/queue.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include -#include "queue.h" - -using namespace std; - -/* Default constructor*/ -template -queue::queue() -{ - queueFront = NULL; - queueRear = NULL; - size = 0; -} - -/* Destructor */ -template -queue::~queue() -{ -} - -/* Display for testing */ -template -void queue::display() -{ - node *current = queueFront; - cout << "Front --> "; - while(current != NULL) { - cout<data<< " "; - current = current -> next; - } - cout < -bool queue::isEmptyQueue() -{ - return (queueFront == NULL); -} - -/* Clear queue */ -template -void queue::clear() -{ - queueFront = NULL; -} - -/* Add new item to the queue */ -template -void queue::enQueue(Kind item) -{ - node *newNode; - newNode = new node; - newNode->data = item; - newNode->next = NULL; - if (queueFront == NULL) { - queueFront = newNode; - queueRear = newNode; - } else { - queueRear->next = newNode; - queueRear = queueRear->next; - } - size++; -} - -/* Return the top element of the queue */ -template -Kind queue::front() -{ - assert(queueFront != NULL); - return queueFront->data; -} - -/* Remove the element of the queue */ -template -void queue::deQueue() -{ - node *temp; - if(!isEmptyQueue()) { - temp = queueFront; - queueFront = queueFront->next; - delete temp; - size--; - } else { - cout << "Queue is empty !" << endl; - } -} - diff --git a/data_structure/queue/queue.h b/data_structure/queue/queue.h deleted file mode 100644 index 715def1efa1..00000000000 --- a/data_structure/queue/queue.h +++ /dev/null @@ -1,34 +0,0 @@ -/* This class specifies the basic operation on a queue as a linked list */ -#ifndef QUEUE_H -#define QUEUE_H - -/* Definition of the node */ -template -struct node -{ - Kind data; - node *next; -}; - -/* Definition of the queue class */ -template -class queue -{ - public: - void display(); /* Show queue */ - queue(); /* Default constructor*/ - ~queue(); /* Destructor */ - bool isEmptyQueue(); /* Determine whether the queue is empty */ - void enQueue (Kind item); /* Add new item to the queue */ - Kind front(); /* Return the first element of the queue */ - void deQueue(); /* Remove the top element of the queue */ - void clear(); - - private: - node *queueFront; /* Pointer to the front of the queue */ - node *queueRear; /* Pointer to the rear of the queue */ - int size; -}; - -#endif - diff --git a/data_structure/queue/test_queue.cpp b/data_structure/queue/test_queue.cpp deleted file mode 100644 index caf80318cb1..00000000000 --- a/data_structure/queue/test_queue.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -#include "queue.h" -#include "queue.cpp" - -using namespace std; - -int main() -{ - queue q; - cout << "---------------------- Test construct ----------------------" << endl; - q.display(); - cout << "---------------------- Test isEmptyQueue ----------------------" << endl; - if(q.isEmptyQueue()) - cout << "PASS" < - - -struct linkedlist{ - int data; - linkedlist *next; - -}; -class stack_linkedList{ - public: - linkedlist *front; - linkedlist *rear; - - stack_linkedList(){ - front=rear=NULL; - } - void enqueue(int); - int dequeue(); - void display(); - -}; -void stack_linkedList::enqueue(int ele){ - - linkedlist *temp=new linkedlist(); - temp->data=ele; - temp->next=NULL; - - if(front==NULL) - front=rear=temp; - else{ - rear->next=temp; - rear=temp; - } -} -int stack_linkedList::dequeue(){ - linkedlist *temp; - int ele; - if(front==NULL) - std::cout<<"\nStack is empty"; - else{ - temp=front; - ele=temp->data; - if(front==rear) //if length of queue is 1; - rear=rear->next; - front=front->next; - delete(temp); - } - return ele; -} -void stack_linkedList::display(){ - - if(front==NULL) - std::cout<<"\nStack is empty"; - - else { - - linkedlist *temp; - temp=front; - while(temp!=NULL){ - std::cout<data<<" "; - temp=temp->next; - } - } -} - -int main(){ - - int op,data; - stack_linkedList ob; - std::cout<<"\n1. enqueue(Insertion) "; - std::cout<<"\n2. dequeue(Deletion)"; - std::cout<<"\n3. Display"; - std::cout<<"\n4. Exit"; - - while(1){ - std::cout<<"\nEnter your choice "; - std::cin>>op; - if(op==1) - { - std::cout<<"Enter data "; - std::cin>>data; - ob.enqueue(data); - } - else if(op==2) - data=ob.dequeue(); - else if(op==3) - ob.display(); - else if(op==4) - exit(0); - else - std::cout<<"\nWrong choice "; - - } - return 0; -} diff --git a/data_structure/stk/makefile b/data_structure/stk/makefile deleted file mode 100644 index e965d2044a6..00000000000 --- a/data_structure/stk/makefile +++ /dev/null @@ -1,13 +0,0 @@ -CC= g++ -CFLAGS = -c -Wall - -all: main test_stack -stack.o: stack.cpp - $(CC) $(CFLAGS) stack.cpp -test_stack: stack.o - $(CC) test_stack.cpp stack.o -o stk -main: stack.o - $(CC) main.cpp stack.o -o main - -clean: - rm *o stk main diff --git a/data_structure/stk/stack.cpp b/data_structure/stk/stack.cpp deleted file mode 100644 index 1e87d7c1484..00000000000 --- a/data_structure/stk/stack.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include -#include -#include "stack.h" - -using namespace std; - -/* Default constructor*/ -template -stack::stack() -{ - stackTop = NULL; - size = 0; -} - -/* Destructor */ -template -stack::~stack() -{ -} - -/* Display for testing */ -template -void stack::display() -{ - node *current = stackTop; - cout << "Top --> "; - while(current != NULL) { - cout<data<< " "; - current = current -> next; - } - cout < -bool stack::isEmptyStack() -{ - return (stackTop == NULL); -} - -/* Clear stack */ -template -void stack::clear() -{ - stackTop = NULL; -} - -/* Add new item to the stack */ -template -void stack::push(Type item) -{ - node *newNode; - newNode = new node; - newNode->data = item; - newNode->next = stackTop; - stackTop = newNode; - size++; -} - -/* Return the top element of the stack */ -template -Type stack::top() -{ - assert(stackTop != NULL); - return stackTop->data; -} - -/* Remove the top element of the stack */ -template -void stack::pop() -{ - node *temp; - if(!isEmptyStack()) { - temp = stackTop; - stackTop = stackTop->next; - delete temp; - size--; - } else { - cout << "Stack is empty !" << endl; - } -} - -/* Operator "=" */ -template -stack stack::operator=(stack & otherStack) -{ - node *newNode, *current, *last; - - if (stackTop != NULL) /* If stack is no empty, make it empty */ - stackTop = NULL; - if (otherStack.stackTop == NULL) - stackTop = NULL; - else { - current = otherStack.stackTop; - stackTop = new node; - stackTop->data = current->data; - stackTop->next = NULL; - last = stackTop; - current = current ->next; - /* Copy the remaining stack */ - while (current != NULL) - { - newNode = new node; - newNode->data = current->data; - newNode->next = NULL; - last->next = newNode; - last = newNode; - current = current->next; - } - } - size = otherStack.size; - return *this; -} diff --git a/data_structure/stk/stack.h b/data_structure/stk/stack.h deleted file mode 100644 index a9366948216..00000000000 --- a/data_structure/stk/stack.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This class specifies the basic operation on a stack as a linked list */ -#ifndef STACK_H -#define STACK_H - -/* Definition of the node */ -template -struct node -{ - Type data; - node *next; -}; - -/* Definition of the stack class */ -template -class stack -{ - public: - void display(); /* Show stack */ - stack(); /* Default constructor*/ - ~stack(); /* Destructor */ - bool isEmptyStack(); /* Determine whether the stack is empty */ - void push (Type item); /* Add new item to the stack */ - Type top(); /* Return the top element of the stack */ - void pop(); /* Remove the top element of the stack */ - void clear(); - - stack operator=(stack & otherStack); - // Overload "=" the assignment operator. - private: - node *stackTop; /* Pointer to the stack */ - int size; -}; - -#endif - diff --git a/data_structure/stk/test_stack.cpp b/data_structure/stk/test_stack.cpp deleted file mode 100644 index 4703fc906ae..00000000000 --- a/data_structure/stk/test_stack.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include "stack.h" -#include "stack.cpp" - -using namespace std; - -int main() -{ - stack stk; - cout << "---------------------- Test construct ----------------------" << endl; - stk.display(); - cout << "---------------------- Test isEmptyStack ----------------------" << endl; - if(stk.isEmptyStack()) - cout << "PASS" < stk1; - cout << "stk current: "<< endl; - stk.display(); - cout << endl << "Assign stk1 = stk "<< endl; - stk1 = stk; - stk1.display(); - cout << endl<< "After pushing 8 9 10 into stk1:" < -#include - -#include -#include - -// structure definition -typedef struct trie { - struct trie * arr[26]; - bool isEndofWord; -} trie; - -// create a new node for trie -trie * createNode() { - trie * nn = new trie(); - for (int i = 0; i < 26; i++) - nn -> arr[i] = NULL; - nn -> isEndofWord = false; - return nn; -} - -// insert string into the trie -void insert(trie * root, std::string str) { - for (int i = 0; i < str.length(); i++) { - int j = str[i] - 'a'; - if (root -> arr[j]) { - root = root -> arr[j]; - } else { - root -> arr[j] = createNode(); - root = root -> arr[j]; - } - } - root -> isEndofWord = true; -} - -// search a string exists inside the trie -bool search(trie * root, std::string str, int index) { - if (index == str.length()) { - if (!root -> isEndofWord) - return false; - return true; - } - int j = str[index] - 'a'; - if (!root -> arr[j]) - return false; - return search(root -> arr[j], str, index + 1); -} - -/* -removes the string if it is not a prefix of any other -string, if it is then just sets the endofword to false, else -removes the given string -*/ -bool deleteString(trie * root, std::string str, int index) { - if (index == str.length()) { - if (!root -> isEndofWord) - return false; - root -> isEndofWord = false; - for (int i = 0; i < 26; i++) - return false; - return true; - } - int j = str[index] - 'a'; - if (!root -> arr[j]) - return false; - bool - var = deleteString(root, str, index + 1); - if (var) { - root -> arr[j] = NULL; - if (root -> isEndofWord) { - return false; - } else { - int i; - for (i = 0; i < 26; i++) - if (root -> arr[i]) - return false; - return true; - } - } -} - -int main() { - trie * root = createNode(); - insert(root, "hello"); - insert(root, "world"); - int a = search(root, "hello", 0); - int b = search(root, "word", 0); - printf("%d %d ", a, b); - return 0; -} diff --git a/data_structures/CMakeLists.txt b/data_structures/CMakeLists.txt new file mode 100644 index 00000000000..6c0555148be --- /dev/null +++ b/data_structures/CMakeLists.txt @@ -0,0 +1,20 @@ +# If necessary, use the RELATIVE flag, otherwise each source file may be listed +# with full pathname. RELATIVE may makes it easier to extract an executable name +# automatically. +file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) +# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) +foreach( testsourcefile ${APP_SOURCES} ) + # I used a simple string replace, to cut off .cpp. + string( REPLACE ".cpp" "" testname ${testsourcefile} ) + add_executable( ${testname} ${testsourcefile} ) + + set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) + if(OpenMP_CXX_FOUND) + target_link_libraries(${testname} OpenMP::OpenMP_CXX) + endif() + install(TARGETS ${testname} DESTINATION "bin/data_structures") + +endforeach( testsourcefile ${APP_SOURCES} ) + +add_subdirectory(cll) diff --git a/data_structures/avltree.cpp b/data_structures/avltree.cpp new file mode 100644 index 00000000000..836f0f6677c --- /dev/null +++ b/data_structures/avltree.cpp @@ -0,0 +1,148 @@ +/** + * \file + * \brief A simple tree implementation using nodes + * + * \todo update code to use C++ STL library features and OO structure + * \warning This program is a poor implementation and does not utilize any of + * the C++ STL features. + */ +#include +#include +#include + +typedef struct node { + int data; + int height; + struct node *left; + struct node *right; +} node; + +/** Create and return a new Node */ +node *createNode(int data) { + node *nn = new node(); + nn->data = data; + nn->height = 0; + nn->left = NULL; + nn->right = NULL; + return nn; +} + +/** Returns height of tree */ +int height(node *root) { + if (root == NULL) + return 0; + return 1 + std::max(height(root->left), height(root->right)); +} + +/** Returns difference between height of left and right subtree */ +int getBalance(node *root) { return height(root->left) - height(root->right); } + +/** Returns Node after Right Rotation */ +node *rightRotate(node *root) { + node *t = root->left; + node *u = t->right; + t->right = root; + root->left = u; + return t; +} + +/** Returns Node after Left Rotation */ +node *leftRotate(node *root) { + node *t = root->right; + node *u = t->left; + t->left = root; + root->right = u; + return t; +} + +/** Returns node with minimum value in the tree */ +node *minValue(node *root) { + if (root->left == NULL) + return root; + return minValue(root->left); +} + +/** Balanced Insertion */ +node *insert(node *root, int item) { + node *nn = createNode(item); + if (root == NULL) + return nn; + if (item < root->data) + root->left = insert(root->left, item); + else + root->right = insert(root->right, item); + int b = getBalance(root); + if (b > 1) { + if (getBalance(root->left) < 0) + root->left = leftRotate(root->left); // Left-Right Case + return rightRotate(root); // Left-Left Case + } else if (b < -1) { + if (getBalance(root->right) > 0) + root->right = rightRotate(root->right); // Right-Left Case + return leftRotate(root); // Right-Right Case + } + return root; +} + +/** Balanced Deletion */ +node *deleteNode(node *root, int key) { + if (root == NULL) + return root; + if (key < root->data) + root->left = deleteNode(root->left, key); + else if (key > root->data) + root->right = deleteNode(root->right, key); + + else { + // Node to be deleted is leaf node or have only one Child + if (!root->right) { + node *temp = root->left; + delete (root); + root = NULL; + return temp; + } else if (!root->left) { + node *temp = root->right; + delete (root); + root = NULL; + return temp; + } + // Node to be deleted have both left and right subtrees + node *temp = minValue(root->right); + root->data = temp->data; + root->right = deleteNode(root->right, temp->data); + } + // Balancing Tree after deletion + return root; +} + +/** LevelOrder (Breadth First Search) */ +void levelOrder(node *root) { + std::queue q; + q.push(root); + while (!q.empty()) { + root = q.front(); + std::cout << root->data << " "; + q.pop(); + if (root->left) + q.push(root->left); + if (root->right) + q.push(root->right); + } +} + +/** Main function */ +int main() { + // Testing AVL Tree + node *root = NULL; + int i; + for (i = 1; i <= 7; i++) root = insert(root, i); + std::cout << "LevelOrder: "; + levelOrder(root); + root = deleteNode(root, 1); // Deleting key with value 1 + std::cout << "\nLevelOrder: "; + levelOrder(root); + root = deleteNode(root, 4); // Deletin key with value 4 + std::cout << "\nLevelOrder: "; + levelOrder(root); + return 0; +} diff --git a/data_structures/binary_search_tree.cpp b/data_structures/binary_search_tree.cpp new file mode 100644 index 00000000000..947bb53d843 --- /dev/null +++ b/data_structures/binary_search_tree.cpp @@ -0,0 +1,174 @@ +/** + * \file + * \brief A simple tree implementation using structured nodes + * + * \todo update code to use C++ STL library features and OO structure + * \warning This program is a poor implementation - C style - and does not + * utilize any of the C++ STL features. + */ +#include + +struct node { + int val; + node *left; + node *right; +}; + +struct queue { + node *t[100]; + int front; + int rear; +}; + +queue q; + +void enqueue(node *n) { q.t[q.rear++] = n; } + +node *dequeue() { return (q.t[q.front++]); } + +void Insert(node *n, int x) { + if (x < n->val) { + if (n->left == NULL) { + node *temp = new node; + temp->val = x; + temp->left = NULL; + temp->right = NULL; + n->left = temp; + } else { + Insert(n->left, x); + } + } else { + if (n->right == NULL) { + node *temp = new node; + temp->val = x; + temp->left = NULL; + temp->right = NULL; + n->left = temp; + } else { + Insert(n->right, x); + } + } +} + +int findMaxInLeftST(node *n) { + while (n->right != NULL) { + n = n->right; + } + return n->val; +} + +void Remove(node *p, node *n, int x) { + if (n->val == x) { + if (n->right == NULL && n->left == NULL) { + if (x < p->val) { + p->right = NULL; + } else { + p->left = NULL; + } + } else if (n->right == NULL) { + if (x < p->val) { + p->right = n->left; + } else { + p->left = n->left; + } + } else if (n->left == NULL) { + if (x < p->val) { + p->right = n->right; + } else { + p->left = n->right; + } + } else { + int y = findMaxInLeftST(n->left); + n->val = y; + Remove(n, n->right, y); + } + } else if (x < n->val) { + Remove(n, n->left, x); + } else { + Remove(n, n->right, x); + } +} + +void BFT(node *n) { + if (n != NULL) { + std::cout << n->val << " "; + enqueue(n->left); + enqueue(n->right); + BFT(dequeue()); + } +} + +void Pre(node *n) { + if (n != NULL) { + std::cout << n->val << " "; + Pre(n->left); + Pre(n->right); + } +} + +void In(node *n) { + if (n != NULL) { + In(n->left); + std::cout << n->val << " "; + In(n->right); + } +} + +void Post(node *n) { + if (n != NULL) { + Post(n->left); + Post(n->right); + std::cout << n->val << " "; + } +} + +int main() { + q.front = 0; + q.rear = 0; + int value; + int ch; + node *root = new node; + std::cout << "\nEnter the value of root node :"; + std::cin >> value; + root->val = value; + root->left = NULL; + root->right = NULL; + do { + std::cout << "\n1. Insert" + << "\n2. Delete" + << "\n3. Breadth First" + << "\n4. Preorder Depth First" + << "\n5. Inorder Depth First" + << "\n6. Postorder Depth First"; + + std::cout << "\nEnter Your Choice : "; + 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; + } + } while (ch != 0); + + return 0; +} diff --git a/data_structures/binaryheap.cpp b/data_structures/binaryheap.cpp new file mode 100644 index 00000000000..72e56e91ad3 --- /dev/null +++ b/data_structures/binaryheap.cpp @@ -0,0 +1,144 @@ +/** + * \file + * \brief A C++ program to demonstrate common Binary Heap Operations + */ +#include +#include +#include + +/** A class for Min Heap */ +class MinHeap { + int *harr; ///< pointer to array of elements in heap + int capacity; ///< maximum possible size of min heap + int heap_size; ///< Current number of elements in min heap + + public: + /** Constructor + * \param[in] capacity initial heap capacity + */ + MinHeap(int capacity); + + /** to heapify a subtree with the root at given index + */ + void MinHeapify(int); + + int parent(int i) { return (i - 1) / 2; } + + /** to get index of left child of node at index i */ + int left(int i) { return (2 * i + 1); } + + /** to get index of right child of node at index i */ + int right(int i) { return (2 * i + 2); } + + /** to extract the root which is the minimum element */ + int extractMin(); + + /** Decreases key value of key at index i to new_val */ + void decreaseKey(int i, int new_val); + + /** Returns the minimum key (key at root) from min heap */ + int getMin() { return harr[0]; } + + /** Deletes a key stored at index i */ + void deleteKey(int i); + + /** Inserts a new key 'k' */ + void insertKey(int k); +}; + +/** Constructor: Builds a heap from a given array a[] of given size */ +MinHeap::MinHeap(int cap) { + heap_size = 0; + capacity = cap; + harr = new int[cap]; +} + +// Inserts a new key 'k' +void MinHeap::insertKey(int k) { + if (heap_size == capacity) { + std::cout << "\nOverflow: Could not insertKey\n"; + return; + } + + // First insert the new key at the end + heap_size++; + int i = heap_size - 1; + harr[i] = k; + + // Fix the min heap property if it is violated + while (i != 0 && harr[parent(i)] > harr[i]) { + std::swap(harr[i], harr[parent(i)]); + i = parent(i); + } +} + +/** Decreases value of key at index 'i' to new_val. It is assumed that new_val + * is smaller than harr[i]. + */ +void MinHeap::decreaseKey(int i, int new_val) { + harr[i] = new_val; + while (i != 0 && harr[parent(i)] > harr[i]) { + std::swap(harr[i], harr[parent(i)]); + i = parent(i); + } +} + +// Method to remove minimum element (or root) from min heap +int MinHeap::extractMin() { + if (heap_size <= 0) + return INT_MAX; + if (heap_size == 1) { + heap_size--; + return harr[0]; + } + + // Store the minimum value, and remove it from heap + int root = harr[0]; + harr[0] = harr[heap_size - 1]; + heap_size--; + MinHeapify(0); + + return root; +} + +/** This function deletes key at index i. It first reduced value to minus + * infinite, then calls extractMin() + */ +void MinHeap::deleteKey(int i) { + decreaseKey(i, INT_MIN); + extractMin(); +} + +/** A recursive method to heapify a subtree with the root at given index + * This method assumes that the subtrees are already heapified + */ +void MinHeap::MinHeapify(int i) { + int l = left(i); + int r = right(i); + int smallest = i; + if (l < heap_size && harr[l] < harr[i]) + smallest = l; + if (r < heap_size && harr[r] < harr[smallest]) + smallest = r; + if (smallest != i) { + std::swap(harr[i], harr[smallest]); + MinHeapify(smallest); + } +} + +// Driver program to test above functions +int main() { + MinHeap h(11); + h.insertKey(3); + h.insertKey(2); + h.deleteKey(1); + h.insertKey(15); + h.insertKey(5); + h.insertKey(4); + h.insertKey(45); + std::cout << h.extractMin() << " "; + std::cout << h.getMin() << " "; + h.decreaseKey(2, 1); + std::cout << h.getMin(); + return 0; +} diff --git a/data_structure/circular_Queue_using_Linked_List.cpp b/data_structures/circular_queue_using_linked_list.cpp similarity index 70% rename from data_structure/circular_Queue_using_Linked_List.cpp rename to data_structures/circular_queue_using_linked_list.cpp index 4b1ec476c3d..5d6484ce396 100644 --- a/data_structure/circular_Queue_using_Linked_List.cpp +++ b/data_structures/circular_queue_using_linked_list.cpp @@ -1,24 +1,19 @@ #include -using namespace std; -struct node -{ +struct node { int data; struct node *next; }; -class Queue -{ +class Queue { node *front; node *rear; -public: - Queue() - { + public: + Queue() { front = NULL; rear = NULL; } - void createNode(int val) - { + void createNode(int val) { node *ptr; node *nn; nn = new node; @@ -28,14 +23,10 @@ class Queue front = nn; rear = nn; } - void enqueue(int val) - { - if (front == NULL || rear == NULL) - { + void enqueue(int val) { + if (front == NULL || rear == NULL) { createNode(val); - } - else - { + } else { node *ptr; node *nn; ptr = front; @@ -46,28 +37,23 @@ class Queue rear = nn; } } - void dequeue() - { + void dequeue() { node *n; n = front; front = front->next; delete (n); } - void traverse() - { + void traverse() { node *ptr; ptr = front; - do - { - cout << ptr->data << " "; + do { + std::cout << ptr->data << " "; ptr = ptr->next; } while (ptr != rear->next); - cout << front->data; - cout << endl; + std::cout << front->data << std::endl; } }; -int main(void) -{ +int main(void) { Queue q; q.enqueue(10); q.enqueue(20); diff --git a/data_structures/cll/CMakeLists.txt b/data_structures/cll/CMakeLists.txt new file mode 100644 index 00000000000..cb18eb3475f --- /dev/null +++ b/data_structures/cll/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable( cll + cll.cpp + main_cll.cpp +) +install(TARGETS cll DESTINATION "bin/data_structures") diff --git a/data_structure/cll/cll.cpp b/data_structures/cll/cll.cpp similarity index 68% rename from data_structure/cll/cll.cpp rename to data_structures/cll/cll.cpp index efc068f3c6a..42bc9067e20 100644 --- a/data_structure/cll/cll.cpp +++ b/data_structures/cll/cll.cpp @@ -5,49 +5,42 @@ using namespace std; /* Constructor */ -cll::cll() -{ +cll::cll() { head = NULL; total = 0; } -cll::~cll() -{ - /* Desstructure, no need to fill */ +cll::~cll() { /* Desstructure, no need to fill */ } /* Display a list. and total element */ -void cll::display() -{ +void cll::display() { if (head == NULL) cout << "List is empty !" << endl; - else - { + else { cout << "CLL list: "; node *current = head; - for (int i = 0; i < total; i++) - { + for (int i = 0; i < total; i++) { cout << current->data << " -> "; - current = current ->next; + current = current->next; } cout << head->data << endl; - cout << "Total element: "<< total <data = new_data; newNode->next = NULL; - if(head==NULL) { + if (head == NULL) { head = newNode; - head -> next = head; + head->next = head; } else { node *current = head; - while (current -> next != head) { + while (current->next != head) { current = current->next; } newNode->next = head; @@ -58,18 +51,17 @@ void cll::insert_front(int new_data) } /* List insert a new value at head in list */ -void cll::insert_tail(int new_data) -{ +void cll::insert_tail(int new_data) { node *newNode; newNode = new node; newNode->data = new_data; newNode->next = NULL; - if(head==NULL) { + if (head == NULL) { head = newNode; - head -> next = head; + head->next = head; } else { node *current = head; - while (current -> next != head) { + while (current->next != head) { current = current->next; } current->next = newNode; @@ -79,22 +71,17 @@ void cll::insert_tail(int new_data) } /* Get total element in list */ -int cll::get_size() -{ - return total; -} - +int cll::get_size() { return total; } /* Return true if the requested item (sent in as an argument) is in the list, otherwise return false */ -bool cll::find_item(int item_to_find) -{ +bool cll::find_item(int item_to_find) { if (head == NULL) { cout << "List is empty !" << endl; return false; } else { node *current = head; - while (current -> next != head) { + while (current->next != head) { if (current->data == item_to_find) return true; current = current->next; @@ -104,24 +91,20 @@ bool cll::find_item(int item_to_find) } /* Overloading method*/ -int cll::operator*() -{ - return head->data; -} +int cll::operator*() { return head->data; } /* Overload the pre-increment operator. The iterator is advanced to the next node. */ -void cll::operator++() -{ +void cll::operator++() { if (head == NULL) { cout << "List is empty !" << endl; } else { node *current = head; - while (current -> next != head) { - current = current -> next; + while (current->next != head) { + current = current->next; } - current->next = head -> next; - head = head -> next; + current->next = head->next; + head = head->next; } total--; } diff --git a/data_structures/cll/cll.h b/data_structures/cll/cll.h new file mode 100644 index 00000000000..a1a9b4d925d --- /dev/null +++ b/data_structures/cll/cll.h @@ -0,0 +1,43 @@ +/* + * Simple data structure CLL (Cicular Linear Linked List) + * */ +#include +#include +#include +#include + +#ifndef CLL_H +#define CLL_H +/*The data structure is a linear linked list of integers */ +struct node { + int data; + node* next; +}; + +class cll { + public: + cll(); /* Construct without parameter */ + ~cll(); + void display(); /* Show the list */ + + /****************************************************** + * Useful method for list + *******************************************************/ + void insert_front(int new_data); /* Insert a new value at head */ + void insert_tail(int new_data); /* Insert a new value at tail */ + int get_size(); /* Get total element in list */ + bool find_item(int item_to_find); /* Find an item in list */ + + /****************************************************** + * Overloading method for list + *******************************************************/ + int operator*(); /* Returns the info contained in head */ + /* Overload the pre-increment operator. + The iterator is advanced to the next node. */ + void operator++(); + + protected: + node* head; + int total; /* Total element in a list */ +}; +#endif diff --git a/data_structures/cll/main_cll.cpp b/data_structures/cll/main_cll.cpp new file mode 100644 index 00000000000..0b6bfd3edef --- /dev/null +++ b/data_structures/cll/main_cll.cpp @@ -0,0 +1,43 @@ +#include "cll.h" +using namespace std; + +int main() { + /* Test CLL */ + cout << "----------- Test construct -----------" << endl; + cll list1; + list1.display(); + cout << "----------- Test insert front -----------" << endl; + list1.insert_front(5); + cout << "After insert 5 at front: " << endl; + list1.display(); + cout << "After insert 10 3 7 at front: " << endl; + list1.insert_front(10); + list1.insert_front(3); + list1.insert_front(7); + list1.display(); + cout << "----------- Test insert tail -----------" << endl; + cout << "After insert 18 19 20 at tail: " << endl; + list1.insert_tail(18); + list1.insert_tail(19); + list1.insert_tail(20); + list1.display(); + cout << "----------- Test find item -----------" << endl; + if (list1.find_item(10)) + cout << "PASS" << endl; + else + cout << "FAIL" << endl; + if (!list1.find_item(30)) + cout << "PASS" << endl; + else + cout << "FAIL" << endl; + cout << "----------- Test * operator -----------" << endl; + int value = *list1; + cout << "Value at *list1: " << value << endl; + cout << "----------- Test ++ operator -----------" << endl; + list1.display(); + ++list1; + cout << "After ++list1: " << endl; + list1.display(); + + return 0; +} diff --git a/data_structures/disjoint_set.cpp b/data_structures/disjoint_set.cpp new file mode 100644 index 00000000000..dd70e4cea1d --- /dev/null +++ b/data_structures/disjoint_set.cpp @@ -0,0 +1,62 @@ +#include +#include + +using std::cout; +using std::endl; +using std::vector; + +vector root, rnk; + +void CreateSet(int n) { + root = vector(n + 1); + rnk = vector(n + 1, 1); + for (int i = 1; i <= n; ++i) { + root[i] = i; + } +} + +int Find(int x) { + if (root[x] == x) { + return x; + } + return root[x] = Find(root[x]); +} + +bool InSameUnion(int x, int y) { return Find(x) == Find(y); } + +void Union(int x, int y) { + int a = Find(x), b = Find(y); + if (a != b) { + if (rnk[a] < rnk[b]) { + root[a] = b; + } else if (rnk[a] > rnk[b]) { + root[b] = a; + } else { + root[a] = b; + ++rnk[b]; + } + } +} + +int main() { + // tests CreateSet & Find + int n = 100; + CreateSet(n); + for (int i = 1; i <= 100; ++i) { + if (root[i] != i) { + cout << "Fail" << endl; + break; + } + } + // tests InSameUnion & Union + cout << "1 and 2 are initially not in the same subset" << endl; + if (InSameUnion(1, 2)) { + cout << "Fail" << endl; + } + Union(1, 2); + cout << "1 and 2 are now in the same subset" << endl; + if (!InSameUnion(1, 2)) { + cout << "Fail" << endl; + } + return 0; +} diff --git a/data_structures/doubly_linked_list.cpp b/data_structures/doubly_linked_list.cpp new file mode 100644 index 00000000000..30cc257d84f --- /dev/null +++ b/data_structures/doubly_linked_list.cpp @@ -0,0 +1,136 @@ +#include +#include +#include + +struct node { + int val; + node *prev; + node *next; +} * start; + +class double_linked_list { + public: + double_linked_list() { start = NULL; } + void insert(int x); + void remove(int x); + void search(int x); + void show(); + void reverseShow(); +}; + +void double_linked_list::insert(int x) { + node *t = start; + if (start != NULL) { + while (t->next != NULL) { + t = t->next; + } + node *n = new node; + t->next = n; + n->prev = t; + n->val = x; + n->next = NULL; + } else { + node *n = new node; + n->val = x; + n->prev = NULL; + n->next = NULL; + start = n; + } +} + +void double_linked_list::remove(int x) { + node *t = start; + while (t != NULL && t->val != x) { + t = t->next; + } + if (t == NULL) { + return; + } + if (t->prev == NULL) { + if (t->next == NULL) { + start = NULL; + } else { + start = t->next; + start->prev = NULL; + } + } else if (t->next == NULL) { + t->prev->next = NULL; + } else { + t->prev->next = t->next; + t->next->prev = t->prev; + } + delete t; +} + +void double_linked_list::search(int x) { + node *t = start; + int found = 0; + while (t != NULL) { + if (t->val == x) { + std::cout << "\nFound"; + found = 1; + break; + } + t = t->next; + } + if (found == 0) { + std::cout << "\nNot Found"; + } +} + +void double_linked_list::show() { + node *t = start; + while (t != NULL) { + std::cout << t->val << "\t"; + t = t->next; + } +} + +void double_linked_list::reverseShow() { + node *t = start; + while (t != NULL && t->next != NULL) { + t = t->next; + } + while (t != NULL) { + std::cout << t->val << "\t"; + t = t->prev; + } +} + +int main() { + int choice, x; + double_linked_list ob; + do { + std::cout << "\n1. Insert"; + std::cout << "\n2. Delete"; + std::cout << "\n3. Search"; + std::cout << "\n4. Forward print"; + std::cout << "\n5. Reverse print"; + std::cout << "\n\nEnter you choice : "; + std::cin >> choice; + switch (choice) { + case 1: + std::cout << "\nEnter the element to be inserted : "; + std::cin >> x; + ob.insert(x); + break; + case 2: + std::cout << "\nEnter the element to be removed : "; + std::cin >> x; + ob.remove(x); + break; + case 3: + std::cout << "\nEnter the element to be searched : "; + std::cin >> x; + ob.search(x); + break; + case 4: + ob.show(); + break; + case 5: + ob.reverseShow(); + break; + } + } while (choice != 0); + return 0; +} diff --git a/data_structures/linked_list.cpp b/data_structures/linked_list.cpp new file mode 100644 index 00000000000..8eb6e586d5a --- /dev/null +++ b/data_structures/linked_list.cpp @@ -0,0 +1,134 @@ +#include + +struct node { + int val; + node *next; +}; + +node *start; + +void insert(int x) { + node *t = start; + node *n = new node; + n->val = x; + n->next = NULL; + if (start != NULL) { + while (t->next != NULL) { + t = t->next; + } + t->next = n; + } else { + start = n; + } +} + +void remove(int x) { + if (start == NULL) { + std::cout << "\nLinked List is empty\n"; + return; + } else if (start->val == x) { + node *temp = start; + start = start->next; + delete temp; + return; + } + + node *temp = start, *parent = start; + + while (temp != NULL && temp->val != x) { + parent = temp; + temp = temp->next; + } + + if (temp == NULL) { + std::cout << std::endl << x << " not found in list\n"; + return; + } + + parent->next = temp->next; + delete temp; +} + +void search(int x) { + node *t = start; + int found = 0; + while (t != NULL) { + if (t->val == x) { + std::cout << "\nFound"; + found = 1; + break; + } + t = t->next; + } + if (found == 0) { + std::cout << "\nNot Found"; + } +} + +void show() { + node *t = start; + while (t != NULL) { + std::cout << t->val << "\t"; + t = t->next; + } +} + +void reverse() { + node *first = start; + if (first != NULL) { + node *second = first->next; + while (second != NULL) { + node *tem = second->next; + second->next = first; + first = second; + second = tem; + } + start->next = NULL; + start = first; + } else { + std::cout << "\nEmpty list"; + } +} + +int main() { + int choice, x; + do { + std::cout << "\n1. Insert"; + std::cout << "\n2. Delete"; + std::cout << "\n3. Search"; + std::cout << "\n4. Print"; + std::cout << "\n5. Reverse"; + std::cout << "\n0. Exit"; + std::cout << "\n\nEnter you choice : "; + std::cin >> choice; + switch (choice) { + case 1: + std::cout << "\nEnter the element to be inserted : "; + std::cin >> x; + insert(x); + break; + case 2: + std::cout << "\nEnter the element to be removed : "; + std::cin >> x; + remove(x); + break; + case 3: + std::cout << "\nEnter the element to be searched : "; + std::cin >> x; + search(x); + break; + case 4: + show(); + std::cout << "\n"; + break; + case 5: + std::cout << "The reversed list: \n"; + reverse(); + show(); + std::cout << "\n"; + break; + } + } while (choice != 0); + + return 0; +} diff --git a/data_structures/linkedlist_implentation_usingarray.cpp b/data_structures/linkedlist_implentation_usingarray.cpp new file mode 100644 index 00000000000..75d400d72ea --- /dev/null +++ b/data_structures/linkedlist_implentation_usingarray.cpp @@ -0,0 +1,114 @@ +/** + * \file + * \brief Linked list implementation using Arrays + * + * The difference between the pointer implementation of linked list and array + * implementation of linked list: + * 1. The NULL is represented by -1; + * 2. Limited size. (in the following case it is 100 nodes at max). But we can + * reuse the nodes that are to be deleted by again linking it bacj to the list. + */ + +#include + +struct Node { + int data; + int next; +}; + +Node AvailArray[100]; ///< array that will act as nodes of a linked list. + +int head = -1; +int avail = 0; +void initialise_list() { + for (int i = 0; i <= 98; i++) { + AvailArray[i].next = i + 1; + } + AvailArray[99].next = -1; // indicating the end of the linked list. +} + +/** This will return the index of the first free node present in the avail list + */ +int getnode() { + int NodeIndexToBeReturned = avail; + avail = AvailArray[avail].next; + return NodeIndexToBeReturned; +} + +/** This function when called will delete the node with + * the index presented as an argument, and will put + * back that node into the array. + */ +void freeNode(int nodeToBeDeleted) { + AvailArray[nodeToBeDeleted].next = avail; + avail = nodeToBeDeleted; +} + +/** The function will insert the given data + * into the front of the linked list. + */ +void insertAtTheBeginning(int data) { + int newNode = getnode(); + AvailArray[newNode].data = data; + AvailArray[newNode].next = head; + head = newNode; +} + +void insertAtTheEnd(int data) { + int newNode = getnode(); + int temp = head; + while (AvailArray[temp].next != -1) { + temp = AvailArray[temp].next; + } + // temp is now pointing to the end node. + AvailArray[newNode].data = data; + AvailArray[newNode].next = -1; + AvailArray[temp].next = newNode; +} + +void display() { + int temp = head; + while (temp != -1) { + std::cout << AvailArray[temp].data << "->"; + temp = AvailArray[temp].next; + } + std::cout << "-1" << std::endl; +} + +/** Main function */ +int main() { + initialise_list(); + int x, y, z; + for (;;) { + std::cout << "1. Insert At The Beginning" << std::endl; + std::cout << "2. Insert At The End" << std::endl; + std::cout << "3. Display" << std::endl; + std::cout << "4.Exit" << std::endl; + std::cout << "Enter Your choice" << std::endl; + std::cin >> z; + switch (z) { + case 1: + std::cout << "Enter the number you want to enter" << std::endl; + std::cin >> x; + insertAtTheBeginning(x); + break; + case 2: + std::cout << "Enter the number you want to enter" << std::endl; + std::cin >> y; + insertAtTheEnd(y); + break; + case 3: + std::cout + << "The linked list contains the following element in order" + << std::endl; + display(); + break; + case 4: + return 0; + default: + std::cout << "The entered choice is not correct" << std::endl; + } + } + + return 0; +} diff --git a/data_structures/list_array.cpp b/data_structures/list_array.cpp new file mode 100644 index 00000000000..c796ffef91c --- /dev/null +++ b/data_structures/list_array.cpp @@ -0,0 +1,153 @@ +#include +using namespace std; + +struct list { + int data[50]; + int top = 0; + bool isSorted = false; + + int BinarySearch(int *array, int first, int last, int x) { + if (last < first) { + return -1; + } + int mid = (first + last) / 2; + if (array[mid] == x) + return mid; + else if (x < array[mid]) + return (BinarySearch(array, first, mid - 1, x)); + else if (x > array[mid]) + return (BinarySearch(array, mid + 1, last, x)); + } + + int LinarSearch(int *array, int x) { + for (int i = 0; i < top; i++) { + if (array[i] == x) { + return i; + } + } + + return -1; + } + + int Search(int x) { + int pos = -1; + + if (isSorted) { + pos = BinarySearch(data, 0, top - 1, x); + } + + else { + pos = LinarSearch(data, x); + } + + if (pos != -1) { + cout << "\nElement found at position : " << pos; + } else { + cout << "\nElement not found"; + } + return pos; + } + + void Sort() { + int i, j, pos; + for (i = 0; i < top; i++) { + int min = data[i]; + for (j = i + 1; j < top; j++) { + if (data[j] < min) { + pos = j; + min = data[pos]; + } + } + + int temp = data[i]; + data[i] = data[pos]; + data[pos] = temp; + } + isSorted = true; + } + + void insert(int x) { + if (!isSorted) { + if (top == 49) { + cout << "\nOverflow"; + } else { + data[top] = x; + top++; + } + } + + else { + int pos = 0; + + for (int i = 0; i < top - 1; i++) { + if (data[i] <= x && x <= data[i + 1]) { + pos = i + 1; + break; + } + } + if (pos == 0) { + pos = top - 1; + } + + for (int i = top; i > pos; i--) { + data[i] = data[i - 1]; + } + top++; + data[pos] = x; + } + } + + void Remove(int x) { + int pos = Search(x); + cout << "\n" << data[pos] << " deleted"; + for (int i = pos; i < top; i++) { + data[i] = data[i + 1]; + } + top--; + } + + void Show() { + for (int i = 0; i < top; i++) { + cout << data[i] << "\t"; + } + } +}; + +int main() { + list L; + int choice; + int x; + do { + cout << "\n1.Insert"; + cout << "\n2.Delete"; + cout << "\n3.Search"; + cout << "\n4.Sort"; + cout << "\n5.Print"; + cout << "\n\nEnter Your Choice : "; + cin >> choice; + switch (choice) { + case 1: + cout << "\nEnter the element to be inserted : "; + cin >> x; + L.insert(x); + break; + case 2: + cout << "\nEnter the element to be removed : "; + cin >> x; + L.Remove(x); + break; + case 3: + cout << "\nEnter the element to be searched : "; + cin >> x; + L.Search(x); + break; + case 4: + L.Sort(); + break; + case 5: + L.Show(); + break; + } + } while (choice != 0); + return 0; +} diff --git a/data_structures/morrisinorder.cpp b/data_structures/morrisinorder.cpp new file mode 100644 index 00000000000..f1f9e068c9f --- /dev/null +++ b/data_structures/morrisinorder.cpp @@ -0,0 +1,92 @@ +#include +#include + +/************************** + @author shrutisheoran +**************************/ + +using namespace std; + +struct Btree { + int data; + struct Btree *left; // Pointer to left subtree + struct Btree *right; // Pointer to right subtree +}; + +void insert(Btree **root, int d) { + Btree *nn = new Btree(); // Creating new node + nn->data = d; + nn->left = NULL; + nn->right = NULL; + if (*root == NULL) { + *root = nn; + return; + } else { + queue q; + // Adding root node to queue + q.push(*root); + while (!q.empty()) { + Btree *node = q.front(); + // Removing parent node from queue + q.pop(); + if (node->left) + // Adding left child of removed node to queue + q.push(node->left); + else { + // Adding new node if no left child is present + node->left = nn; + return; + } + if (node->right) + // Adding right child of removed node to queue + q.push(node->right); + else { + // Adding new node if no right child is present + node->right = nn; + return; + } + } + } +} + +void morrisInorder(Btree *root) { + Btree *curr = root; + Btree *temp; + while (curr) { + if (curr->left == NULL) { + cout << curr->data << " "; + // If left of current node is NULL then curr is shifted to right + curr = curr->right; + } else { + // Left of current node is stored in temp + temp = curr->left; + // Moving to extreme right of temp + while (temp->right && temp->right != curr) temp = temp->right; + // If extreme right is null it is made to point to currrent node + // (will be used for backtracking) + if (temp->right == NULL) { + temp->right = curr; + // current node is made to point its left subtree + curr = curr->left; + } + // If extreme right already points to currrent node it it set to + // null + else if (temp->right == curr) { + cout << curr->data << " "; + temp->right = NULL; + // current node is made to point its right subtree + curr = curr->right; + } + } + } +} + +int main() { + // Testing morrisInorder funtion + Btree *root = NULL; + int i; + for (i = 1; i <= 7; i++) insert(&root, i); + cout << "Morris Inorder: "; + morrisInorder(root); + return 0; +} diff --git a/data_structures/queue.h b/data_structures/queue.h new file mode 100644 index 00000000000..3cb55174118 --- /dev/null +++ b/data_structures/queue.h @@ -0,0 +1,88 @@ +/* This class specifies the basic operation on a queue as a linked list */ +#ifndef DATA_STRUCTURES_QUEUE_H_ +#define DATA_STRUCTURES_QUEUE_H_ + +#include +#include + +/** Definition of the node */ +template +struct node { + Kind data; + node *next; +}; + +/** Definition of the queue class */ +template +class queue { + public: + /** Show queue */ + void display() { + node *current = queueFront; + std::cout << "Front --> "; + while (current != NULL) { + std::cout << current->data << " "; + current = current->next; + } + std::cout << std::endl; + std::cout << "Size of queue: " << size << std::endl; + } + + /** Default constructor*/ + queue() { + queueFront = NULL; + queueRear = NULL; + size = 0; + } + + /** Destructor */ + ~queue() {} + + /** Determine whether the queue is empty */ + bool isEmptyQueue() { return (queueFront == NULL); } + + /** Add new item to the queue */ + void enQueue(Kind item) { + node *newNode; + newNode = new node; + newNode->data = item; + newNode->next = NULL; + if (queueFront == NULL) { + queueFront = newNode; + queueRear = newNode; + } else { + queueRear->next = newNode; + queueRear = queueRear->next; + } + size++; + } + + /** Return the first element of the queue */ + Kind front() { + assert(queueFront != NULL); + return queueFront->data; + } + + /** Remove the top element of the queue */ + void deQueue() { + node *temp; + if (!isEmptyQueue()) { + temp = queueFront; + queueFront = queueFront->next; + delete temp; + size--; + } else { + std::cout << "Queue is empty !" << std::endl; + } + } + + /** Clear queue */ + void clear() { queueFront = NULL; } + + private: + node *queueFront; /**< Pointer to the front of the queue */ + node *queueRear; /**< Pointer to the rear of the queue */ + int size; +}; + +#endif // DATA_STRUCTURES_QUEUE_H_ diff --git a/data_structure/queue_using_array.cpp b/data_structures/queue_using_array.cpp similarity index 95% rename from data_structure/queue_using_array.cpp rename to data_structures/queue_using_array.cpp index ccd6e3cd616..a887c99fc7f 100644 --- a/data_structure/queue_using_array.cpp +++ b/data_structures/queue_using_array.cpp @@ -58,8 +58,7 @@ void Queue_Array::display() { if (front == -1) { std::cout << "\nStack is empty"; } else { - for (int i = front; i <= rear; i++) - std::cout << arr[i] << " "; + for (int i = front; i <= rear; i++) std::cout << arr[i] << " "; } } diff --git a/data_structures/queue_using_array2.cpp b/data_structures/queue_using_array2.cpp new file mode 100644 index 00000000000..13f7d8e17f8 --- /dev/null +++ b/data_structures/queue_using_array2.cpp @@ -0,0 +1,57 @@ +#include +using namespace std; + +int queue[10]; +int front = 0; +int rear = 0; + +void Enque(int x) { + if (rear == 10) { + cout << "\nOverflow"; + } else { + queue[rear++] = x; + } +} + +void Deque() { + if (front == rear) { + cout << "\nUnderflow"; + } + + else { + cout << "\n" << queue[front++] << " deleted"; + for (int i = front; i < rear; i++) { + queue[i - front] = queue[i]; + } + rear = rear - front; + front = 0; + } +} + +void show() { + for (int i = front; i < rear; i++) { + cout << queue[i] << "\t"; + } +} + +int main() { + int ch, x; + do { + cout << "\n1. Enque"; + cout << "\n2. Deque"; + cout << "\n3. Print"; + cout << "\nEnter Your Choice : "; + cin >> ch; + if (ch == 1) { + cout << "\nInsert : "; + cin >> x; + Enque(x); + } else if (ch == 2) { + Deque(); + } else if (ch == 3) { + show(); + } + } while (ch != 0); + + return 0; +} diff --git a/data_structure/Queue Using Linked List.cpp b/data_structures/queue_using_linked_list.cpp similarity index 69% rename from data_structure/Queue Using Linked List.cpp rename to data_structures/queue_using_linked_list.cpp index 39d7a9ae376..7b44d240c74 100644 --- a/data_structure/Queue Using Linked List.cpp +++ b/data_structures/queue_using_linked_list.cpp @@ -1,18 +1,15 @@ #include using namespace std; -struct node -{ +struct node { int val; node *next; }; node *front, *rear; -void Enque(int x) -{ - if (rear == NULL) - { +void Enque(int x) { + if (rear == NULL) { node *n = new node; n->val = x; n->next = NULL; @@ -20,9 +17,7 @@ void Enque(int x) front = n; } - else - { - + else { node *n = new node; n->val = x; n->next = NULL; @@ -31,17 +26,12 @@ void Enque(int x) } } -void Deque() -{ - if (rear == NULL && front == NULL) - { +void Deque() { + if (rear == NULL && front == NULL) { cout << "\nUnderflow"; - } - else - { + } else { node *t = front; - cout << "\n" - << t->val << " deleted"; + cout << "\n" << t->val << " deleted"; front = front->next; delete t; if (front == NULL) @@ -49,38 +39,29 @@ void Deque() } } -void show() -{ +void show() { node *t = front; - while (t != NULL) - { + while (t != NULL) { cout << t->val << "\t"; t = t->next; } } -int main() -{ +int main() { int ch, x; - do - { + do { cout << "\n1. Enque"; cout << "\n2. Deque"; cout << "\n3. Print"; cout << "\nEnter Your Choice : "; cin >> ch; - if (ch == 1) - { + if (ch == 1) { cout << "\nInsert : "; cin >> x; Enque(x); - } - else if (ch == 2) - { + } else if (ch == 2) { Deque(); - } - else if (ch == 3) - { + } else if (ch == 3) { show(); } } while (ch != 0); diff --git a/data_structures/queue_using_linkedlist.cpp b/data_structures/queue_using_linkedlist.cpp new file mode 100644 index 00000000000..f1bf18123f9 --- /dev/null +++ b/data_structures/queue_using_linkedlist.cpp @@ -0,0 +1,86 @@ +/* + Write a program to implement Queue using linkedlist. +*/ +#include + +struct linkedlist { + int data; + linkedlist *next; +}; +class stack_linkedList { + public: + linkedlist *front; + linkedlist *rear; + + stack_linkedList() { front = rear = NULL; } + void enqueue(int); + int dequeue(); + void display(); +}; +void stack_linkedList::enqueue(int ele) { + linkedlist *temp = new linkedlist(); + temp->data = ele; + temp->next = NULL; + + if (front == NULL) + front = rear = temp; + else { + rear->next = temp; + rear = temp; + } +} +int stack_linkedList::dequeue() { + linkedlist *temp; + int ele; + if (front == NULL) + std::cout << "\nStack is empty"; + else { + temp = front; + ele = temp->data; + if (front == rear) // if length of queue is 1; + rear = rear->next; + front = front->next; + delete (temp); + } + return ele; +} +void stack_linkedList::display() { + if (front == NULL) + std::cout << "\nStack is empty"; + + else { + linkedlist *temp; + temp = front; + while (temp != NULL) { + std::cout << temp->data << " "; + temp = temp->next; + } + } +} + +int main() { + int op, data; + stack_linkedList ob; + std::cout << "\n1. enqueue(Insertion) "; + std::cout << "\n2. dequeue(Deletion)"; + std::cout << "\n3. Display"; + std::cout << "\n4. Exit"; + + while (1) { + std::cout << "\nEnter your choice "; + std::cin >> op; + if (op == 1) { + std::cout << "Enter data "; + std::cin >> data; + ob.enqueue(data); + } else if (op == 2) + data = ob.dequeue(); + else if (op == 3) + ob.display(); + else if (op == 4) + exit(0); + else + std::cout << "\nWrong choice "; + } + return 0; +} diff --git a/data_structures/stack.h b/data_structures/stack.h new file mode 100644 index 00000000000..f4b8992e706 --- /dev/null +++ b/data_structures/stack.h @@ -0,0 +1,111 @@ +/* This class specifies the basic operation on a stack as a linked list */ +#ifndef DATA_STRUCTURES_STACK_H_ +#define DATA_STRUCTURES_STACK_H_ + +#include +#include + +/* Definition of the node */ +template +struct node { + Type data; + node *next; +}; + +/* Definition of the stack class */ +template +class stack { + public: + /** Show stack */ + void display() { + node *current = stackTop; + std::cout << "Top --> "; + while (current != NULL) { + std::cout << current->data << " "; + current = current->next; + } + std::cout << std::endl; + std::cout << "Size of stack: " << size << std::endl; + } + + /** Default constructor*/ + stack() { + stackTop = NULL; + size = 0; + } + + /** Destructor */ + ~stack() {} + + /** Determine whether the stack is empty */ + bool isEmptyStack() { return (stackTop == NULL); } + + /** Add new item to the stack */ + void push(Type item) { + node *newNode; + newNode = new node; + newNode->data = item; + newNode->next = stackTop; + stackTop = newNode; + size++; + } + + /** Return the top element of the stack */ + Type top() { + assert(stackTop != NULL); + return stackTop->data; + } + + /** Remove the top element of the stack */ + void pop() { + node *temp; + if (!isEmptyStack()) { + temp = stackTop; + stackTop = stackTop->next; + delete temp; + size--; + } else { + std::cout << "Stack is empty !" << std::endl; + } + } + + /** Clear stack */ + void clear() { stackTop = NULL; } + + /** Overload "=" the assignment operator */ + stack &operator=(const stack &otherStack) { + node *newNode, *current, *last; + + /* If stack is no empty, make it empty */ + if (stackTop != NULL) { + stackTop = NULL; + } + if (otherStack.stackTop == NULL) { + stackTop = NULL; + } else { + current = otherStack.stackTop; + stackTop = new node; + stackTop->data = current->data; + stackTop->next = NULL; + last = stackTop; + current = current->next; + /* Copy the remaining stack */ + while (current != NULL) { + newNode = new node; + newNode->data = current->data; + newNode->next = NULL; + last->next = newNode; + last = newNode; + current = current->next; + } + } + size = otherStack.size; + return *this; + } + + private: + node *stackTop; /**< Pointer to the stack */ + int size; +}; + +#endif // DATA_STRUCTURES_STACK_H_ diff --git a/data_structures/stack_using_array.cpp b/data_structures/stack_using_array.cpp new file mode 100644 index 00000000000..36be9eb3919 --- /dev/null +++ b/data_structures/stack_using_array.cpp @@ -0,0 +1,55 @@ +#include + +int *stack; +int top = 0, stack_size; + +void push(int x) { + if (top == stack_size) { + std::cout << "\nOverflow"; + } else { + stack[top++] = x; + } +} + +void pop() { + if (top == 0) { + std::cout << "\nUnderflow"; + } else { + std::cout << "\n" << stack[--top] << " deleted"; + } +} + +void show() { + for (int i = 0; i < top; i++) { + std::cout << stack[i] << "\n"; + } +} + +void topmost() { std::cout << "\nTopmost element: " << stack[top - 1]; } +int main() { + std::cout << "\nEnter stack_size of stack : "; + std::cin >> stack_size; + stack = new int[stack_size]; + int ch, x; + do { + std::cout << "\n1. Push"; + std::cout << "\n2. Pop"; + std::cout << "\n3. Print"; + std::cout << "\n4. Print topmost element:"; + std::cout << "\nEnter Your Choice : "; + std::cin >> ch; + if (ch == 1) { + std::cout << "\nInsert : "; + std::cin >> x; + push(x); + } else if (ch == 2) { + pop(); + } else if (ch == 3) { + show(); + } else if (ch == 4) { + topmost(); + } + } while (ch != 0); + + return 0; +} diff --git a/data_structures/stack_using_linked_list.cpp b/data_structures/stack_using_linked_list.cpp new file mode 100644 index 00000000000..ae53fe95ad3 --- /dev/null +++ b/data_structures/stack_using_linked_list.cpp @@ -0,0 +1,57 @@ +#include +using namespace std; + +struct node { + int val; + node *next; +}; + +node *top; + +void push(int x) { + node *n = new node; + n->val = x; + n->next = top; + top = n; +} + +void pop() { + if (top == NULL) { + cout << "\nUnderflow"; + } else { + node *t = top; + cout << "\n" << t->val << " deleted"; + top = top->next; + delete t; + } +} + +void show() { + node *t = top; + while (t != NULL) { + cout << t->val << "\n"; + t = t->next; + } +} + +int main() { + int ch, x; + do { + cout << "\n1. Push"; + cout << "\n2. Pop"; + cout << "\n3. Print"; + cout << "\nEnter Your Choice : "; + cin >> ch; + if (ch == 1) { + cout << "\nInsert : "; + cin >> x; + push(x); + } else if (ch == 2) { + pop(); + } else if (ch == 3) { + show(); + } + } while (ch != 0); + + return 0; +} diff --git a/data_structure/stk/student.txt b/data_structures/student.txt similarity index 100% rename from data_structure/stk/student.txt rename to data_structures/student.txt diff --git a/data_structures/test_queue.cpp b/data_structures/test_queue.cpp new file mode 100644 index 00000000000..387ccf2f795 --- /dev/null +++ b/data_structures/test_queue.cpp @@ -0,0 +1,41 @@ +#include +#include + +#include "./queue.h" + +int main() { + queue q; + std::cout << "---------------------- Test construct ----------------------" + << std::endl; + q.display(); + std::cout + << "---------------------- Test isEmptyQueue ----------------------" + << std::endl; + if (q.isEmptyQueue()) + std::cout << "PASS" << std::endl; + else + std::cout << "FAIL" << std::endl; + std::cout << "---------------------- Test enQueue ----------------------" + << std::endl; + std::cout << "After Hai, Jeff, Tom, Jkingston go into queue: " << std::endl; + q.enQueue("Hai"); + q.enQueue("Jeff"); + q.enQueue("Tom"); + q.enQueue("Jkingston"); + q.display(); + std::cout << "---------------------- Test front ----------------------" + << std::endl; + std::string value = q.front(); + if (value == "Hai") + std::cout << "PASS" << std::endl; + else + std::cout << "FAIL" << std::endl; + std::cout << "---------------------- Test deQueue ----------------------" + << std::endl; + q.display(); + q.deQueue(); + q.deQueue(); + std::cout << "After Hai, Jeff left the queue: " << std::endl; + q.display(); + return 0; +} diff --git a/data_structures/test_stack.cpp b/data_structures/test_stack.cpp new file mode 100644 index 00000000000..aa636916f8e --- /dev/null +++ b/data_structures/test_stack.cpp @@ -0,0 +1,59 @@ +#include + +#include "./stack.h" + +int main() { + stack stk; + std::cout << "---------------------- Test construct ----------------------" + << std::endl; + stk.display(); + std::cout + << "---------------------- Test isEmptyStack ----------------------" + << std::endl; + if (stk.isEmptyStack()) + std::cout << "PASS" << std::endl; + else + std::cout << "FAIL" << std::endl; + std::cout << "---------------------- Test push ----------------------" + << std::endl; + std::cout << "After pushing 10 20 30 40 into stack: " << std::endl; + stk.push(10); + stk.push(20); + stk.push(30); + stk.push(40); + stk.display(); + std::cout << "---------------------- Test top ----------------------" + << std::endl; + int value = stk.top(); + if (value == 40) + std::cout << "PASS" << std::endl; + else + std::cout << "FAIL" << std::endl; + std::cout << "---------------------- Test pop ----------------------" + << std::endl; + stk.display(); + stk.pop(); + stk.pop(); + std::cout << "After popping 2 times: " << std::endl; + stk.display(); + std::cout << "---------------------- Test overload = operator " + "----------------------" + << std::endl; + stack stk1; + std::cout << "stk current: " << std::endl; + stk.display(); + std::cout << std::endl << "Assign stk1 = stk " << std::endl; + stk1 = stk; + stk1.display(); + std::cout << std::endl << "After pushing 8 9 10 into stk1:" << std::endl; + stk1.push(8); + stk1.push(9); + stk1.push(10); + stk1.display(); + std::cout << std::endl << "stk current: " << std::endl; + stk.display(); + std::cout << "Assign back stk = stk1:" << std::endl; + stk = stk1; + stk.display(); + return 0; +} diff --git a/data_structure/stk/main.cpp b/data_structures/test_stack_students.cpp similarity index 67% rename from data_structure/stk/main.cpp rename to data_structures/test_stack_students.cpp index 2d6bbec5617..a6048c4c938 100644 --- a/data_structure/stk/main.cpp +++ b/data_structures/test_stack_students.cpp @@ -8,29 +8,26 @@ * ./main student.txt ************************************************************ * */ -#include -#include +#include #include +#include +#include #include -#include - -#include "stack.h" -#include "stack.cpp" -using namespace std; +#include "./stack.h" -int main(int argc, char * argv[]) { +int main(int argc, char* argv[]) { double GPA; double highestGPA; - string name; + std::string name; assert(argc == 2); - ifstream infile; - stack stk; + std::ifstream infile; + stack stk; infile.open(argv[1]); - cout << fixed << showpoint; - cout << setprecision(2); + std::cout << std::fixed << std::showpoint; + std::cout << std::setprecision(2); infile >> GPA >> name; highestGPA = GPA; @@ -44,12 +41,12 @@ int main(int argc, char * argv[]) { } infile >> GPA >> name; } - cout << "Highest GPA: " << highestGPA < using namespace std; -struct node -{ +struct node { int val; node *left; node *right; }; -void CreateTree(node *curr, node *n, int x, char pos) -{ - if (n != NULL) - { +void CreateTree(node *curr, node *n, int x, char pos) { + if (n != NULL) { char ch; - cout << "\nLeft or Right of " << n->val << " : "; - cin >> ch; - if (ch == 'l') - CreateTree(n, n->left, x, ch); - else if (ch == 'r') - CreateTree(n, n->right, x, ch); - } - else - { + cout << "\nLeft or Right of " << n->val << " : "; + cin >> ch; + if (ch == 'l') + CreateTree(n, n->left, x, ch); + else if (ch == 'r') + CreateTree(n, n->right, x, ch); + } else { node *t = new node; t->val = x; t->left = NULL; t->right = NULL; - if (pos == 'l') - { + if (pos == 'l') { curr->left = t; - } - else if (pos == 'r') - { + } else if (pos == 'r') { curr->right = t; } } } -void BFT(node *n) -{ - list queue; +void BFT(node *n) { + list queue; queue.push_back(n); - while(!queue.empty()) - { + while (!queue.empty()) { n = queue.front(); cout << n->val << " "; queue.pop_front(); - if(n->left != NULL) + if (n->left != NULL) queue.push_back(n->left); - if(n->right != NULL) + if (n->right != NULL) queue.push_back(n->right); } } -void Pre(node *n) -{ - if (n != NULL) - { +void Pre(node *n) { + if (n != NULL) { cout << n->val << " "; Pre(n->left); Pre(n->right); } } -void In(node *n) -{ - if (n != NULL) - { +void In(node *n) { + if (n != NULL) { In(n->left); cout << n->val << " "; In(n->right); } } -void Post(node *n) -{ - if (n != NULL) - { +void Post(node *n) { + if (n != NULL) { Post(n->left); Post(n->right); cout << n->val << " "; } } -int main() -{ +int main() { int value; int ch; node *root = new node; @@ -97,8 +80,7 @@ int main() root->val = value; root->left = NULL; root->right = NULL; - do - { + do { cout << "\n1. Insert"; cout << "\n2. Breadth First"; cout << "\n3. Preorder Depth First"; @@ -107,8 +89,7 @@ int main() cout << "\nEnter Your Choice : "; cin >> ch; - switch (ch) - { + switch (ch) { case 1: int x; char pos; diff --git a/data_structure/trie_modern.cpp b/data_structures/trie_modern.cpp similarity index 96% rename from data_structure/trie_modern.cpp rename to data_structures/trie_modern.cpp index 218c90b68b5..c2eba30e053 100644 --- a/data_structure/trie_modern.cpp +++ b/data_structures/trie_modern.cpp @@ -1,8 +1,8 @@ /** - * Copyright 2020 @author Anmol3299 * @file * - * A basic implementation of trie class to store only lower-case strings. + * Copyright 2020 @author Anmol3299 + * \brief A basic implementation of trie class to store only lower-case strings. */ #include // for io operations #include // for std::shared_ptr<> @@ -35,7 +35,8 @@ class Trie { * Function to check if a node has some children which can form words. * @param node whose character array of pointers need to be checked for * children. - * @return if a child is found, it returns @ true, else it returns @ false. + * @return `true` if a child is found + * @return `false` if a child is not found */ inline static bool hasChildren(std::shared_ptr node) { for (size_t i = 0; i < ALPHABETS; i++) { @@ -98,7 +99,7 @@ class Trie { } public: - // constructor to initialise the root of the trie. + /// constructor to initialise the root of the trie. Trie() : m_root(std::make_shared()) {} /** diff --git a/data_structures/trie_tree.cpp b/data_structures/trie_tree.cpp new file mode 100644 index 00000000000..66b67fbc0cb --- /dev/null +++ b/data_structures/trie_tree.cpp @@ -0,0 +1,87 @@ +#include +#include + +#include +#include + +// structure definition +typedef struct trie { + struct trie* arr[26]; + bool isEndofWord; +} trie; + +// create a new node for trie +trie* createNode() { + trie* nn = new trie(); + for (int i = 0; i < 26; i++) nn->arr[i] = NULL; + nn->isEndofWord = false; + return nn; +} + +// insert string into the trie +void insert(trie* root, std::string str) { + for (int i = 0; i < str.length(); i++) { + int j = str[i] - 'a'; + if (root->arr[j]) { + root = root->arr[j]; + } else { + root->arr[j] = createNode(); + root = root->arr[j]; + } + } + root->isEndofWord = true; +} + +// search a string exists inside the trie +bool search(trie* root, std::string str, int index) { + if (index == str.length()) { + if (!root->isEndofWord) + return false; + return true; + } + int j = str[index] - 'a'; + if (!root->arr[j]) + return false; + return search(root->arr[j], str, index + 1); +} + +/* +removes the string if it is not a prefix of any other +string, if it is then just sets the endofword to false, else +removes the given string +*/ +bool deleteString(trie* root, std::string str, int index) { + if (index == str.length()) { + if (!root->isEndofWord) + return false; + root->isEndofWord = false; + for (int i = 0; i < 26; i++) return false; + return true; + } + int j = str[index] - 'a'; + if (!root->arr[j]) + return false; + bool var = deleteString(root, str, index + 1); + if (var) { + root->arr[j] = NULL; + if (root->isEndofWord) { + return false; + } else { + int i; + for (i = 0; i < 26; i++) + if (root->arr[i]) + return false; + return true; + } + } +} + +int main() { + trie* root = createNode(); + insert(root, "hello"); + insert(root, "world"); + int a = search(root, "hello", 0); + int b = search(root, "word", 0); + printf("%d %d ", a, b); + return 0; +} diff --git a/doc/cppreference-doxygen-web.tag.xml b/doc/cppreference-doxygen-web.tag.xml new file mode 100644 index 00000000000..ea8388b8b8e --- /dev/null +++ b/doc/cppreference-doxygen-web.tag.xml @@ -0,0 +1,35489 @@ + + + + std + + std::is_function + + T + atomic_fetch_and_explicit + cpp/atomic/atomic_fetch_sub + + (T... args) + + + T + atomic_fetch_xor_explicit + cpp/atomic/atomic_fetch_xor + + (T... args) + + + T + set_unexpected + cpp/error/set_unexpected + + (T... args) + + std::input_iterator_tag + std::logical_and + std::is_integral + std::money_get + + T + fputs + cpp/io/c/fputs + + (T... args) + + std::basic_ofstream + std::ratio_subtract + + T + modf + cpp/numeric/math/modf + + (T... args) + + std::size_t + + T + not2 + cpp/utility/functional/not2 + + (T... args) + + + T + strlen + cpp/string/byte/strlen + + (T... args) + + + T + exp2 + cpp/numeric/math/exp2 + + (T... args) + + std::ctype_byname + std::wcout + + T + setiosflags + cpp/io/manip/setiosflags + + (T... args) + + + T + adjacent_difference + cpp/algorithm/adjacent_difference + + (T... args) + + + T + cos + cpp/numeric/math/cos + + (T... args) + + + T + fwscanf + cpp/io/c/fwscanf + + (T... args) + + + T + atomic_init + cpp/atomic/atomic_init + + (T... args) + + std::fstream + std::valarray + std::ratio_greater_equal + + T + forward_as_tuple + cpp/utility/tuple/forward_as_tuple + + (T... args) + + std::remove_extent + std::ratio_greater + + T + abort + cpp/utility/program/abort + + (T... args) + + + T + wcsncmp + cpp/string/wide/wcsncmp + + (T... args) + + std::intptr_t + std::regex_iterator + + T + set_intersection + cpp/algorithm/set_intersection + + (T... args) + + std::lock_guard + std::wbuffer_convert + std::modulus + std::ratio_divide + + T + atomic_signal_fence + cpp/atomic/atomic_signal_fence + + (T... args) + + + T + llabs + cpp/numeric/math/abs + + (T... args) + + + T + make_move_iterator + cpp/iterator/make_move_iterator + + (T... args) + + std::ostreambuf_iterator + std::dynarray + std::is_nothrow_move_constructible + std::vector + + T + scanf + cpp/io/c/fscanf + + (T... args) + + std::match_results + std::back_insert_iterator + + T + nextafter + cpp/numeric/math/nextafter + + (T... args) + + std::iterator + std::int8_t + + T + stol + cpp/string/basic_string/stol + + (T... args) + + + T + strcspn + cpp/string/byte/strcspn + + (T... args) + + + T + ungetwc + cpp/io/c/ungetwc + + (T... args) + + + T + transform + cpp/algorithm/transform + + (T... args) + + std::student_t_distribution + std::mt19937_64 + std::runtime_error + + T + putc + cpp/io/c/fputc + + (T... args) + + + T + iswdigit + cpp/string/wide/iswdigit + + (T... args) + + std::ranlux24_base + + T + rint + cpp/numeric/math/rint + + (T... args) + + std::allocator_traits + + T + memset + cpp/string/byte/memset + + (T... args) + + + T + isgraph + cpp/string/byte/isgraph + + (T... args) + + std::codecvt + std::ratio_less_equal + + T + replace_copy_if + cpp/algorithm/replace_copy + + (T... args) + + + T + scalbn + cpp/numeric/math/scalbn + + (T... args) + + std::condition_variable_any + + T + partial_sort_copy + cpp/algorithm/partial_sort_copy + + (T... args) + + std::deca + std::extreme_value_distribution + std::cout + std::decay + std::is_trivially_move_assignable + std::adopt_lock_t + + T + make_exception_ptr + cpp/error/make_exception_ptr + + (T... args) + + std::wcerr + + T + frexp + cpp/numeric/math/frexp + + (T... args) + + std::lognormal_distribution + + T + isxdigit + cpp/string/byte/isxdigit + + (T... args) + + std::wclog + + T + atomic_exchange_explicit + cpp/atomic/atomic_exchange + + (T... args) + + + T + wprintf + cpp/io/c/fwprintf + + (T... args) + + std::char_traits + std::remove_reference + + T + fdim + cpp/numeric/math/fdim + + (T... args) + + std::num_get + + T + wctype + cpp/string/wide/wctype + + (T... args) + + std::is_pointer + + T + mbrtoc32 + cpp/string/multibyte/mbrtoc32 + + (T... args) + + + T + setw + cpp/io/manip/setw + + (T... args) + + + T + get_temporary_buffer + cpp/memory/get_temporary_buffer + + (T... args) + + + T + fmax + cpp/numeric/math/fmax + + (T... args) + + std::multiset + + T + atomic_thread_fence + cpp/atomic/atomic_thread_fence + + (T... args) + + + T + atomic_exchange + cpp/atomic/atomic_exchange + + (T... args) + + std::weak_ptr + std::bidirectional_iterator_tag + std::wstring_convert + + T + fgetwc + cpp/io/c/fgetwc + + (T... args) + + + T + swprintf + cpp/io/c/fwprintf + + (T... args) + + + T + prev_permutation + cpp/algorithm/prev_permutation + + (T... args) + + std::greater_equal + std::is_trivially_constructible + + T + max_element + cpp/algorithm/max_element + + (T... args) + + std::string + std::discrete_distribution + std::wostream + std::is_polymorphic + + T + set_symmetric_difference + cpp/algorithm/set_symmetric_difference + + (T... args) + + + T + wcscpy + cpp/string/wide/wcscpy + + (T... args) + + + T + const_pointer_cast + cpp/memory/shared_ptr/pointer_cast + + (T... args) + + + T + minmax_element + cpp/algorithm/minmax_element + + (T... args) + + + T + wcstok + cpp/string/wide/wcstok + + (T... args) + + + T + ref + cpp/utility/functional/ref + + (T... args) + + std::reverse_iterator + + T + feupdateenv + cpp/numeric/fenv/feupdateenv + + (T... args) + + std::bad_array_new_length + + T + endl + cpp/io/manip/endl + + (T... args) + + + T + end + cpp/iterator/end + + (T... args) + + std::condition_variable + + T + wmemmove + cpp/string/wide/wmemmove + + (T... args) + + + T + fmin + cpp/numeric/math/fmin + + (T... args) + + + T + uninitialized_fill_n + cpp/memory/uninitialized_fill_n + + (T... args) + + std::ranlux48 + + T + nouppercase + cpp/io/manip/uppercase + + (T... args) + + + T + noshowpos + cpp/io/manip/showpos + + (T... args) + + + T + ctime + cpp/chrono/c/ctime + + (T... args) + + + T + wmemset + cpp/string/wide/wmemset + + (T... args) + + std::unexpected_handler + + T + iswpunct + cpp/string/wide/iswpunct + + (T... args) + + std::piecewise_constant_distribution + std::codecvt_base + std::set + + T + pop_heap + cpp/algorithm/pop_heap + + (T... args) + + + T + sprintf + cpp/io/c/fprintf + + (T... args) + + + T + fixed + cpp/io/manip/fixed + + (T... args) + + + T + make_shared + cpp/memory/shared_ptr/make_shared + + (T... args) + + std::forward_iterator_tag + std::codecvt_byname + std::pointer_safety + std::uint_least64_t + std::placeholders + std::nothrow_t + std::is_nothrow_copy_assignable + std::is_same + + T + make_heap + cpp/algorithm/make_heap + + (T... args) + + + T + fmod + cpp/numeric/math/fmod + + (T... args) + + std::unique_lock + std::basic_ostringstream + + T + atol + cpp/string/byte/atoi + + (T... args) + + std::is_error_code_enum + std::time_put_byname + + T + uninitialized_copy + cpp/memory/uninitialized_copy + + (T... args) + + std::time_get + + T + dynamic_pointer_cast + cpp/memory/shared_ptr/pointer_cast + + (T... args) + + + T + set_union + cpp/algorithm/set_union + + (T... args) + + std::regex + std::cin + + T + hexfloat + cpp/io/manip/fixed + + (T... args) + + + T + vswprintf + cpp/io/c/vfwprintf + + (T... args) + + + T + asctime + cpp/chrono/c/asctime + + (T... args) + + std::unordered_map + + T + iswspace + cpp/string/wide/iswspace + + (T... args) + + std::initializer_list + + T + nan + cpp/numeric/math/nan + + (T... args) + + + T + sort + cpp/algorithm/sort + + (T... args) + + + T + quick_exit + cpp/utility/program/quick_exit + + (T... args) + + std::is_const + + T + log10 + cpp/numeric/math/log10 + + (T... args) + + std::basic_regex + + T + mbstowcs + cpp/string/multibyte/mbstowcs + + (T... args) + + + T + isspace + cpp/string/byte/isspace + + (T... args) + + std::poisson_distribution + std::bad_typeid + + T + strncat + cpp/string/byte/strncat + + (T... args) + + std::less_equal + + T + isinf + cpp/numeric/math/isinf + + (T... args) + + + T + atof + cpp/string/byte/atof + + (T... args) + + std::sig_atomic_t + + T + erf + cpp/numeric/math/erf + + (T... args) + + + T + is_sorted_until + cpp/algorithm/is_sorted_until + + (T... args) + + + T + cbrt + cpp/numeric/math/cbrt + + (T... args) + + + T + log1p + cpp/numeric/math/log1p + + (T... args) + + + T + return_temporary_buffer + cpp/memory/return_temporary_buffer + + (T... args) + + + T + mbsrtowcs + cpp/string/multibyte/mbsrtowcs + + (T... args) + + + T + feraiseexcept + cpp/numeric/fenv/feraiseexcept + + (T... args) + + + T + fseek + cpp/io/c/fseek + + (T... args) + + std::make_unsigned + std::basic_filebuf + + T + atomic_fetch_or_explicit + cpp/atomic/atomic_fetch_or + + (T... args) + + std::logical_or + + T + log + cpp/numeric/math/log + + (T... args) + + + T + putchar + cpp/io/c/putchar + + (T... args) + + + T + make_tuple + cpp/utility/tuple/make_tuple + + (T... args) + + + T + expm1 + cpp/numeric/math/expm1 + + (T... args) + + std::wstringbuf + + T + fma + cpp/numeric/math/fma + + (T... args) + + std::kilo + std::bernoulli_distribution + + T + remove_copy_if + cpp/algorithm/remove_copy + + (T... args) + + + T + showpoint + cpp/io/manip/showpoint + + (T... args) + + std::int16_t + + T + fscanf + cpp/io/c/fscanf + + (T... args) + + + T + stable_partition + cpp/algorithm/stable_partition + + (T... args) + + std::basic_ios + std::int32_t + + T + fill_n + cpp/algorithm/fill_n + + (T... args) + + std::is_rvalue_reference + + T + remove_copy + cpp/algorithm/remove_copy + + (T... args) + + + T + atomic_compare_exchange_strong_explicit + cpp/atomic/atomic_compare_exchange + + (T... args) + + std::integral_constant + std::wsmatch + + T + wctomb + cpp/string/multibyte/wctomb + + (T... args) + + + T + fgets + cpp/io/c/fgets + + (T... args) + + + T + remainder + cpp/numeric/math/remainder + + (T... args) + + std::cerr + std::codecvt_utf8 + + T + allocate_shared + cpp/memory/shared_ptr/allocate_shared + + (T... args) + + std::ratio_add + + T + unique + cpp/algorithm/unique + + (T... args) + + std::is_trivially_move_constructible + + T + includes + cpp/algorithm/includes + + (T... args) + + + T + iswalnum + cpp/string/wide/iswalnum + + (T... args) + + std::wcsub_match + + T + exit + cpp/utility/program/exit + + (T... args) + + + T + put_time + cpp/io/manip/put_time + + (T... args) + + + T + to_string + cpp/string/basic_string/to_string + + (T... args) + + + T + is_heap_until + cpp/algorithm/is_heap_until + + (T... args) + + std::is_member_pointer + + T + wcstold + cpp/string/wide/wcstof + + (T... args) + + std::wstreampos + std::uint_least16_t + + T + stold + cpp/string/basic_string/stof + + (T... args) + + + T + ftell + cpp/io/c/ftell + + (T... args) + + std::tuple + + T + copy_backward + cpp/algorithm/copy_backward + + (T... args) + + + T + wcstoll + cpp/string/wide/wcstol + + (T... args) + + + T + perror + cpp/io/c/perror + + (T... args) + + + T + vwscanf + cpp/io/c/vfwscanf + + (T... args) + + + T + stable_sort + cpp/algorithm/stable_sort + + (T... args) + + std::make_signed + + T + generic_category + cpp/error/generic_category + + (T... args) + + + T + abs(int) + cpp/numeric/math/abs + + (T... args) + + + T + fgetws + cpp/io/c/fgetws + + (T... args) + + std::logic_error + std::sregex_iterator + + T + showpos + cpp/io/manip/showpos + + (T... args) + + std::int_least64_t + + T + exp + cpp/numeric/math/exp + + (T... args) + + std::binary_negate + + T + fill + cpp/algorithm/fill + + (T... args) + + + T + isalpha + cpp/string/byte/isalpha + + (T... args) + + std::discard_block_engine + std::is_trivially_assignable + std::add_cv + + T + lgamma + cpp/numeric/math/lgamma + + (T... args) + + std::pico + std::iterator_traits + std::is_trivially_default_constructible + + T + feclearexcept + cpp/numeric/fenv/feclearexcept + + (T... args) + + + T + wcsncpy + cpp/string/wide/wcsncpy + + (T... args) + + + T + undeclare_reachable + cpp/memory/gc/undeclare_reachable + + (T... args) + + std::shared_ptr + + T + oct + cpp/io/manip/hex + + (T... args) + + std::bad_alloc + std::ostringstream + std::basic_fstream + std::stringbuf + std::exponential_distribution + std::uint32_t + + T + strspn + cpp/string/byte/strspn + + (T... args) + + std::wcregex_iterator + std::bad_function_call + + T + realloc + cpp/memory/c/realloc + + (T... args) + + + T + copy + cpp/algorithm/copy + + (T... args) + + + T + binary_search + cpp/algorithm/binary_search + + (T... args) + + + T + system_category + cpp/error/system_category + + (T... args) + + + T + mbrtowc + cpp/string/multibyte/mbrtowc + + (T... args) + + std::false_type + + T + strtof + cpp/string/byte/strtof + + (T... args) + + + T + mem_fn + cpp/utility/functional/mem_fn + + (T... args) + + std::wregex + + T + distance + cpp/iterator/distance + + (T... args) + + + T + lock + cpp/thread/lock + + (T... args) + + + T + strcmp + cpp/string/byte/strcmp + + (T... args) + + + T + tmpfile + cpp/io/c/tmpfile + + (T... args) + + + T + hypot + cpp/numeric/math/hypot + + (T... args) + + + T + getenv + cpp/utility/program/getenv + + (T... args) + + + T + strrchr + cpp/string/byte/strrchr + + (T... args) + + + T + count + cpp/algorithm/count + + (T... args) + + std::uint_least8_t + + T + tan + cpp/numeric/math/tan + + (T... args) + + + T + strftime + cpp/chrono/c/strftime + + (T... args) + + std::uniform_real_distribution + + T + stod + cpp/string/basic_string/stof + + (T... args) + + + T + towupper + cpp/string/wide/towupper + + (T... args) + + std::smatch + std::cregex_token_iterator + std::range_error + std::is_assignable + + T + atoll + cpp/string/byte/atoi + + (T... args) + + std::is_copy_assignable + std::invalid_argument + + T + atomic_store + cpp/atomic/atomic_store + + (T... args) + + std::is_unsigned + std::jmp_buf + std::is_class + std::geometric_distribution + + T + stoi + cpp/string/basic_string/stol + + (T... args) + + + T + rethrow_exception + cpp/error/rethrow_exception + + (T... args) + + std::uint_fast8_t + + T + sin + cpp/numeric/math/sin + + (T... args) + + + T + atomic_fetch_sub_explicit + cpp/atomic/atomic_fetch_sub + + (T... args) + + + T + unexpected + cpp/error/unexpected + + (T... args) + + + T + mbtowc + cpp/string/multibyte/mbtowc + + (T... args) + + std::mersenne_twister_engine + + T + get_time + cpp/io/manip/get_time + + (T... args) + + + T + partition + cpp/algorithm/partition + + (T... args) + + + T + next + cpp/iterator/next + + (T... args) + + std::is_arithmetic + std::negate + std::try_to_lock_t + std::wfilebuf + std::is_compound + std::iostream + std::is_object + + T + isfinite + cpp/numeric/math/isfinite + + (T... args) + + + T + boolalpha + cpp/io/manip/boolalpha + + (T... args) + + + T + fetestexcept + cpp/numeric/fenv/fetestexcept + + (T... args) + + + T + mbrlen + cpp/string/multibyte/mbrlen + + (T... args) + + std::recursive_mutex + std::is_copy_constructible + + T + iswgraph + cpp/string/wide/iswgraph + + (T... args) + + std::codecvt_utf8_utf16 + std::not_equal_to + std::is_destructible + std::int_fast32_t + + T + time + cpp/chrono/c/time + + (T... args) + + + T + atomic_compare_exchange_strong + cpp/atomic/atomic_compare_exchange + + (T... args) + + std::rank + + T + wcschr + cpp/string/wide/wcschr + + (T... args) + + + T + uppercase + cpp/io/manip/uppercase + + (T... args) + + std::milli + std::deci + + T + lower_bound + cpp/algorithm/lower_bound + + (T... args) + + std::add_lvalue_reference + std::is_bind_expression + std::ios_base + + T + copy_if + cpp/algorithm/copy + + (T... args) + + std::ratio_less + std::int64_t + std::nullptr_t + + T + isnan + cpp/numeric/math/isnan + + (T... args) + + + T + has_facet + cpp/locale/has_facet + + (T... args) + + + T + kill_dependency + cpp/atomic/kill_dependency + + (T... args) + + + T + uninitialized_copy_n + cpp/memory/uninitialized_copy_n + + (T... args) + + std::stack + + T + feholdexcept + cpp/numeric/fenv/feholdexcept + + (T... args) + + + T + div + cpp/numeric/math/div + + (T... args) + + + T + at_quick_exit + cpp/utility/program/at_quick_exit + + (T... args) + + std::uint_fast64_t + std::is_reference + std::ratio + std::shared_future + std::u16streampos + + T + wcspbrk + cpp/string/wide/wcspbrk + + (T... args) + + + T + search + cpp/algorithm/search + + (T... args) + + std::wistream + std::aligned_storage + + T + find_first_of + cpp/algorithm/find_first_of + + (T... args) + + + T + iota + cpp/algorithm/iota + + (T... args) + + std::wstreambuf + + T + declare_reachable + cpp/memory/gc/declare_reachable + + (T... args) + + + T + atomic_compare_exchange_weak + cpp/atomic/atomic_compare_exchange + + (T... args) + + std::binary_function + + T + strtod + cpp/string/byte/strtof + + (T... args) + + + T + accumulate + cpp/algorithm/accumulate + + (T... args) + + + T + wcsrchr + cpp/string/wide/wcsrchr + + (T... args) + + std::out_of_range + + T + min_element + cpp/algorithm/min_element + + (T... args) + + std::independent_bits_engine + + T + clearerr + cpp/io/c/clearerr + + (T... args) + + + T + random_shuffle + cpp/algorithm/random_shuffle + + (T... args) + + std::stringstream + std::tera + + T + iswalpha + cpp/string/wide/iswalpha + + (T... args) + + std::recursive_timed_mutex + std::nano + + T + atomic_fetch_and + cpp/atomic/atomic_fetch_sub + + (T... args) + + + T + wmemchr + cpp/string/wide/wmemchr + + (T... args) + + std::unordered_multimap + std::normal_distribution + + T + bsearch + cpp/algorithm/bsearch + + (T... args) + + + T + ilogb + cpp/numeric/math/ilogb + + (T... args) + + std::minstd_rand + std::is_signed + + T + unique_copy + cpp/algorithm/unique_copy + + (T... args) + + + T + _Exit + cpp/utility/program/_Exit + + (T... args) + + + T + move + cpp/utility/move + + (T... args) + + + T + find_end + cpp/algorithm/find_end + + (T... args) + + std::is_move_constructible + std::unique_ptr + + T + fesetexceptflag + cpp/numeric/fenv/feexceptflag + + (T... args) + + std::is_nothrow_copy_constructible + std::forward_list + std::errc + std::lconv + + T + nth_element + cpp/algorithm/nth_element + + (T... args) + + + T + gets + cpp/io/c/gets + + (T... args) + + + T + lexicographical_compare + cpp/algorithm/lexicographical_compare + + (T... args) + + + T + nearbyint + cpp/numeric/math/nearbyint + + (T... args) + + std::strstreambuf + std::locale + std::equal_to + + T + memcpy + cpp/string/byte/memcpy + + (T... args) + + + T + fwrite + cpp/io/c/fwrite + + (T... args) + + std::divides + std::collate_byname + + T + unitbuf + cpp/io/manip/unitbuf + + (T... args) + + + T + iswlower + cpp/string/wide/iswlower + + (T... args) + + + T + mblen + cpp/string/multibyte/mblen + + (T... args) + + + T + swscanf + cpp/io/c/fwscanf + + (T... args) + + + T + wcstoimax + cpp/string/wide/wcstoimax + + (T... args) + + std::domain_error + + T + fprintf + cpp/io/c/fprintf + + (T... args) + + + T + find_if + cpp/algorithm/find + + (T... args) + + std::is_empty + + T + strtoimax + cpp/string/byte/strtoimax + + (T... args) + + + T + isalnum + cpp/string/byte/isalnum + + (T... args) + + + T + atomic_fetch_add_explicit + cpp/atomic/atomic_fetch_add + + (T... args) + + std::is_nothrow_default_constructible + std::ratio_equal + + T + push_heap + cpp/algorithm/push_heap + + (T... args) + + + T + min + cpp/algorithm/min + + (T... args) + + + T + fwprintf + cpp/io/c/fwprintf + + (T... args) + + std::ostream + std::streamsize + + T + uncaught_exception + cpp/error/uncaught_exception + + (T... args) + + std::shared_lock + + T + strtoll + cpp/string/byte/strtol + + (T... args) + + std::uint8_t + + T + throw_with_nested + cpp/error/throw_with_nested + + (T... args) + + + T + shuffle + cpp/algorithm/random_shuffle + + (T... args) + + + T + isprint + cpp/string/byte/isprint + + (T... args) + + + T + get_new_handler + cpp/memory/new/get_new_handler + + (T... args) + + + T + call_once + cpp/thread/call_once + + (T... args) + + + T + trunc + cpp/numeric/math/trunc + + (T... args) + + + T + wcscspn + cpp/string/wide/wcscspn + + (T... args) + + std::enable_shared_from_this + std::ptrdiff_t + + T + mbrtoc16 + cpp/string/multibyte/mbrtoc16 + + (T... args) + + std::int_fast8_t + std::aligned_union + + T + lround + cpp/numeric/math/round + + (T... args) + + std::future + std::wcmatch + std::overflow_error + std::centi + + T + pow + cpp/numeric/math/pow + + (T... args) + + std::wssub_match + std::is_nothrow_move_assignable + std::pair + + T + tgamma + cpp/numeric/math/tgamma + + (T... args) + + + T + erfc + cpp/numeric/math/erfc + + (T... args) + + + T + llround + cpp/numeric/math/round + + (T... args) + + + T + abs(float) + cpp/numeric/math/fabs + + (T... args) + + + T + asinh + cpp/numeric/math/asinh + + (T... args) + + + T + feof + cpp/io/c/feof + + (T... args) + + std::wsregex_token_iterator + std::weibull_distribution + + T + noskipws + cpp/io/manip/skipws + + (T... args) + + std::less + std::multiplies + + T + find + cpp/algorithm/find + + (T... args) + + + T + atoi + cpp/string/byte/atoi + + (T... args) + + std::is_enum + + T + not1 + cpp/utility/functional/not1 + + (T... args) + + + T + vfscanf + cpp/io/c/vfscanf + + (T... args) + + std::unary_function + + T + stof + cpp/string/basic_string/stof + + (T... args) + + + T + regex_search + cpp/regex/regex_search + + (T... args) + + std::error_code + std::yocto + std::streampos + std::istream_iterator + + T + rotate_copy + cpp/algorithm/rotate_copy + + (T... args) + + + T + set_new_handler + cpp/memory/new/set_new_handler + + (T... args) + + + T + undeclare_no_pointers + cpp/memory/gc/undeclare_no_pointers + + (T... args) + + std::wifstream + + T + async + cpp/thread/async + + (T... args) + + + T + partition_point + cpp/algorithm/partition_point + + (T... args) + + std::moneypunct_byname + + T + vsscanf + cpp/io/c/vfscanf + + (T... args) + + std::terminate_handler + std::ctype_base + std::reference_wrapper + + T + fesetround + cpp/numeric/fenv/feround + + (T... args) + + + T + atomic_is_lock_free + cpp/atomic/atomic_is_lock_free + + (T... args) + + std::ranlux48_base + + T + tanh + cpp/numeric/math/tanh + + (T... args) + + std::bit_not + std::int_fast16_t + + T + ldiv + cpp/numeric/math/div + + (T... args) + + + T + setbase + cpp/io/manip/setbase + + (T... args) + + + T + remove + cpp/algorithm/remove + + (T... args) + + + T + strtol + cpp/string/byte/strtol + + (T... args) + + + T + strpbrk + cpp/string/byte/strpbrk + + (T... args) + + std::error_category + std::regex_traits + + T + signbit + cpp/numeric/math/signbit + + (T... args) + + + T + wcsncat + cpp/string/wide/wcsncat + + (T... args) + + + T + get_money + cpp/io/manip/get_money + + (T... args) + + std::regex_constants + + T + set_difference + cpp/algorithm/set_difference + + (T... args) + + std::negative_binomial_distribution + + T + cref + cpp/utility/functional/ref + + (T... args) + + std::is_union + + T + getline + cpp/string/basic_string/getline + + (T... args) + + std::mt19937 + std::enable_if + + T + to_wstring + cpp/string/basic_string/to_wstring + + (T... args) + + std::chi_squared_distribution + std::add_rvalue_reference + + T + system + cpp/utility/program/system + + (T... args) + + + T + static_pointer_cast + cpp/memory/shared_ptr/pointer_cast + + (T... args) + + std::basic_istream + std::ostream_iterator + + T + wcstoumax + cpp/string/wide/wcstoimax + + (T... args) + + + T + memmove + cpp/string/byte/memmove + + (T... args) + + + T + getwchar + cpp/io/c/getwchar + + (T... args) + + + T + scientific + cpp/io/manip/fixed + + (T... args) + + + T + wcsftime + cpp/chrono/c/wcsftime + + (T... args) + + + T + begin + cpp/iterator/begin + + (T... args) + + + T + ceil + cpp/numeric/math/ceil + + (T... args) + + + T + sinh + cpp/numeric/math/sinh + + (T... args) + + + T + is_permutation + cpp/algorithm/is_permutation + + (T... args) + + std::is_trivially_copy_assignable + + T + generate_n + cpp/algorithm/generate_n + + (T... args) + + + T + acosh + cpp/numeric/math/acosh + + (T... args) + + std::clog + std::is_scalar + + T + advance + cpp/iterator/advance + + (T... args) + + std::uses_allocator + std::piecewise_linear_distribution + std::hash + + T + flush + cpp/io/manip/flush + + (T... args) + + std::shuffle_order_engine + std::chrono + std::greater + std::csub_match + std::uintmax_t + + T + atomic_fetch_xor + cpp/atomic/atomic_fetch_xor + + (T... args) + + std::remove_pointer + std::numeric_limits + + T + ws + cpp/io/manip/ws + + (T... args) + + std::add_volatile + std::once_flag + std::is_literal_type + std::money_base + + T + signal + cpp/utility/program/signal + + (T... args) + + + T + noshowbase + cpp/io/manip/showbase + + (T... args) + + std::peta + std::is_placeholder + + T + generate + cpp/algorithm/generate + + (T... args) + + + T + ldexp + cpp/numeric/math/ldexp + + (T... args) + + std::add_const + std::basic_stringbuf + std::tm + std::is_abstract + std::deque + + T + vsnprintf + cpp/io/c/vfprintf + + (T... args) + + std::allocator + + T + remove_if + cpp/algorithm/remove + + (T... args) + + std::scoped_allocator_adaptor + std::ssub_match + + T + stoull + cpp/string/basic_string/stoul + + (T... args) + + std::messages_byname + + T + fegetexceptflag + cpp/numeric/fenv/feexceptflag + + (T... args) + + + T + find_if_not + cpp/algorithm/find + + (T... args) + + std::promise + + T + merge + cpp/algorithm/merge + + (T... args) + + + T + free + cpp/memory/c/free + + (T... args) + + + T + count_if + cpp/algorithm/count + + (T... args) + + + T + clock + cpp/chrono/c/clock + + (T... args) + + + T + mktime + cpp/chrono/c/mktime + + (T... args) + + std::add_pointer + std::uintptr_t + + T + inserter + cpp/iterator/inserter + + (T... args) + + + T + puts + cpp/io/c/puts + + (T... args) + + std::bit_and + + T + asin + cpp/numeric/math/asin + + (T... args) + + std::uniform_int_distribution + std::type_info + + T + iscntrl + cpp/string/byte/iscntrl + + (T... args) + + + T + difftime + cpp/chrono/c/difftime + + (T... args) + + + T + terminate + cpp/error/terminate + + (T... args) + + + T + memcmp + cpp/string/byte/memcmp + + (T... args) + + std::fisher_f_distribution + + T + uninitialized_fill + cpp/memory/uninitialized_fill + + (T... args) + + std::strstream + + T + hex + cpp/io/manip/hex + + (T... args) + + + T + tie + cpp/utility/tuple/tie + + (T... args) + + + T + back_inserter + cpp/iterator/back_inserter + + (T... args) + + + T + upper_bound + cpp/algorithm/upper_bound + + (T... args) + + std::time_get_byname + std::basic_streambuf + + T + adjacent_find + cpp/algorithm/adjacent_find + + (T... args) + + std::is_nothrow_constructible + + T + use_facet + cpp/locale/use_facet + + (T... args) + + std::queue + std::is_base_of + std::intmax_t + std::ranlux24 + + T + vfwprintf + cpp/io/c/vfwprintf + + (T... args) + + + T + atomic_fetch_add + cpp/atomic/atomic_fetch_add + + (T... args) + + std::remove_cv + + T + fsetpos + cpp/io/c/fsetpos + + (T... args) + + + T + malloc + cpp/memory/c/malloc + + (T... args) + + + T + localtime + cpp/chrono/c/localtime + + (T... args) + + std::is_trivially_destructible + std::wcin + + T + wcscmp + cpp/string/wide/wcscmp + + (T... args) + + + T + c32rtomb + cpp/string/multibyte/c32rtomb + + (T... args) + + + T + isupper + cpp/string/byte/isupper + + (T... args) + + std::atomic + std::basic_stringstream + + T + wcstod + cpp/string/wide/wcstof + + (T... args) + + + T + tolower + cpp/string/byte/tolower + + (T... args) + + std::is_void + + T + sort_heap + cpp/algorithm/sort_heap + + (T... args) + + std::plus + + T + isdigit + cpp/string/byte/isdigit + + (T... args) + + std::bitset + + T + wcslen + cpp/string/wide/wcslen + + (T... args) + + + T + wmemcmp + cpp/string/wide/wmemcmp + + (T... args) + + std::FILE + + T + move_if_noexcept + cpp/utility/move_if_noexcept + + (T... args) + + + T + declval + cpp/utility/declval + + (T... args) + + + T + fpclassify + cpp/numeric/math/fpclassify + + (T... args) + + + T + iswupper + cpp/string/wide/iswupper + + (T... args) + + std::thread + std::future_error + std::time_base + std::alignment_of + std::time_put + std::bit_or + + T + rand + cpp/numeric/random/rand + + (T... args) + + + T + atomic_compare_exchange_weak_explicit + cpp/atomic/atomic_compare_exchange + + (T... args) + + std::pointer_traits + + T + partial_sort + cpp/algorithm/partial_sort + + (T... args) + + std::basic_string + + T + llrint + cpp/numeric/math/rint + + (T... args) + + std::priority_queue + + T + fclose + cpp/io/c/fclose + + (T... args) + + + T + reverse + cpp/algorithm/reverse + + (T... args) + + std::exa + + T + partial_sum + cpp/algorithm/partial_sum + + (T... args) + + std::wostringstream + + T + showbase + cpp/io/manip/showbase + + (T... args) + + std::is_default_constructible + std::cregex_iterator + + T + vswscanf + cpp/io/c/vfwscanf + + (T... args) + + std::wstring + + T + atan + cpp/numeric/math/atan + + (T... args) + + + T + atanh + cpp/numeric/math/atanh + + (T... args) + + std::remove_all_extents + + T + iter_swap + cpp/algorithm/iter_swap + + (T... args) + + + T + scalbln + cpp/numeric/math/scalbn + + (T... args) + + std::istrstream + + T + reverse_copy + cpp/algorithm/reverse_copy + + (T... args) + + std::unary_negate + std::unordered_multiset + std::basic_ostream + std::wsregex_iterator + std::uint_fast16_t + std::is_nothrow_assignable + + T + forward + cpp/utility/forward + + (T... args) + + std::moneypunct + + T + getc + cpp/io/c/fgetc + + (T... args) + + std::type_index + + T + equal_range + cpp/algorithm/equal_range + + (T... args) + + + T + atomic_fetch_sub + cpp/atomic/atomic_fetch_sub + + (T... args) + + + T + is_partitioned + cpp/algorithm/is_partitioned + + (T... args) + + + T + next_permutation + cpp/algorithm/next_permutation + + (T... args) + + + T + isblank + cpp/string/byte/isblank + + (T... args) + + + T + noshowpoint + cpp/io/manip/showpoint + + (T... args) + + + T + atan2 + cpp/numeric/math/atan2 + + (T... args) + + + T + nanf + cpp/numeric/math/nan + + (T... args) + + + T + towctrans + cpp/string/wide/towctrans + + (T... args) + + std::is_standard_layout + std::timed_mutex + + T + right + cpp/io/manip/left + + (T... args) + + + T + fputwc + cpp/io/c/fputwc + + (T... args) + + + T + strtoul + cpp/string/byte/strtoul + + (T... args) + + + T + is_heap + cpp/algorithm/is_heap + + (T... args) + + std::bad_exception + + T + fflush + cpp/io/c/fflush + + (T... args) + + + T + strtoumax + cpp/string/byte/strtoimax + + (T... args) + + + T + nexttoward + cpp/numeric/math/nextafter + + (T... args) + + std::int_fast64_t + std::function + + T + nounitbuf + cpp/io/manip/unitbuf + + (T... args) + + std::bad_cast + std::error_condition + std::filebuf + std::int_least16_t + + T + ispunct + cpp/string/byte/ispunct + + (T... args) + + std::istreambuf_iterator + std::u16string + + T + noboolalpha + cpp/io/manip/boolalpha + + (T... args) + + + T + make_pair + cpp/utility/pair/make_pair + + (T... args) + + std::is_error_condition_enum + std::is_nothrow_destructible + std::wiostream + + T + iswctype + cpp/string/wide/iswctype + + (T... args) + + std::allocator_arg_t + + T + srand + cpp/numeric/random/srand + + (T... args) + + std::rel_ops + std::uint_least32_t + std::collate + + T + replace_copy + cpp/algorithm/replace_copy + + (T... args) + + + T + future_category + cpp/thread/future/future_category + + (T... args) + + std::remove_const + + T + resetiosflags + cpp/io/manip/resetiosflags + + (T... args) + + + T + vprintf + cpp/io/c/vfprintf + + (T... args) + + std::u32string + std::uint_fast32_t + + T + gmtime + cpp/chrono/c/gmtime + + (T... args) + + std::is_lvalue_reference + + T + align + cpp/memory/align + + (T... args) + + + T + tuple_cat + cpp/utility/tuple/tuple_cat + + (T... args) + + + T + ends + cpp/io/manip/ends + + (T... args) + + + T + set_terminate + cpp/error/set_terminate + + (T... args) + + + T + lrint + cpp/numeric/math/rint + + (T... args) + + std::complex + std::ofstream + std::insert_iterator + std::bad_array_length + + T + none_of + cpp/algorithm/all_any_none_of + + (T... args) + + std::this_thread + + T + wscanf + cpp/io/c/fwscanf + + (T... args) + + + T + fputc + cpp/io/c/fputc + + (T... args) + + + T + dec + cpp/io/manip/hex + + (T... args) + + + T + strcat + cpp/string/byte/strcat + + (T... args) + + std::is_trivially_copyable + std::basic_istringstream + std::basic_ifstream + std::list + + T + raise + cpp/utility/program/raise + + (T... args) + + std::minus + + T + wcsspn + cpp/string/wide/wcsspn + + (T... args) + + + T + fabs + cpp/numeric/math/fabs + + (T... args) + + + T + wmemcpy + cpp/string/wide/wmemcpy + + (T... args) + + + T + copy_n + cpp/algorithm/copy_n + + (T... args) + + std::map + std::linear_congruential_engine + + T + rethrow_if_nested + cpp/error/rethrow_if_nested + + (T... args) + + + T + setlocale + cpp/locale/setlocale + + (T... args) + + std::codecvt_utf16 + + T + addressof + cpp/memory/addressof + + (T... args) + + + T + calloc + cpp/memory/c/calloc + + (T... args) + + std::cmatch + + T + strerror + cpp/string/byte/strerror + + (T... args) + + std::defer_lock_t + + T + strcpy + cpp/string/byte/strcpy + + (T... args) + + std::exception + + T + wcstoull + cpp/string/wide/wcstoul + + (T... args) + + + T + c16rtomb + cpp/string/multibyte/c16rtomb + + (T... args) + + std::front_insert_iterator + + T + generate_canonical + cpp/numeric/random/generate_canonical + + (T... args) + + + T + vfprintf + cpp/io/c/vfprintf + + (T... args) + + + T + notify_all_at_thread_exit + cpp/thread/notify_all_at_thread_exit + + (T... args) + + + T + rotate + cpp/algorithm/rotate + + (T... args) + + + T + current_exception + cpp/error/current_exception + + (T... args) + + + T + strtok + cpp/string/byte/strtok + + (T... args) + + + T + wcscat + cpp/string/wide/wcscat + + (T... args) + + + T + strncpy + cpp/string/byte/strncpy + + (T... args) + + + T + towlower + cpp/string/wide/towlower + + (T... args) + + + T + floor + cpp/numeric/math/floor + + (T... args) + + std::zetta + + T + left + cpp/io/manip/left + + (T... args) + + + T + ferror + cpp/io/c/ferror + + (T... args) + + std::streambuf + + T + atomic_load_explicit + cpp/atomic/atomic_load + + (T... args) + + std::experimental + std::num_put + + T + swap + cpp/algorithm/swap + + (T... args) + + + T + acos + cpp/numeric/math/acos + + (T... args) + + std::owner_less + + T + wcscoll + cpp/string/wide/wcscoll + + (T... args) + + + T + sqrt + cpp/numeric/math/sqrt + + (T... args) + + std::extent + + T + mbsinit + cpp/string/multibyte/mbsinit + + (T... args) + + std::bad_optional_access + + T + qsort + cpp/algorithm/qsort + + (T... args) + + + T + stoll + cpp/string/basic_string/stol + + (T... args) + + + T + put_money + cpp/io/manip/put_money + + (T... args) + + + T + wcstoul + cpp/string/wide/wcstoul + + (T... args) + + + T + wcstol + cpp/string/wide/wcstol + + (T... args) + + + T + atexit + cpp/utility/program/atexit + + (T... args) + + + T + atomic_fetch_or + cpp/atomic/atomic_fetch_or + + (T... args) + + + T + rewind + cpp/io/c/rewind + + (T... args) + + + T + wcsxfrm + cpp/string/wide/wcsxfrm + + (T... args) + + std::yotta + std::wcregex_token_iterator + + T + round + cpp/numeric/math/round + + (T... args) + + std::uint64_t + std::messages + + T + vwprintf + cpp/io/c/vfwprintf + + (T... args) + + + T + all_of + cpp/algorithm/all_any_none_of + + (T... args) + + std::regex_token_iterator + + T + replace + cpp/algorithm/replace + + (T... args) + + std::move_iterator + + T + remquo + cpp/numeric/math/remquo + + (T... args) + + + T + setbuf + cpp/io/c/setbuf + + (T... args) + + std::messages_base + + T + strncmp + cpp/string/byte/strncmp + + (T... args) + + + T + localeconv + cpp/locale/localeconv + + (T... args) + + + T + wctrans + cpp/string/wide/wctrans + + (T... args) + + std::istringstream + std::giga + + T + any_of + cpp/algorithm/all_any_none_of + + (T... args) + + std::integer_sequence + + T + equal + cpp/algorithm/equal + + (T... args) + + + T + max + cpp/algorithm/max + + (T... args) + + + T + strxfrm + cpp/string/byte/strxfrm + + (T... args) + + std::has_virtual_destructor + std::max_align_t + std::remove_volatile + std::underlying_type + + T + iswxdigit + cpp/string/wide/iswxdigit + + (T... args) + + + T + labs + cpp/numeric/math/abs + + (T... args) + + std::hecto + + T + regex_match + cpp/regex/regex_match + + (T... args) + + std::is_member_object_pointer + std::exception_ptr + + T + fputws + cpp/io/c/fputws + + (T... args) + + + T + wcrtomb + cpp/string/multibyte/wcrtomb + + (T... args) + + + T + setprecision + cpp/io/manip/setprecision + + (T... args) + + + T + setvbuf + cpp/io/c/setvbuf + + (T... args) + + std::nested_exception + std::random_access_iterator_tag + + T + regex_replace + cpp/regex/regex_replace + + (T... args) + + std::ctype + + T + freopen + cpp/io/c/freopen + + (T... args) + + + T + logb + cpp/numeric/math/logb + + (T... args) + + std::time_t + + T + wctob + cpp/string/multibyte/wctob + + (T... args) + + std::knuth_b + + T + atomic_load + cpp/atomic/atomic_load + + (T... args) + + + T + search_n + cpp/algorithm/search_n + + (T... args) + + + T + toupper + cpp/string/byte/toupper + + (T... args) + + std::auto_ptr + + T + move_backward + cpp/algorithm/move_backward + + (T... args) + + + T + is_sorted + cpp/algorithm/is_sorted + + (T... args) + + std::minstd_rand0 + + T + strtoull + cpp/string/byte/strtoul + + (T... args) + + std::sregex_token_iterator + std::logical_not + std::fpos_t + + T + iswblank + cpp/string/wide/iswblank + + (T... args) + + std::istream + std::seed_seq + std::default_delete + std::femto + std::clock_t + std::true_type + + T + get_pointer_safety + cpp/memory/gc/get_pointer_safety + + (T... args) + + std::mbstate_t + + T + get_unexpected + cpp/error/get_unexpected + + (T... args) + + + T + sscanf + cpp/io/c/fscanf + + (T... args) + + std::ostrstream + std::gamma_distribution + std::bad_weak_ptr + std::output_iterator_tag + std::micro + std::is_trivial + + T + fesetenv + cpp/numeric/fenv/feenv + + (T... args) + + + T + atomic_store_explicit + cpp/atomic/atomic_store + + (T... args) + + + T + strtold + cpp/string/byte/strtof + + (T... args) + + + T + fread + cpp/io/c/fread + + (T... args) + + std::packaged_task + std::unordered_set + std::is_volatile + + T + memchr + cpp/string/byte/memchr + + (T... args) + + + T + btowc + cpp/string/multibyte/btowc + + (T... args) + + std::wfstream + + T + replace_if + cpp/algorithm/replace + + (T... args) + + std::multimap + + T + strcoll + cpp/string/byte/strcoll + + (T... args) + + + T + vsprintf + cpp/io/c/vfprintf + + (T... args) + + + T + mismatch + cpp/algorithm/mismatch + + (T... args) + + + T + getchar + cpp/io/c/getchar + + (T... args) + + std::atomic_flag + + T + islower + cpp/string/byte/islower + + (T... args) + + + T + tmpnam + cpp/io/c/tmpnam + + (T... args) + + std::numpunct_byname + + T + nanl + cpp/numeric/math/nan + + (T... args) + + std::binomial_distribution + + T + fopen + cpp/io/c/fopen + + (T... args) + + std::basic_iostream + std::wofstream + std::fpos + std::underflow_error + + T + for_each + cpp/algorithm/for_each + + (T... args) + + + T + fegetround + cpp/numeric/fenv/feround + + (T... args) + + + T + ungetc + cpp/io/c/ungetc + + (T... args) + + std::cauchy_distribution + std::is_trivially_copy_constructible + std::conditional + std::is_pod + + T + internal + cpp/io/manip/left + + (T... args) + + + T + vfwscanf + cpp/io/c/vfwscanf + + (T... args) + + std::int_least8_t + + T + fgetc + cpp/io/c/fgetc + + (T... args) + + std::streamoff + std::is_move_assignable + std::int_least32_t + + T + wcstof + cpp/string/wide/wcstof + + (T... args) + + std::wstringstream + std::subtract_with_carry_engine + std::regex_error + + T + bind + cpp/utility/functional/bind + + (T... args) + + + T + skipws + cpp/io/manip/skipws + + (T... args) + + std::is_constructible + std::piecewise_construct_t + + T + iswprint + cpp/string/wide/iswprint + + (T... args) + + + T + wcstombs + cpp/string/multibyte/wcstombs + + (T... args) + + + T + inplace_merge + cpp/algorithm/inplace_merge + + (T... args) + + + T + copysign + cpp/numeric/math/copysign + + (T... args) + + + T + putwchar + cpp/io/c/putwchar + + (T... args) + + std::mutex + + T + wcsstr + cpp/string/wide/wcsstr + + (T... args) + + + T + fegetenv + cpp/numeric/fenv/feenv + + (T... args) + + + T + longjmp + cpp/utility/program/longjmp + + (T... args) + + + T + iswcntrl + cpp/string/wide/iswcntrl + + (T... args) + + std::system_error + + T + declare_no_pointers + cpp/memory/gc/declare_no_pointers + + (T... args) + + + T + isnormal + cpp/numeric/math/isnormal + + (T... args) + + + T + swap_ranges + cpp/algorithm/swap_ranges + + (T... args) + + std::wistringstream + std::is_floating_point + + T + minmax + cpp/algorithm/minmax + + (T... args) + + + T + defaultfloat + cpp/io/manip/fixed + + (T... args) + + + T + rename + cpp/io/c/rename + + (T... args) + + + T + snprintf + cpp/io/c/fprintf + + (T... args) + + + T + try_lock + cpp/thread/try_lock + + (T... args) + + std::ratio_not_equal + std::ratio_multiply + std::result_of + std::is_fundamental + + T + stoul + cpp/string/basic_string/stoul + + (T... args) + + std::ifstream + std::u32streampos + + T + fgetpos + cpp/io/c/fgetpos + + (T... args) + + std::length_error + + T + partition_copy + cpp/algorithm/partition_copy + + (T... args) + + + T + vscanf + cpp/io/c/vfscanf + + (T... args) + + + T + front_inserter + cpp/iterator/front_inserter + + (T... args) + + std::sub_match + std::common_type + + T + get_terminate + cpp/error/get_terminate + + (T... args) + + + T + cosh + cpp/numeric/math/cosh + + (T... args) + + std::shared_timed_mutex + std::array + std::random_device + std::default_random_engine + std::raw_storage_iterator + std::is_convertible + + T + prev + cpp/iterator/prev + + (T... args) + + std::uint16_t + + T + strchr + cpp/string/byte/strchr + + (T... args) + + std::is_array + + T + strstr + cpp/string/byte/strstr + + (T... args) + + std::mega + + T + printf + cpp/io/c/fprintf + + (T... args) + + std::numpunct + std::money_put + std::new_handler + std::is_member_function_pointer + + T + setfill + cpp/io/manip/setfill + + (T... args) + + + T + inner_product + cpp/algorithm/inner_product + + (T... args) + + + + std::is_function + cpp/types/is_function + + + std::input_iterator_tag + cpp/iterator/iterator_tags + + + std::logical_and + cpp/utility/functional/logical_and + + T + operator() + cpp/utility/functional/logical_and + + (T... args) + + + + std::is_integral + cpp/types/is_integral + + + std::money_get + cpp/locale/money_get + + T + do_get + cpp/locale/money_get/get + + (T... args) + + std::money_get::char_type + std::money_get::pattern + + T + get + cpp/locale/money_get/get + + (T... args) + + + T + ~money_get + cpp/locale/money_get/~money_get + + (T... args) + + std::money_get::string_type + std::money_get::iter_type + + T + money_get + cpp/locale/money_get/money_get + + (T... args) + + + + std::money_get::char_type + cpp/locale/money_get + + + std::money_get::pattern + cpp/locale/money_base + + + std::money_get::string_type + cpp/locale/money_get + + + std::money_get::iter_type + cpp/locale/money_get + + + std::basic_ofstream + cpp/io/basic_ofstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + basic_ofstream + cpp/io/basic_ofstream/basic_ofstream + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + std::basic_ofstream::event_callback + + T + open + cpp/io/basic_ofstream/open + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + close + cpp/io/basic_ofstream/close + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::basic_ofstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + is_open + cpp/io/basic_ofstream/is_open + + (T... args) + + + T + operator= + cpp/io/basic_ofstream/operator= + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + std::basic_ofstream::sentry + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::basic_ofstream::event_callback + cpp/io/ios_base/event_callback + + + std::basic_ofstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::basic_ofstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_ostream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + + std::ratio_subtract + cpp/numeric/ratio/ratio_subtract + + + std::size_t + cpp/types/size_t + + + std::ctype_byname + cpp/locale/ctype_byname + + T + ~ctype_byname + cpp/locale/ctype_byname + + (T... args) + + + T + ctype_byname + cpp/locale/ctype_byname + + (T... args) + + + T + do_toupper + cpp/locale/ctype/toupper + + (T... args) + + + T + toupper + cpp/locale/ctype/toupper + + (T... args) + + + T + do_scan_is + cpp/locale/ctype/scan_is + + (T... args) + + + T + do_tolower + cpp/locale/ctype/tolower + + (T... args) + + + T + do_narrow + cpp/locale/ctype/narrow + + (T... args) + + + T + widen + cpp/locale/ctype/widen + + (T... args) + + + T + is + cpp/locale/ctype/is + + (T... args) + + + T + scan_is + cpp/locale/ctype/scan_is + + (T... args) + + + T + tolower + cpp/locale/ctype/tolower + + (T... args) + + + T + do_is + cpp/locale/ctype/is + + (T... args) + + + T + narrow + cpp/locale/ctype/narrow + + (T... args) + + std::ctype_byname::mask + + T + do_widen + cpp/locale/ctype/widen + + (T... args) + + + + std::ctype_byname::mask + cpp/locale/ctype_base + + + std::wcout + cpp/io/basic_ostream + + + std::fstream + cpp/io/basic_fstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + open + cpp/io/basic_fstream/open + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + fstream + cpp/io/basic_fstream/basic_fstream + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + std::fstream::sentry + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + std::fstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + close + cpp/io/basic_fstream/close + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::fstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + is_open + cpp/io/basic_fstream/is_open + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + operator= + cpp/io/basic_fstream/operator= + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::fstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::fstream::event_callback + cpp/io/ios_base/event_callback + + + std::fstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::valarray + cpp/numeric/valarray + + + std::ratio_greater_equal + cpp/numeric/ratio/ratio_greater_equal + + + std::remove_extent + cpp/types/remove_extent + + + std::ratio_greater + cpp/numeric/ratio/ratio_greater + + + std::intptr_t + cpp/types/integer + + + std::regex_iterator + cpp/regex/regex_iterator + + T + operator!= + cpp/regex/regex_iterator/operator_cmp + + (T... args) + + + T + operator= + cpp/regex/regex_iterator/operator= + + (T... args) + + + T + operator== + cpp/regex/regex_iterator/operator_cmp + + (T... args) + + + T + operator-> + cpp/regex/regex_iterator/operator* + + (T... args) + + + T + regex_iterator + cpp/regex/regex_iterator/regex_iterator + + (T... args) + + + T + operator++ + cpp/regex/regex_iterator/operator_arith + + (T... args) + + + T + operator* + cpp/regex/regex_iterator/operator* + + (T... args) + + + T + operator++(int) + cpp/regex/regex_iterator/operator_arith + + (T... args) + + + + std::lock_guard + cpp/thread/lock_guard + + T + ~lock_guard + cpp/thread/lock_guard/~lock_guard + + (T... args) + + + T + lock_guard + cpp/thread/lock_guard/lock_guard + + (T... args) + + + + std::wbuffer_convert + cpp/locale/wbuffer_convert + + T + state + cpp/locale/wbuffer_convert/state + + (T... args) + + + T + wbuffer_convert + cpp/locale/wbuffer_convert/wbuffer_convert + + (T... args) + + + T + rdbuf + cpp/locale/wbuffer_convert/rdbuf + + (T... args) + + + T + ~wbuffer_convert + cpp/locale/wbuffer_convert/~wbuffer_convert + + (T... args) + + + + std::modulus + cpp/utility/functional/modulus + + T + operator() + cpp/utility/functional/modulus + + (T... args) + + + + std::ratio_divide + cpp/numeric/ratio/ratio_divide + + + std::ostreambuf_iterator + cpp/iterator/ostreambuf_iterator + + + std::dynarray + cpp/container/dynarray + + T + rbegin + cpp/container/dynarray/rbegin + + (T... args) + + + T + crend + cpp/container/dynarray/rend + + (T... args) + + + T + begin + cpp/container/dynarray/begin + + (T... args) + + + T + data + cpp/container/dynarray/data + + (T... args) + + + T + at + cpp/container/dynarray/at + + (T... args) + + + T + back + cpp/container/dynarray/back + + (T... args) + + + T + end + cpp/container/dynarray/end + + (T... args) + + + T + fill + cpp/container/dynarray/fill + + (T... args) + + + T + empty + cpp/container/dynarray/empty + + (T... args) + + + T + size + cpp/container/dynarray/size + + (T... args) + + + T + cend + cpp/container/dynarray/end + + (T... args) + + + T + ~dynarray + cpp/container/dynarray/~dynarray + + (T... args) + + + T + max_size + cpp/container/dynarray/max_size + + (T... args) + + + T + rend + cpp/container/dynarray/rend + + (T... args) + + + T + front + cpp/container/dynarray/front + + (T... args) + + + T + dynarray + cpp/container/dynarray/dynarray + + (T... args) + + + T + operator[] + cpp/container/dynarray/operator_at + + (T... args) + + + T + crbegin + cpp/container/dynarray/rbegin + + (T... args) + + + T + cbegin + cpp/container/dynarray/begin + + (T... args) + + + + std::is_nothrow_move_constructible + cpp/types/is_move_constructible + + + std::vector + cpp/container/vector + + T + push_back + cpp/container/vector/push_back + + (T... args) + + + T + crbegin + cpp/container/vector/rbegin + + (T... args) + + + T + erase + cpp/container/vector/erase + + (T... args) + + + T + data + cpp/container/vector/data + + (T... args) + + + T + insert + cpp/container/vector/insert + + (T... args) + + + T + pop_back + cpp/container/vector/pop_back + + (T... args) + + + T + shrink_to_fit + cpp/container/vector/shrink_to_fit + + (T... args) + + + T + back + cpp/container/vector/back + + (T... args) + + + T + end + cpp/container/vector/end + + (T... args) + + + T + resize + cpp/container/vector/resize + + (T... args) + + + T + emplace_back + cpp/container/vector/emplace_back + + (T... args) + + + T + size + cpp/container/vector/size + + (T... args) + + + T + cbegin + cpp/container/vector/begin + + (T... args) + + + T + front + cpp/container/vector/front + + (T... args) + + + T + ~vector + cpp/container/vector/~vector + + (T... args) + + + T + rbegin + cpp/container/vector/rbegin + + (T... args) + + + T + crend + cpp/container/vector/rend + + (T... args) + + + T + assign + cpp/container/vector/assign + + (T... args) + + + T + operator= + cpp/container/vector/operator= + + (T... args) + + + T + vector + cpp/container/vector/vector + + (T... args) + + + T + reserve + cpp/container/vector/reserve + + (T... args) + + + T + capacity + cpp/container/vector/capacity + + (T... args) + + + T + empty + cpp/container/vector/empty + + (T... args) + + + T + cend + cpp/container/vector/end + + (T... args) + + + T + swap + cpp/container/vector/swap + + (T... args) + + + T + max_size + cpp/container/vector/max_size + + (T... args) + + + T + rend + cpp/container/vector/rend + + (T... args) + + + T + get_allocator + cpp/container/vector/get_allocator + + (T... args) + + + T + clear + cpp/container/vector/clear + + (T... args) + + + T + at + cpp/container/vector/at + + (T... args) + + + T + emplace + cpp/container/vector/emplace + + (T... args) + + + T + operator[] + cpp/container/vector/operator_at + + (T... args) + + + T + begin + cpp/container/vector/begin + + (T... args) + + + + std::match_results + cpp/regex/match_results + + T + cbegin + cpp/regex/match_results/begin + + (T... args) + + + T + format + cpp/regex/match_results/format + + (T... args) + + + T + ~match_results + cpp/regex/match_results/~match_results + + (T... args) + + + T + size + cpp/regex/match_results/size + + (T... args) + + + T + swap + cpp/regex/match_results/swap + + (T... args) + + + T + position + cpp/regex/match_results/position + + (T... args) + + + T + prefix + cpp/regex/match_results/prefix + + (T... args) + + + T + str + cpp/regex/match_results/str + + (T... args) + + + T + begin + cpp/regex/match_results/begin + + (T... args) + + + T + empty + cpp/regex/match_results/empty + + (T... args) + + + T + suffix + cpp/regex/match_results/suffix + + (T... args) + + + T + get_allocator + cpp/regex/match_results/get_allocator + + (T... args) + + + T + end + cpp/regex/match_results/end + + (T... args) + + + T + match_results + cpp/regex/match_results/match_results + + (T... args) + + + T + ready + cpp/regex/match_results/ready + + (T... args) + + + T + cend + cpp/regex/match_results/end + + (T... args) + + + T + operator[] + cpp/regex/match_results/operator_at + + (T... args) + + + T + length + cpp/regex/match_results/length + + (T... args) + + + T + max_size + cpp/regex/match_results/max_size + + (T... args) + + + + std::back_insert_iterator + cpp/iterator/back_insert_iterator + + + std::iterator + cpp/iterator/iterator + + + std::int8_t + cpp/types/integer + + + std::student_t_distribution + cpp/numeric/random/student_t_distribution + + T + n + cpp/numeric/random/student_t_distribution/n + + (T... args) + + + T + reset + cpp/numeric/random/student_t_distribution/reset + + (T... args) + + + T + max + cpp/numeric/random/student_t_distribution/max + + (T... args) + + + T + operator() + cpp/numeric/random/student_t_distribution/operator() + + (T... args) + + + T + student_t_distribution + cpp/numeric/random/student_t_distribution/student_t_distribution + + (T... args) + + + T + param + cpp/numeric/random/student_t_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/student_t_distribution/min + + (T... args) + + + + std::mt19937_64 + cpp/numeric/random/mersenne_twister_engine + + T + discard + cpp/numeric/random/mersenne_twister_engine/discard + + (T... args) + + + T + mt19937_64 + cpp/numeric/random/mersenne_twister_engine/mersenne_twister_engine + + (T... args) + + + T + max + cpp/numeric/random/mersenne_twister_engine/max + + (T... args) + + + T + operator() + cpp/numeric/random/mersenne_twister_engine/operator() + + (T... args) + + + T + seed + cpp/numeric/random/mersenne_twister_engine/seed + + (T... args) + + + T + min + cpp/numeric/random/mersenne_twister_engine/min + + (T... args) + + + + std::runtime_error + cpp/error/runtime_error + + T + runtime_error + cpp/error/runtime_error + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::ranlux24_base + cpp/numeric/random/subtract_with_carry_engine + + T + discard + cpp/numeric/random/subtract_with_carry_engine/discard + + (T... args) + + + T + ranlux24_base + cpp/numeric/random/subtract_with_carry_engine/subtract_with_carry_engine + + (T... args) + + + T + max + cpp/numeric/random/subtract_with_carry_engine/max + + (T... args) + + + T + operator() + cpp/numeric/random/subtract_with_carry_engine/operator() + + (T... args) + + + T + seed + cpp/numeric/random/subtract_with_carry_engine/seed + + (T... args) + + + T + min + cpp/numeric/random/subtract_with_carry_engine/min + + (T... args) + + + + std::allocator_traits + cpp/memory/allocator_traits + + T + destroy + cpp/memory/allocator_traits/destroy + + (T... args) + + + T + select_on_container_copy_construction + cpp/memory/allocator_traits/select_on_container_copy_construction + + (T... args) + + + T + max_size + cpp/memory/allocator_traits/max_size + + (T... args) + + + T + allocate + cpp/memory/allocator_traits/allocate + + (T... args) + + + T + deallocate + cpp/memory/allocator_traits/deallocate + + (T... args) + + + T + construct + cpp/memory/allocator_traits/construct + + (T... args) + + + + std::codecvt + cpp/locale/codecvt + std::codecvt::extern_type + + T + out + cpp/locale/codecvt/out + + (T... args) + + + T + do_length + cpp/locale/codecvt/length + + (T... args) + + + T + always_noconv + cpp/locale/codecvt/always_noconv + + (T... args) + + + T + do_encoding + cpp/locale/codecvt/encoding + + (T... args) + + + T + do_in + cpp/locale/codecvt/in + + (T... args) + + + T + unshift + cpp/locale/codecvt/unshift + + (T... args) + + std::codecvt::state_type + + T + max_length + cpp/locale/codecvt/max_length + + (T... args) + + + T + encoding + cpp/locale/codecvt/encoding + + (T... args) + + + T + codecvt + cpp/locale/codecvt/codecvt + + (T... args) + + + T + do_unshift + cpp/locale/codecvt/unshift + + (T... args) + + + T + do_out + cpp/locale/codecvt/out + + (T... args) + + + T + do_max_length + cpp/locale/codecvt/max_length + + (T... args) + + + T + do_always_noconv + cpp/locale/codecvt/always_noconv + + (T... args) + + + T + in + cpp/locale/codecvt/in + + (T... args) + + std::codecvt::intern_type + + T + length + cpp/locale/codecvt/length + + (T... args) + + + T + ~codecvt + cpp/locale/codecvt/~codecvt + + (T... args) + + + + std::codecvt::extern_type + cpp/locale/codecvt + + + std::codecvt::state_type + cpp/locale/codecvt + + + std::codecvt::intern_type + cpp/locale/codecvt + + + std::ratio_less_equal + cpp/numeric/ratio/ratio_less_equal + + + std::condition_variable_any + cpp/thread/condition_variable_any + + T + condition_variable_any + cpp/thread/condition_variable_any/condition_variable_any + + (T... args) + + + T + notify_one + cpp/thread/condition_variable_any/notify_one + + (T... args) + + + T + wait_for + cpp/thread/condition_variable_any/wait_for + + (T... args) + + + T + native_handle + cpp/thread/condition_variable_any/native_handle + + (T... args) + + + T + notify_all + cpp/thread/condition_variable_any/notify_all + + (T... args) + + + T + ~condition_variable_any + cpp/thread/condition_variable_any/~condition_variable_any + + (T... args) + + + T + wait_until + cpp/thread/condition_variable_any/wait_until + + (T... args) + + + T + wait + cpp/thread/condition_variable_any/wait + + (T... args) + + + + std::deca + cpp/numeric/ratio/ratio + + + std::extreme_value_distribution + cpp/numeric/random/extreme_value_distribution + + T + max + cpp/numeric/random/extreme_value_distribution/max + + (T... args) + + + T + b + cpp/numeric/random/extreme_value_distribution/params + + (T... args) + + + T + a + cpp/numeric/random/extreme_value_distribution/params + + (T... args) + + + T + operator() + cpp/numeric/random/extreme_value_distribution/operator() + + (T... args) + + + T + extreme_value_distribution + cpp/numeric/random/extreme_value_distribution/extreme_value_distribution + + (T... args) + + + T + param + cpp/numeric/random/extreme_value_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/extreme_value_distribution/min + + (T... args) + + + T + reset + cpp/numeric/random/extreme_value_distribution/reset + + (T... args) + + + + std::cout + cpp/io/basic_ostream + + + std::decay + cpp/types/decay + + + std::is_trivially_move_assignable + cpp/types/is_move_assignable + + + std::adopt_lock_t + cpp/thread/lock_tag_t + + + std::wcerr + cpp/io/basic_ostream + + + std::lognormal_distribution + cpp/numeric/random/lognormal_distribution + + T + max + cpp/numeric/random/lognormal_distribution/max + + (T... args) + + + T + reset + cpp/numeric/random/lognormal_distribution/reset + + (T... args) + + + T + lognormal_distribution + cpp/numeric/random/lognormal_distribution/lognormal_distribution + + (T... args) + + + T + m + cpp/numeric/random/lognormal_distribution/params + + (T... args) + + + T + operator() + cpp/numeric/random/lognormal_distribution/operator() + + (T... args) + + + T + s + cpp/numeric/random/lognormal_distribution/params + + (T... args) + + + T + param + cpp/numeric/random/lognormal_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/lognormal_distribution/min + + (T... args) + + + + std::wclog + cpp/io/basic_ostream + + + std::char_traits + cpp/string/char_traits + + T + assign + cpp/string/char_traits/assign + + (T... args) + + + T + not_eof + cpp/string/char_traits/not_eof + + (T... args) + + + T + to_int_type + cpp/string/char_traits/to_int_type + + (T... args) + + + T + to_char_type + cpp/string/char_traits/to_char_type + + (T... args) + + + T + eq + cpp/string/char_traits/cmp + + (T... args) + + + T + copy + cpp/string/char_traits/copy + + (T... args) + + + T + length + cpp/string/char_traits/length + + (T... args) + + + T + lt + cpp/string/char_traits/cmp + + (T... args) + + + T + eof + cpp/string/char_traits/eof + + (T... args) + + + T + find + cpp/string/char_traits/find + + (T... args) + + + T + move + cpp/string/char_traits/move + + (T... args) + + + T + compare + cpp/string/char_traits/compare + + (T... args) + + + T + eq_int_type + cpp/string/char_traits/eq_int_type + + (T... args) + + + + std::remove_reference + cpp/types/remove_reference + + + std::num_get + cpp/locale/num_get + + T + do_get + cpp/locale/num_get/get + + (T... args) + + std::num_get::char_type + std::num_get::iter_type + + T + num_get + cpp/locale/num_get/num_get + + (T... args) + + + T + ~num_get + cpp/locale/num_get/~num_get + + (T... args) + + + T + get + cpp/locale/num_get/get + + (T... args) + + + + std::num_get::char_type + cpp/locale/num_get + + + std::num_get::iter_type + cpp/locale/num_get + + + std::is_pointer + cpp/types/is_pointer + + + std::multiset + cpp/container/multiset + + T + begin + cpp/container/multiset/begin + + (T... args) + + + T + erase + cpp/container/multiset/erase + + (T... args) + + + T + insert + cpp/container/multiset/insert + + (T... args) + + + T + swap + cpp/container/multiset/swap + + (T... args) + + + T + end + cpp/container/multiset/end + + (T... args) + + + T + emplace_hint + cpp/container/multiset/emplace_hint + + (T... args) + + + T + key_comp + cpp/container/multiset/key_comp + + (T... args) + + + T + cbegin + cpp/container/multiset/begin + + (T... args) + + + T + count + cpp/container/multiset/count + + (T... args) + + + T + find + cpp/container/multiset/find + + (T... args) + + + T + crbegin + cpp/container/multiset/rbegin + + (T... args) + + + T + multiset + cpp/container/multiset/multiset + + (T... args) + + + T + upper_bound + cpp/container/multiset/upper_bound + + (T... args) + + + T + rbegin + cpp/container/multiset/rbegin + + (T... args) + + + T + crend + cpp/container/multiset/rend + + (T... args) + + + T + size + cpp/container/multiset/size + + (T... args) + + + T + operator= + cpp/container/multiset/operator= + + (T... args) + + + T + ~multiset + cpp/container/multiset/~multiset + + (T... args) + + + T + value_comp + cpp/container/multiset/value_comp + + (T... args) + + + T + empty + cpp/container/multiset/empty + + (T... args) + + + T + lower_bound + cpp/container/multiset/lower_bound + + (T... args) + + + T + get_allocator + cpp/container/multiset/get_allocator + + (T... args) + + + T + max_size + cpp/container/multiset/max_size + + (T... args) + + + T + rend + cpp/container/multiset/rend + + (T... args) + + + T + cend + cpp/container/multiset/end + + (T... args) + + + T + clear + cpp/container/multiset/clear + + (T... args) + + + T + equal_range + cpp/container/multiset/equal_range + + (T... args) + + + T + emplace + cpp/container/multiset/emplace + + (T... args) + + + + std::weak_ptr + cpp/memory/weak_ptr + + T + operator= + cpp/memory/weak_ptr/operator= + + (T... args) + + + T + swap + cpp/memory/weak_ptr/swap + + (T... args) + + + T + weak_ptr + cpp/memory/weak_ptr/weak_ptr + + (T... args) + + + T + owner_before + cpp/memory/weak_ptr/owner_before + + (T... args) + + + T + ~weak_ptr + cpp/memory/weak_ptr/~weak_ptr + + (T... args) + + + T + use_count + cpp/memory/weak_ptr/use_count + + (T... args) + + + T + expired + cpp/memory/weak_ptr/expired + + (T... args) + + + T + lock + cpp/memory/weak_ptr/lock + + (T... args) + + + T + reset + cpp/memory/weak_ptr/reset + + (T... args) + + + + std::bidirectional_iterator_tag + cpp/iterator/iterator_tags + + + std::wstring_convert + cpp/locale/wstring_convert + + T + converted + cpp/locale/wstring_convert/converted + + (T... args) + + + T + to_bytes + cpp/locale/wstring_convert/to_bytes + + (T... args) + + + T + ~wstring_convert + cpp/locale/wstring_convert/~wstring_convert + + (T... args) + + + T + state + cpp/locale/wstring_convert/state + + (T... args) + + + T + wstring_convert + cpp/locale/wstring_convert/wstring_convert + + (T... args) + + + T + from_bytes + cpp/locale/wstring_convert/from_bytes + + (T... args) + + + + std::greater_equal + cpp/utility/functional/greater_equal + + T + operator() + cpp/utility/functional/greater_equal + + (T... args) + + + + std::is_trivially_constructible + cpp/types/is_constructible + + + std::string + cpp/string/basic_string + + T + push_back + cpp/string/basic_string/push_back + + (T... args) + + + T + shrink_to_fit + cpp/string/basic_string/shrink_to_fit + + (T... args) + + + T + rfind + cpp/string/basic_string/rfind + + (T... args) + + + T + begin + cpp/string/basic_string/begin + + (T... args) + + + T + erase + cpp/string/basic_string/erase + + (T... args) + + + T + append + cpp/string/basic_string/append + + (T... args) + + + T + data + cpp/string/basic_string/data + + (T... args) + + + T + insert + cpp/string/basic_string/insert + + (T... args) + + + T + assign + cpp/string/basic_string/assign + + (T... args) + + + T + find_first_not_of + cpp/string/basic_string/find_first_not_of + + (T... args) + + + T + back + cpp/string/basic_string/back + + (T... args) + + + T + end + cpp/string/basic_string/end + + (T... args) + + + T + resize + cpp/string/basic_string/resize + + (T... args) + + + T + copy + cpp/string/basic_string/copy + + (T... args) + + + T + find_last_of + cpp/string/basic_string/find_last_of + + (T... args) + + + T + pop_back + cpp/string/basic_string/pop_back + + (T... args) + + + T + replace + cpp/string/basic_string/replace + + (T... args) + + + T + front + cpp/string/basic_string/front + + (T... args) + + + T + substr + cpp/string/basic_string/substr + + (T... args) + + + T + find + cpp/string/basic_string/find + + (T... args) + + + T + compare + cpp/string/basic_string/compare + + (T... args) + + + T + crbegin + cpp/string/basic_string/rbegin + + (T... args) + + + T + cbegin + cpp/string/basic_string/begin + + (T... args) + + + T + find_first_of + cpp/string/basic_string/find_first_of + + (T... args) + + + T + rbegin + cpp/string/basic_string/rbegin + + (T... args) + + + T + crend + cpp/string/basic_string/rend + + (T... args) + + + T + size + cpp/string/basic_string/size + + (T... args) + + + T + operator= + cpp/string/basic_string/operator= + + (T... args) + + + T + find_last_not_of + cpp/string/basic_string/find_last_not_of + + (T... args) + + + T + reserve + cpp/string/basic_string/reserve + + (T... args) + + + T + capacity + cpp/string/basic_string/capacity + + (T... args) + + + T + c_str + cpp/string/basic_string/c_str + + (T... args) + + + T + empty + cpp/string/basic_string/empty + + (T... args) + + + T + cend + cpp/string/basic_string/end + + (T... args) + + + T + string + cpp/string/basic_string/basic_string + + (T... args) + + + T + max_size + cpp/string/basic_string/max_size + + (T... args) + + + T + rend + cpp/string/basic_string/rend + + (T... args) + + + T + get_allocator + cpp/string/basic_string/get_allocator + + (T... args) + + + T + clear + cpp/string/basic_string/clear + + (T... args) + + + T + at + cpp/string/basic_string/at + + (T... args) + + + T + swap + cpp/string/basic_string/swap + + (T... args) + + + T + operator[] + cpp/string/basic_string/operator_at + + (T... args) + + + T + length + cpp/string/basic_string/size + + (T... args) + + + + std::discrete_distribution + cpp/numeric/random/discrete_distribution + + T + probabilities + cpp/numeric/random/discrete_distribution/probabilities + + (T... args) + + + T + reset + cpp/numeric/random/discrete_distribution/reset + + (T... args) + + + T + operator() + cpp/numeric/random/discrete_distribution/operator() + + (T... args) + + + T + discrete_distribution + cpp/numeric/random/discrete_distribution/discrete_distribution + + (T... args) + + + T + max + cpp/numeric/random/discrete_distribution/max + + (T... args) + + + T + param + cpp/numeric/random/discrete_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/discrete_distribution/min + + (T... args) + + + + std::wostream + cpp/io/basic_ostream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + std::wostream::event_callback + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + ~wostream + cpp/io/basic_ostream/~basic_ostream + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + wostream + cpp/io/basic_ostream/basic_ostream + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::wostream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + std::wostream::sentry + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::wostream::event_callback + cpp/io/ios_base/event_callback + + + std::wostream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::wostream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_ostream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + + std::is_polymorphic + cpp/types/is_polymorphic + + + std::reverse_iterator + cpp/iterator/reverse_iterator + + + std::bad_array_new_length + cpp/memory/new/bad_array_new_length + + T + bad_array_new_length + cpp/memory/new/bad_array_new_length/bad_array_new_length + + (T... args) + + + T + what + cpp/memory/new/bad_alloc + + (T... args) + + + + std::condition_variable + cpp/thread/condition_variable + + T + wait + cpp/thread/condition_variable/wait + + (T... args) + + + T + notify_one + cpp/thread/condition_variable/notify_one + + (T... args) + + + T + wait_for + cpp/thread/condition_variable/wait_for + + (T... args) + + + T + notify_all + cpp/thread/condition_variable/notify_all + + (T... args) + + + T + native_handle + cpp/thread/condition_variable/native_handle + + (T... args) + + + T + wait_until + cpp/thread/condition_variable/wait_until + + (T... args) + + + T + condition_variable + cpp/thread/condition_variable/condition_variable + + (T... args) + + + T + ~condition_variable + cpp/thread/condition_variable/~condition_variable + + (T... args) + + + + std::ranlux48 + cpp/numeric/random/discard_block_engine + + T + discard + cpp/numeric/random/discard_block_engine/discard + + (T... args) + + + T + operator() + cpp/numeric/random/discard_block_engine/operator() + + (T... args) + + + T + ranlux48 + cpp/numeric/random/discard_block_engine/discard_block_engine + + (T... args) + + + T + base + cpp/numeric/random/discard_block_engine/base + + (T... args) + + + T + seed + cpp/numeric/random/discard_block_engine/seed + + (T... args) + + + T + max + cpp/numeric/random/discard_block_engine/max + + (T... args) + + + T + min + cpp/numeric/random/discard_block_engine/min + + (T... args) + + + + std::unexpected_handler + cpp/error/unexpected_handler + + + std::piecewise_constant_distribution + cpp/numeric/random/piecewise_constant_distribution + + T + densities + cpp/numeric/random/piecewise_constant_distribution/params + + (T... args) + + + T + max + cpp/numeric/random/piecewise_constant_distribution/max + + (T... args) + + + T + intervals + cpp/numeric/random/piecewise_constant_distribution/params + + (T... args) + + + T + reset + cpp/numeric/random/piecewise_constant_distribution/reset + + (T... args) + + + T + piecewise_constant_distribution + cpp/numeric/random/piecewise_constant_distribution/piecewise_constant_distribution + + (T... args) + + + T + operator() + cpp/numeric/random/piecewise_constant_distribution/operator() + + (T... args) + + + T + param + cpp/numeric/random/piecewise_constant_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/piecewise_constant_distribution/min + + (T... args) + + + + std::codecvt_base + cpp/locale/codecvt_base + + + std::set + cpp/container/set + + T + begin + cpp/container/set/begin + + (T... args) + + + T + erase + cpp/container/set/erase + + (T... args) + + + T + insert + cpp/container/set/insert + + (T... args) + + + T + ~set + cpp/container/set/~set + + (T... args) + + + T + rbegin + cpp/container/set/rbegin + + (T... args) + + + T + end + cpp/container/set/end + + (T... args) + + + T + emplace_hint + cpp/container/set/emplace_hint + + (T... args) + + + T + key_comp + cpp/container/set/key_comp + + (T... args) + + + T + count + cpp/container/set/count + + (T... args) + + + T + find + cpp/container/set/find + + (T... args) + + + T + crbegin + cpp/container/set/rbegin + + (T... args) + + + T + cbegin + cpp/container/set/begin + + (T... args) + + + T + upper_bound + cpp/container/set/upper_bound + + (T... args) + + + T + swap + cpp/container/set/swap + + (T... args) + + + T + crend + cpp/container/set/rend + + (T... args) + + + T + size + cpp/container/set/size + + (T... args) + + + T + set + cpp/container/set/set + + (T... args) + + + T + operator= + cpp/container/set/operator= + + (T... args) + + + T + value_comp + cpp/container/set/value_comp + + (T... args) + + + T + empty + cpp/container/set/empty + + (T... args) + + + T + lower_bound + cpp/container/set/lower_bound + + (T... args) + + + T + get_allocator + cpp/container/set/get_allocator + + (T... args) + + + T + max_size + cpp/container/set/max_size + + (T... args) + + + T + rend + cpp/container/set/rend + + (T... args) + + + T + cend + cpp/container/set/end + + (T... args) + + + T + clear + cpp/container/set/clear + + (T... args) + + + T + equal_range + cpp/container/set/equal_range + + (T... args) + + + T + emplace + cpp/container/set/emplace + + (T... args) + + + + std::forward_iterator_tag + cpp/iterator/iterator_tags + + + std::codecvt_byname + cpp/locale/codecvt_byname + std::codecvt_byname::extern_type + + T + out + cpp/locale/codecvt/out + + (T... args) + + + T + do_length + cpp/locale/codecvt/length + + (T... args) + + + T + do_unshift + cpp/locale/codecvt/unshift + + (T... args) + + + T + do_encoding + cpp/locale/codecvt/encoding + + (T... args) + + + T + do_in + cpp/locale/codecvt/in + + (T... args) + + + T + unshift + cpp/locale/codecvt/unshift + + (T... args) + + + T + max_length + cpp/locale/codecvt/max_length + + (T... args) + + std::codecvt_byname::state_type + + T + encoding + cpp/locale/codecvt/encoding + + (T... args) + + + T + always_noconv + cpp/locale/codecvt/always_noconv + + (T... args) + + + T + do_out + cpp/locale/codecvt/out + + (T... args) + + + T + codecvt_byname + cpp/locale/codecvt_byname + + (T... args) + + + T + do_max_length + cpp/locale/codecvt/max_length + + (T... args) + + + T + do_always_noconv + cpp/locale/codecvt/always_noconv + + (T... args) + + + T + in + cpp/locale/codecvt/in + + (T... args) + + std::codecvt_byname::intern_type + + T + length + cpp/locale/codecvt/length + + (T... args) + + + T + ~codecvt_byname + cpp/locale/codecvt_byname + + (T... args) + + + + std::codecvt_byname::extern_type + cpp/locale/codecvt + + + std::codecvt_byname::state_type + cpp/locale/codecvt + + + std::codecvt_byname::intern_type + cpp/locale/codecvt + + + std::pointer_safety + cpp/memory/gc/pointer_safety + + + std::uint_least64_t + cpp/types/integer + + + std::placeholders + cpp/utility/functional/placeholders + + + std::nothrow_t + cpp/memory/new/nothrow_t + + + std::is_nothrow_copy_assignable + cpp/types/is_copy_assignable + + + std::is_same + cpp/types/is_same + + + std::unique_lock + cpp/thread/unique_lock + + T + mutex + cpp/thread/unique_lock/mutex + + (T... args) + + + T + swap + cpp/thread/unique_lock/swap + + (T... args) + + + T + owns_lock + cpp/thread/unique_lock/owns_lock + + (T... args) + + + T + try_lock_for + cpp/thread/unique_lock/try_lock_for + + (T... args) + + + T + release + cpp/thread/unique_lock/release + + (T... args) + + + T + lock + cpp/thread/unique_lock/lock + + (T... args) + + + T + operator bool + cpp/thread/unique_lock/operator_bool + + (T... args) + + + T + ~unique_lock + cpp/thread/unique_lock/~unique_lock + + (T... args) + + + T + unlock + cpp/thread/unique_lock/unlock + + (T... args) + + + T + operator= + cpp/thread/unique_lock/operator= + + (T... args) + + + T + try_lock_until + cpp/thread/unique_lock/try_lock_until + + (T... args) + + + T + try_lock + cpp/thread/unique_lock/try_lock + + (T... args) + + + T + unique_lock + cpp/thread/unique_lock/unique_lock + + (T... args) + + + + std::basic_ostringstream + cpp/io/basic_ostringstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + str + cpp/io/basic_ostringstream/str + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + std::basic_ostringstream::event_callback + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::basic_ostringstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + operator= + cpp/io/basic_ostringstream/operator= + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + basic_ostringstream + cpp/io/basic_ostringstream/basic_ostringstream + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + std::basic_ostringstream::sentry + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::basic_ostringstream::event_callback + cpp/io/ios_base/event_callback + + + std::basic_ostringstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::basic_ostringstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_ostream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + + std::is_error_code_enum + cpp/error/error_code/is_error_code_enum + + + std::time_put_byname + cpp/locale/time_put_byname + + T + time_put_byname + cpp/locale/time_put_byname + + (T... args) + + std::time_put_byname::char_type + + T + do_put + cpp/locale/time_put/put + + (T... args) + + + T + put + cpp/locale/time_put/put + + (T... args) + + + T + ~time_put_byname + cpp/locale/time_put_byname + + (T... args) + + std::time_put_byname::iter_type + + + std::time_put_byname::char_type + cpp/locale/time_put + + + std::time_put_byname::iter_type + cpp/locale/time_put + + + std::time_get + cpp/locale/time_get + + T + do_date_order + cpp/locale/time_get/date_order + + (T... args) + + + T + do_get + cpp/locale/time_get/get + + (T... args) + + + T + do_get_monthname + cpp/locale/time_get/get_monthname + + (T... args) + + + T + get_weekday + cpp/locale/time_get/get_weekday + + (T... args) + + + T + do_get_time + cpp/locale/time_get/get_time + + (T... args) + + + T + ~time_get + cpp/locale/time_get/~time_get + + (T... args) + + + T + do_get_year + cpp/locale/time_get/get_year + + (T... args) + + std::time_get::iter_type + + T + get_monthname + cpp/locale/time_get/get_monthname + + (T... args) + + + T + get_time + cpp/locale/time_get/get_time + + (T... args) + + + T + time_get + cpp/locale/time_get/time_get + + (T... args) + + + T + do_get_date + cpp/locale/time_get/get_date + + (T... args) + + + T + get_date + cpp/locale/time_get/get_date + + (T... args) + + std::time_get::char_type + + T + date_order + cpp/locale/time_get/date_order + + (T... args) + + + T + get_year + cpp/locale/time_get/get_year + + (T... args) + + + T + get + cpp/locale/time_get/get + + (T... args) + + + T + do_get_weekday + cpp/locale/time_get/get_weekday + + (T... args) + + + + std::time_get::iter_type + cpp/locale/time_get + + + std::time_get::char_type + cpp/locale/time_get + + + std::regex + cpp/regex/basic_regex + + T + operator= + cpp/regex/basic_regex/operator= + + (T... args) + + + T + swap + cpp/regex/basic_regex/swap + + (T... args) + + + T + imbue + cpp/regex/basic_regex/imbue + + (T... args) + + + T + assign + cpp/regex/basic_regex/assign + + (T... args) + + + T + regex + cpp/regex/basic_regex/basic_regex + + (T... args) + + + T + mark_count + cpp/regex/basic_regex/mark_count + + (T... args) + + + T + getloc + cpp/regex/basic_regex/getloc + + (T... args) + + + T + flags + cpp/regex/basic_regex/flags + + (T... args) + + + T + ~regex + cpp/regex/basic_regex/~basic_regex + + (T... args) + + + + std::cin + cpp/io/basic_istream + + + std::unordered_map + cpp/container/unordered_map + + T + max_bucket_count + cpp/container/unordered_map/max_bucket_count + + (T... args) + + + T + cbegin + cpp/container/unordered_map/begin + + (T... args) + + + T + erase + cpp/container/unordered_map/erase + + (T... args) + + + T + insert + cpp/container/unordered_map/insert + + (T... args) + + + T + bucket_count + cpp/container/unordered_map/bucket_count + + (T... args) + + + T + max_load_factor + cpp/container/unordered_map/max_load_factor + + (T... args) + + + T + end + cpp/container/unordered_map/end + + (T... args) + + + T + emplace_hint + cpp/container/unordered_map/emplace_hint + + (T... args) + + + T + end(int) + cpp/container/unordered_map/end2 + + (T... args) + + + T + load_factor + cpp/container/unordered_map/load_factor + + (T... args) + + + T + get_allocator + cpp/container/unordered_map/get_allocator + + (T... args) + + + T + key_eq + cpp/container/unordered_map/key_eq + + (T... args) + + + T + ~unordered_map + cpp/container/unordered_map/~unordered_map + + (T... args) + + + T + hash_function + cpp/container/unordered_map/hash_function + + (T... args) + + + T + find + cpp/container/unordered_map/find + + (T... args) + + + T + at + cpp/container/unordered_map/at + + (T... args) + + + T + cbegin(int) + cpp/container/unordered_map/begin2 + + (T... args) + + + T + swap + cpp/container/unordered_map/swap + + (T... args) + + + T + begin(int) + cpp/container/unordered_map/begin2 + + (T... args) + + + T + unordered_map + cpp/container/unordered_map/unordered_map + + (T... args) + + + T + size + cpp/container/unordered_map/size + + (T... args) + + + T + operator= + cpp/container/unordered_map/operator= + + (T... args) + + + T + cend(int) + cpp/container/unordered_map/end2 + + (T... args) + + + T + reserve + cpp/container/unordered_map/reserve + + (T... args) + + + T + rehash + cpp/container/unordered_map/rehash + + (T... args) + + + T + bucket + cpp/container/unordered_map/bucket + + (T... args) + + + T + empty + cpp/container/unordered_map/empty + + (T... args) + + + T + cend + cpp/container/unordered_map/end + + (T... args) + + + T + max_size + cpp/container/unordered_map/max_size + + (T... args) + + + T + count + cpp/container/unordered_map/count + + (T... args) + + + T + clear + cpp/container/unordered_map/clear + + (T... args) + + + T + equal_range + cpp/container/unordered_map/equal_range + + (T... args) + + + T + emplace + cpp/container/unordered_map/emplace + + (T... args) + + + T + operator[] + cpp/container/unordered_map/operator_at + + (T... args) + + + T + begin + cpp/container/unordered_map/begin + + (T... args) + + + T + bucket_size + cpp/container/unordered_map/bucket_size + + (T... args) + + + + std::initializer_list + cpp/utility/initializer_list + + T + end + cpp/utility/initializer_list/end + + (T... args) + + + T + size + cpp/utility/initializer_list/size + + (T... args) + + + T + initializer_list + cpp/utility/initializer_list/initializer_list + + (T... args) + + + T + begin + cpp/utility/initializer_list/begin + + (T... args) + + + + std::is_const + cpp/types/is_const + + + std::basic_regex + cpp/regex/basic_regex + + T + basic_regex + cpp/regex/basic_regex/basic_regex + + (T... args) + + + T + operator= + cpp/regex/basic_regex/operator= + + (T... args) + + + T + swap + cpp/regex/basic_regex/swap + + (T... args) + + + T + assign + cpp/regex/basic_regex/assign + + (T... args) + + + T + ~basic_regex + cpp/regex/basic_regex/~basic_regex + + (T... args) + + + T + getloc + cpp/regex/basic_regex/getloc + + (T... args) + + + T + mark_count + cpp/regex/basic_regex/mark_count + + (T... args) + + + T + imbue + cpp/regex/basic_regex/imbue + + (T... args) + + + T + flags + cpp/regex/basic_regex/flags + + (T... args) + + + + std::poisson_distribution + cpp/numeric/random/poisson_distribution + + T + poisson_distribution + cpp/numeric/random/poisson_distribution/poisson_distribution + + (T... args) + + + T + mean + cpp/numeric/random/poisson_distribution/mean + + (T... args) + + + T + max + cpp/numeric/random/poisson_distribution/max + + (T... args) + + + T + param + cpp/numeric/random/poisson_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/poisson_distribution/min + + (T... args) + + + T + reset + cpp/numeric/random/poisson_distribution/reset + + (T... args) + + + + std::bad_typeid + cpp/types/bad_typeid + + T + bad_typeid + cpp/types/bad_typeid/bad_typeid + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::less_equal + cpp/utility/functional/less_equal + + T + operator() + cpp/utility/functional/less_equal + + (T... args) + + + + std::sig_atomic_t + cpp/utility/program/sig_atomic_t + + + std::make_unsigned + cpp/types/make_unsigned + + + std::basic_filebuf + cpp/io/basic_filebuf + + T + eback + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + setp + cpp/io/basic_streambuf/setp + + (T... args) + + + T + pbackfail + cpp/io/basic_streambuf/pbackfail + + (T... args) + + + T + seekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + pbase + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + egptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + basic_filebuf + cpp/io/basic_filebuf/basic_filebuf + + (T... args) + + + T + underflow + cpp/io/basic_streambuf/underflow + + (T... args) + + + T + setbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + gbump + cpp/io/basic_streambuf/gbump + + (T... args) + + + T + xsgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + is_open + cpp/io/basic_filebuf/is_open + + (T... args) + + + T + sputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + pptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + seekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + pubsync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + pubseekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + setg + cpp/io/basic_streambuf/setg + + (T... args) + + + T + pbump + cpp/io/basic_streambuf/pbump + + (T... args) + + + T + pubseekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + ~basic_filebuf + cpp/io/basic_filebuf/~basic_filebuf + + (T... args) + + + T + sputbackc + cpp/io/basic_streambuf/sputbackc + + (T... args) + + + T + in_avail + cpp/io/basic_streambuf/in_avail + + (T... args) + + + T + getloc + cpp/io/basic_streambuf/getloc + + (T... args) + + + T + sungetc + cpp/io/basic_streambuf/sungetc + + (T... args) + + + T + epptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + close + cpp/io/basic_filebuf/close + + (T... args) + + + T + sync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + xsputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + pubimbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + showmanyc + cpp/io/basic_streambuf/showmanyc + + (T... args) + + + T + open + cpp/io/basic_filebuf/open + + (T... args) + + + T + sgetc + cpp/io/basic_streambuf/sgetc + + (T... args) + + + T + swap + cpp/io/basic_streambuf/swap + + (T... args) + + + T + sputc + cpp/io/basic_streambuf/sputc + + (T... args) + + + T + overflow + cpp/io/basic_streambuf/overflow + + (T... args) + + + T + uflow + cpp/io/basic_streambuf/uflow + + (T... args) + + + T + sgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + sbumpc + cpp/io/basic_streambuf/sbumpc + + (T... args) + + + T + operator= + cpp/io/basic_filebuf/operator= + + (T... args) + + + T + pubsetbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + imbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + snextc + cpp/io/basic_streambuf/snextc + + (T... args) + + + T + gptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + + std::logical_or + cpp/utility/functional/logical_or + + T + operator() + cpp/utility/functional/logical_or + + (T... args) + + + + std::wstringbuf + cpp/io/basic_stringbuf + + T + pptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + epptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + eback + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + setp + cpp/io/basic_streambuf/setp + + (T... args) + + + T + sputbackc + cpp/io/basic_streambuf/sputbackc + + (T... args) + + + T + sgetc + cpp/io/basic_streambuf/sgetc + + (T... args) + + + T + sungetc + cpp/io/basic_streambuf/sungetc + + (T... args) + + + T + pubseekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + seekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + str + cpp/io/basic_stringbuf/str + + (T... args) + + + T + sync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + xsputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + pbase + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + pubimbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + showmanyc + cpp/io/basic_streambuf/showmanyc + + (T... args) + + + T + egptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + seekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + underflow + cpp/io/basic_streambuf/underflow + + (T... args) + + + T + setbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + gbump + cpp/io/basic_streambuf/gbump + + (T... args) + + + T + in_avail + cpp/io/basic_streambuf/in_avail + + (T... args) + + + T + swap + cpp/io/basic_streambuf/swap + + (T... args) + + + T + pbackfail + cpp/io/basic_streambuf/pbackfail + + (T... args) + + + T + sputc + cpp/io/basic_streambuf/sputc + + (T... args) + + + T + xsgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + uflow + cpp/io/basic_streambuf/uflow + + (T... args) + + + T + gptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + sputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + sgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + sbumpc + cpp/io/basic_streambuf/sbumpc + + (T... args) + + + T + overflow + cpp/io/basic_streambuf/overflow + + (T... args) + + + T + operator= + cpp/io/basic_stringbuf/operator= + + (T... args) + + + T + pbump + cpp/io/basic_streambuf/pbump + + (T... args) + + + T + pubsetbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + pubsync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + imbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + setg + cpp/io/basic_streambuf/setg + + (T... args) + + + T + snextc + cpp/io/basic_streambuf/snextc + + (T... args) + + + T + getloc + cpp/io/basic_streambuf/getloc + + (T... args) + + + T + pubseekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + wstringbuf + cpp/io/basic_stringbuf/basic_stringbuf + + (T... args) + + + + std::kilo + cpp/numeric/ratio/ratio + + + std::bernoulli_distribution + cpp/numeric/random/bernoulli_distribution + + T + bernoulli_distribution + cpp/numeric/random/bernoulli_distribution/bernoulli_distribution + + (T... args) + + + T + p + cpp/numeric/random/bernoulli_distribution/p + + (T... args) + + + T + reset + cpp/numeric/random/bernoulli_distribution/reset + + (T... args) + + + T + max + cpp/numeric/random/bernoulli_distribution/max + + (T... args) + + + T + param + cpp/numeric/random/bernoulli_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/bernoulli_distribution/min + + (T... args) + + + + std::int16_t + cpp/types/integer + + + std::basic_ios + cpp/io/basic_ios + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + imbue + cpp/io/ios_base/imbue + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + std::basic_ios::failure + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + basic_ios + cpp/io/basic_ios/basic_ios + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + ~basic_ios + cpp/io/basic_ios/~basic_ios + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + std::basic_ios::event_callback + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::basic_ios::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::basic_ios::event_callback + cpp/io/ios_base/event_callback + + + std::int32_t + cpp/types/integer + + + std::is_rvalue_reference + cpp/types/is_rvalue_reference + + + std::integral_constant + cpp/types/integral_constant + + + std::wsmatch + cpp/regex/match_results + + T + cbegin + cpp/regex/match_results/begin + + (T... args) + + + T + format + cpp/regex/match_results/format + + (T... args) + + + T + wsmatch + cpp/regex/match_results/match_results + + (T... args) + + + T + size + cpp/regex/match_results/size + + (T... args) + + + T + swap + cpp/regex/match_results/swap + + (T... args) + + + T + position + cpp/regex/match_results/position + + (T... args) + + + T + prefix + cpp/regex/match_results/prefix + + (T... args) + + + T + str + cpp/regex/match_results/str + + (T... args) + + + T + ~wsmatch + cpp/regex/match_results/~match_results + + (T... args) + + + T + empty + cpp/regex/match_results/empty + + (T... args) + + + T + suffix + cpp/regex/match_results/suffix + + (T... args) + + + T + get_allocator + cpp/regex/match_results/get_allocator + + (T... args) + + + T + end + cpp/regex/match_results/end + + (T... args) + + + T + max_size + cpp/regex/match_results/max_size + + (T... args) + + + T + ready + cpp/regex/match_results/ready + + (T... args) + + + T + cend + cpp/regex/match_results/end + + (T... args) + + + T + operator[] + cpp/regex/match_results/operator_at + + (T... args) + + + T + length + cpp/regex/match_results/length + + (T... args) + + + T + begin + cpp/regex/match_results/begin + + (T... args) + + + + std::cerr + cpp/io/basic_ostream + + + std::codecvt_utf8 + cpp/locale/codecvt_utf8 + std::codecvt_utf8::extern_type + + T + out + cpp/locale/codecvt/out + + (T... args) + + + T + do_length + cpp/locale/codecvt/length + + (T... args) + + + T + do_unshift + cpp/locale/codecvt/unshift + + (T... args) + + + T + do_encoding + cpp/locale/codecvt/encoding + + (T... args) + + + T + do_in + cpp/locale/codecvt/in + + (T... args) + + + T + unshift + cpp/locale/codecvt/unshift + + (T... args) + + + T + max_length + cpp/locale/codecvt/max_length + + (T... args) + + std::codecvt_utf8::state_type + + T + encoding + cpp/locale/codecvt/encoding + + (T... args) + + + T + always_noconv + cpp/locale/codecvt/always_noconv + + (T... args) + + + T + do_out + cpp/locale/codecvt/out + + (T... args) + + + T + do_max_length + cpp/locale/codecvt/max_length + + (T... args) + + + T + do_always_noconv + cpp/locale/codecvt/always_noconv + + (T... args) + + + T + in + cpp/locale/codecvt/in + + (T... args) + + std::codecvt_utf8::intern_type + + T + length + cpp/locale/codecvt/length + + (T... args) + + + + std::codecvt_utf8::extern_type + cpp/locale/codecvt + + + std::codecvt_utf8::state_type + cpp/locale/codecvt + + + std::codecvt_utf8::intern_type + cpp/locale/codecvt + + + std::ratio_add + cpp/numeric/ratio/ratio_add + + + std::is_trivially_move_constructible + cpp/types/is_move_constructible + + + std::wcsub_match + cpp/regex/sub_match + + T + operator string_type + cpp/regex/sub_match/str + + (T... args) + + + T + wcsub_match + cpp/regex/sub_match/sub_match + + (T... args) + + + T + str + cpp/regex/sub_match/str + + (T... args) + + + T + length + cpp/regex/sub_match/length + + (T... args) + + + T + compare + cpp/regex/sub_match/compare + + (T... args) + + + + std::is_member_pointer + cpp/types/is_member_pointer + + + std::wstreampos + cpp/io/fpos + + T + state + cpp/io/fpos/state + + (T... args) + + + + std::uint_least16_t + cpp/types/integer + + + std::tuple + cpp/utility/tuple + + T + operator= + cpp/utility/tuple/operator= + + (T... args) + + + T + swap + cpp/utility/tuple/swap + + (T... args) + + + T + tuple + cpp/utility/tuple/tuple + + (T... args) + + + + std::make_signed + cpp/types/make_signed + + + std::logic_error + cpp/error/logic_error + + T + logic_error + cpp/error/logic_error + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::sregex_iterator + cpp/regex/regex_iterator + + T + operator!= + cpp/regex/regex_iterator/operator_cmp + + (T... args) + + + T + operator= + cpp/regex/regex_iterator/operator= + + (T... args) + + + T + operator== + cpp/regex/regex_iterator/operator_cmp + + (T... args) + + + T + operator-> + cpp/regex/regex_iterator/operator* + + (T... args) + + + T + operator++ + cpp/regex/regex_iterator/operator_arith + + (T... args) + + + T + sregex_iterator + cpp/regex/regex_iterator/regex_iterator + + (T... args) + + + T + operator* + cpp/regex/regex_iterator/operator* + + (T... args) + + + T + operator++(int) + cpp/regex/regex_iterator/operator_arith + + (T... args) + + + + std::int_least64_t + cpp/types/integer + + + std::binary_negate + cpp/utility/functional/binary_negate + + T + operator() + cpp/utility/functional/binary_negate + + (T... args) + + + T + binary_negate + cpp/utility/functional/binary_negate + + (T... args) + + + + std::discard_block_engine + cpp/numeric/random/discard_block_engine + + T + discard + cpp/numeric/random/discard_block_engine/discard + + (T... args) + + + T + max + cpp/numeric/random/discard_block_engine/max + + (T... args) + + + T + operator() + cpp/numeric/random/discard_block_engine/operator() + + (T... args) + + + T + base + cpp/numeric/random/discard_block_engine/base + + (T... args) + + + T + seed + cpp/numeric/random/discard_block_engine/seed + + (T... args) + + + T + discard_block_engine + cpp/numeric/random/discard_block_engine/discard_block_engine + + (T... args) + + + T + min + cpp/numeric/random/discard_block_engine/min + + (T... args) + + + + std::is_trivially_assignable + cpp/types/is_assignable + + + std::add_cv + cpp/types/add_cv + + + std::pico + cpp/numeric/ratio/ratio + + + std::iterator_traits + cpp/iterator/iterator_traits + + + std::is_trivially_default_constructible + cpp/types/is_default_constructible + + + std::shared_ptr + cpp/memory/shared_ptr + + T + shared_ptr + cpp/memory/shared_ptr/shared_ptr + + (T... args) + + + T + ~shared_ptr + cpp/memory/shared_ptr/~shared_ptr + + (T... args) + + + T + swap + cpp/memory/shared_ptr/swap + + (T... args) + + + T + owner_before + cpp/memory/shared_ptr/owner_before + + (T... args) + + + T + reset + cpp/memory/shared_ptr/reset + + (T... args) + + + T + operator-> + cpp/memory/shared_ptr/operator* + + (T... args) + + + T + operator= + cpp/memory/shared_ptr/operator= + + (T... args) + + + T + unique + cpp/memory/shared_ptr/unique + + (T... args) + + + T + operator* + cpp/memory/shared_ptr/operator* + + (T... args) + + + T + operator bool + cpp/memory/shared_ptr/operator_bool + + (T... args) + + + T + get + cpp/memory/shared_ptr/get + + (T... args) + + + + std::bad_alloc + cpp/memory/new/bad_alloc + + T + operator= + cpp/memory/new/bad_alloc + + (T... args) + + + T + bad_alloc + cpp/memory/new/bad_alloc + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::ostringstream + cpp/io/basic_ostringstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + str + cpp/io/basic_ostringstream/str + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + std::ostringstream::event_callback + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + ostringstream + cpp/io/basic_ostringstream/basic_ostringstream + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::ostringstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + operator= + cpp/io/basic_ostringstream/operator= + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + std::ostringstream::sentry + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::ostringstream::event_callback + cpp/io/ios_base/event_callback + + + std::ostringstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::ostringstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_ostream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + + std::basic_fstream + cpp/io/basic_fstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + basic_fstream + cpp/io/basic_fstream/basic_fstream + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + open + cpp/io/basic_fstream/open + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + std::basic_fstream::sentry + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + std::basic_fstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + close + cpp/io/basic_fstream/close + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::basic_fstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + is_open + cpp/io/basic_fstream/is_open + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + operator= + cpp/io/basic_fstream/operator= + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::basic_fstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::basic_fstream::event_callback + cpp/io/ios_base/event_callback + + + std::basic_fstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::stringbuf + cpp/io/basic_stringbuf + + T + pptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + epptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + eback + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + setp + cpp/io/basic_streambuf/setp + + (T... args) + + + T + sputbackc + cpp/io/basic_streambuf/sputbackc + + (T... args) + + + T + sgetc + cpp/io/basic_streambuf/sgetc + + (T... args) + + + T + stringbuf + cpp/io/basic_stringbuf/basic_stringbuf + + (T... args) + + + T + sungetc + cpp/io/basic_streambuf/sungetc + + (T... args) + + + T + pubseekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + seekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + str + cpp/io/basic_stringbuf/str + + (T... args) + + + T + sync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + xsputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + pbase + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + pubimbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + showmanyc + cpp/io/basic_streambuf/showmanyc + + (T... args) + + + T + egptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + seekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + underflow + cpp/io/basic_streambuf/underflow + + (T... args) + + + T + setbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + gbump + cpp/io/basic_streambuf/gbump + + (T... args) + + + T + in_avail + cpp/io/basic_streambuf/in_avail + + (T... args) + + + T + swap + cpp/io/basic_streambuf/swap + + (T... args) + + + T + pbackfail + cpp/io/basic_streambuf/pbackfail + + (T... args) + + + T + sputc + cpp/io/basic_streambuf/sputc + + (T... args) + + + T + xsgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + uflow + cpp/io/basic_streambuf/uflow + + (T... args) + + + T + gptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + sputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + sgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + sbumpc + cpp/io/basic_streambuf/sbumpc + + (T... args) + + + T + overflow + cpp/io/basic_streambuf/overflow + + (T... args) + + + T + operator= + cpp/io/basic_stringbuf/operator= + + (T... args) + + + T + pbump + cpp/io/basic_streambuf/pbump + + (T... args) + + + T + pubsetbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + pubsync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + imbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + setg + cpp/io/basic_streambuf/setg + + (T... args) + + + T + snextc + cpp/io/basic_streambuf/snextc + + (T... args) + + + T + getloc + cpp/io/basic_streambuf/getloc + + (T... args) + + + T + pubseekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + + std::exponential_distribution + cpp/numeric/random/exponential_distribution + + T + exponential_distribution + cpp/numeric/random/exponential_distribution/exponential_distribution + + (T... args) + + + T + min + cpp/numeric/random/exponential_distribution/min + + (T... args) + + + T + max + cpp/numeric/random/exponential_distribution/max + + (T... args) + + + T + operator() + cpp/numeric/random/exponential_distribution/operator() + + (T... args) + + + T + param + cpp/numeric/random/exponential_distribution/param + + (T... args) + + + T + reset + cpp/numeric/random/exponential_distribution/reset + + (T... args) + + + T + lambda + cpp/numeric/random/exponential_distribution/lambda + + (T... args) + + + + std::uint32_t + cpp/types/integer + + + std::wcregex_iterator + cpp/regex/regex_iterator + + T + operator!= + cpp/regex/regex_iterator/operator_cmp + + (T... args) + + + T + operator= + cpp/regex/regex_iterator/operator= + + (T... args) + + + T + operator== + cpp/regex/regex_iterator/operator_cmp + + (T... args) + + + T + operator-> + cpp/regex/regex_iterator/operator* + + (T... args) + + + T + operator++ + cpp/regex/regex_iterator/operator_arith + + (T... args) + + + T + operator* + cpp/regex/regex_iterator/operator* + + (T... args) + + + T + wcregex_iterator + cpp/regex/regex_iterator/regex_iterator + + (T... args) + + + T + operator++(int) + cpp/regex/regex_iterator/operator_arith + + (T... args) + + + + std::bad_function_call + cpp/utility/functional/bad_function_call + + T + bad_function_call + cpp/utility/functional/bad_function_call + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::false_type + cpp/types/integral_constant + + + std::wregex + cpp/regex/basic_regex + + T + wregex + cpp/regex/basic_regex/basic_regex + + (T... args) + + + T + swap + cpp/regex/basic_regex/swap + + (T... args) + + + T + imbue + cpp/regex/basic_regex/imbue + + (T... args) + + + T + assign + cpp/regex/basic_regex/assign + + (T... args) + + + T + ~wregex + cpp/regex/basic_regex/~basic_regex + + (T... args) + + + T + operator= + cpp/regex/basic_regex/operator= + + (T... args) + + + T + mark_count + cpp/regex/basic_regex/mark_count + + (T... args) + + + T + getloc + cpp/regex/basic_regex/getloc + + (T... args) + + + T + flags + cpp/regex/basic_regex/flags + + (T... args) + + + + std::uint_least8_t + cpp/types/integer + + + std::uniform_real_distribution + cpp/numeric/random/uniform_real_distribution + + T + uniform_real_distribution + cpp/numeric/random/uniform_real_distribution/uniform_real_distribution + + (T... args) + + + T + reset + cpp/numeric/random/uniform_real_distribution/reset + + (T... args) + + + T + a + cpp/numeric/random/uniform_real_distribution/params + + (T... args) + + + T + max + cpp/numeric/random/uniform_real_distribution/max + + (T... args) + + + T + param + cpp/numeric/random/uniform_real_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/uniform_real_distribution/min + + (T... args) + + + T + b + cpp/numeric/random/uniform_real_distribution/params + + (T... args) + + + + std::smatch + cpp/regex/match_results + + T + smatch + cpp/regex/match_results/match_results + + (T... args) + + + T + cbegin + cpp/regex/match_results/begin + + (T... args) + + + T + format + cpp/regex/match_results/format + + (T... args) + + + T + size + cpp/regex/match_results/size + + (T... args) + + + T + swap + cpp/regex/match_results/swap + + (T... args) + + + T + position + cpp/regex/match_results/position + + (T... args) + + + T + ~smatch + cpp/regex/match_results/~match_results + + (T... args) + + + T + prefix + cpp/regex/match_results/prefix + + (T... args) + + + T + str + cpp/regex/match_results/str + + (T... args) + + + T + empty + cpp/regex/match_results/empty + + (T... args) + + + T + suffix + cpp/regex/match_results/suffix + + (T... args) + + + T + get_allocator + cpp/regex/match_results/get_allocator + + (T... args) + + + T + end + cpp/regex/match_results/end + + (T... args) + + + T + max_size + cpp/regex/match_results/max_size + + (T... args) + + + T + ready + cpp/regex/match_results/ready + + (T... args) + + + T + cend + cpp/regex/match_results/end + + (T... args) + + + T + operator[] + cpp/regex/match_results/operator_at + + (T... args) + + + T + length + cpp/regex/match_results/length + + (T... args) + + + T + begin + cpp/regex/match_results/begin + + (T... args) + + + + std::cregex_token_iterator + cpp/regex/regex_token_iterator + + T + operator!= + cpp/regex/regex_token_iterator/operator_cmp + + (T... args) + + + T + operator= + cpp/regex/regex_token_iterator/operator= + + (T... args) + + + T + operator== + cpp/regex/regex_token_iterator/operator_cmp + + (T... args) + + + T + operator-> + cpp/regex/regex_token_iterator/operator* + + (T... args) + + + T + cregex_token_iterator + cpp/regex/regex_token_iterator/regex_token_iterator + + (T... args) + + + T + operator++ + cpp/regex/regex_token_iterator/operator_arith + + (T... args) + + + T + operator* + cpp/regex/regex_token_iterator/operator* + + (T... args) + + + T + operator++(int) + cpp/regex/regex_token_iterator/operator_arith + + (T... args) + + + + std::range_error + cpp/error/range_error + + T + range_error + cpp/error/range_error + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::is_assignable + cpp/types/is_assignable + + + std::is_copy_assignable + cpp/types/is_copy_assignable + + + std::invalid_argument + cpp/error/invalid_argument + + T + invalid_argument + cpp/error/invalid_argument + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::is_unsigned + cpp/types/is_unsigned + + + std::jmp_buf + cpp/utility/program/jmp_buf + + + std::is_class + cpp/types/is_class + + + std::geometric_distribution + cpp/numeric/random/geometric_distribution + + T + p + cpp/numeric/random/geometric_distribution/p + + (T... args) + + + T + reset + cpp/numeric/random/geometric_distribution/reset + + (T... args) + + + T + max + cpp/numeric/random/geometric_distribution/max + + (T... args) + + + T + geometric_distribution + cpp/numeric/random/geometric_distribution/geometric_distribution + + (T... args) + + + T + param + cpp/numeric/random/geometric_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/geometric_distribution/min + + (T... args) + + + + std::uint_fast8_t + cpp/types/integer + + + std::mersenne_twister_engine + cpp/numeric/random/mersenne_twister_engine + + T + discard + cpp/numeric/random/mersenne_twister_engine/discard + + (T... args) + + + T + max + cpp/numeric/random/mersenne_twister_engine/max + + (T... args) + + + T + operator() + cpp/numeric/random/mersenne_twister_engine/operator() + + (T... args) + + + T + mersenne_twister_engine + cpp/numeric/random/mersenne_twister_engine/mersenne_twister_engine + + (T... args) + + + T + seed + cpp/numeric/random/mersenne_twister_engine/seed + + (T... args) + + + T + min + cpp/numeric/random/mersenne_twister_engine/min + + (T... args) + + + + std::is_arithmetic + cpp/types/is_arithmetic + + + std::negate + cpp/utility/functional/negate + + T + operator() + cpp/utility/functional/negate + + (T... args) + + + + std::try_to_lock_t + cpp/thread/lock_tag_t + + + std::wfilebuf + cpp/io/basic_filebuf + + T + eback + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + setp + cpp/io/basic_streambuf/setp + + (T... args) + + + T + pbackfail + cpp/io/basic_streambuf/pbackfail + + (T... args) + + + T + seekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + pbase + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + egptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + underflow + cpp/io/basic_streambuf/underflow + + (T... args) + + + T + setbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + gbump + cpp/io/basic_streambuf/gbump + + (T... args) + + + T + xsgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + is_open + cpp/io/basic_filebuf/is_open + + (T... args) + + + T + sputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + pptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + seekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + pubsync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + pubseekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + setg + cpp/io/basic_streambuf/setg + + (T... args) + + + T + pbump + cpp/io/basic_streambuf/pbump + + (T... args) + + + T + pubseekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + ~wfilebuf + cpp/io/basic_filebuf/~basic_filebuf + + (T... args) + + + T + sputbackc + cpp/io/basic_streambuf/sputbackc + + (T... args) + + + T + in_avail + cpp/io/basic_streambuf/in_avail + + (T... args) + + + T + getloc + cpp/io/basic_streambuf/getloc + + (T... args) + + + T + sungetc + cpp/io/basic_streambuf/sungetc + + (T... args) + + + T + wfilebuf + cpp/io/basic_filebuf/basic_filebuf + + (T... args) + + + T + epptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + close + cpp/io/basic_filebuf/close + + (T... args) + + + T + sync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + xsputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + pubimbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + showmanyc + cpp/io/basic_streambuf/showmanyc + + (T... args) + + + T + open + cpp/io/basic_filebuf/open + + (T... args) + + + T + sgetc + cpp/io/basic_streambuf/sgetc + + (T... args) + + + T + swap + cpp/io/basic_streambuf/swap + + (T... args) + + + T + sputc + cpp/io/basic_streambuf/sputc + + (T... args) + + + T + overflow + cpp/io/basic_streambuf/overflow + + (T... args) + + + T + uflow + cpp/io/basic_streambuf/uflow + + (T... args) + + + T + sgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + sbumpc + cpp/io/basic_streambuf/sbumpc + + (T... args) + + + T + operator= + cpp/io/basic_filebuf/operator= + + (T... args) + + + T + pubsetbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + imbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + snextc + cpp/io/basic_streambuf/snextc + + (T... args) + + + T + gptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + + std::is_compound + cpp/types/is_compound + + + std::iostream + cpp/io/basic_iostream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + ~iostream + cpp/io/basic_iostream/~basic_iostream + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + std::iostream::sentry + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + std::iostream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::iostream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + iostream + cpp/io/basic_iostream/basic_iostream + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::iostream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::iostream::event_callback + cpp/io/ios_base/event_callback + + + std::iostream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::is_object + cpp/types/is_object + + + std::recursive_mutex + cpp/thread/recursive_mutex + + T + unlock + cpp/thread/recursive_mutex/unlock + + (T... args) + + + T + native_handle + cpp/thread/recursive_mutex/native_handle + + (T... args) + + + T + recursive_mutex + cpp/thread/recursive_mutex/recursive_mutex + + (T... args) + + + T + lock + cpp/thread/recursive_mutex/lock + + (T... args) + + + T + try_lock + cpp/thread/recursive_mutex/try_lock + + (T... args) + + + + std::is_copy_constructible + cpp/types/is_copy_constructible + + + std::codecvt_utf8_utf16 + cpp/locale/codecvt_utf8_utf16 + std::codecvt_utf8_utf16::extern_type + + T + out + cpp/locale/codecvt/out + + (T... args) + + + T + do_length + cpp/locale/codecvt/length + + (T... args) + + + T + do_unshift + cpp/locale/codecvt/unshift + + (T... args) + + + T + do_encoding + cpp/locale/codecvt/encoding + + (T... args) + + + T + do_in + cpp/locale/codecvt/in + + (T... args) + + + T + unshift + cpp/locale/codecvt/unshift + + (T... args) + + + T + max_length + cpp/locale/codecvt/max_length + + (T... args) + + std::codecvt_utf8_utf16::state_type + + T + encoding + cpp/locale/codecvt/encoding + + (T... args) + + + T + always_noconv + cpp/locale/codecvt/always_noconv + + (T... args) + + + T + do_out + cpp/locale/codecvt/out + + (T... args) + + + T + do_max_length + cpp/locale/codecvt/max_length + + (T... args) + + + T + do_always_noconv + cpp/locale/codecvt/always_noconv + + (T... args) + + + T + in + cpp/locale/codecvt/in + + (T... args) + + std::codecvt_utf8_utf16::intern_type + + T + length + cpp/locale/codecvt/length + + (T... args) + + + + std::codecvt_utf8_utf16::extern_type + cpp/locale/codecvt + + + std::codecvt_utf8_utf16::state_type + cpp/locale/codecvt + + + std::codecvt_utf8_utf16::intern_type + cpp/locale/codecvt + + + std::not_equal_to + cpp/utility/functional/not_equal_to + + T + operator() + cpp/utility/functional/not_equal_to + + (T... args) + + + + std::is_destructible + cpp/types/is_destructible + + + std::int_fast32_t + cpp/types/integer + + + std::rank + cpp/types/rank + + + std::milli + cpp/numeric/ratio/ratio + + + std::deci + cpp/numeric/ratio/ratio + + + std::add_lvalue_reference + cpp/types/add_reference + + + std::is_bind_expression + cpp/utility/functional/is_bind_expression + + + std::ios_base + cpp/io/ios_base + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + std::ios_base::event_callback + std::ios_base::failure + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + imbue + cpp/io/ios_base/imbue + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + ios_base + cpp/io/ios_base/ios_base + + (T... args) + + + T + ~ios_base + cpp/io/ios_base/~ios_base + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + + std::ios_base::event_callback + cpp/io/ios_base/event_callback + + + std::ios_base::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::ratio_less + cpp/numeric/ratio/ratio_less + + + std::int64_t + cpp/types/integer + + + std::nullptr_t + cpp/types/nullptr_t + + + std::stack + cpp/container/stack + + T + operator= + cpp/container/stack/operator= + + (T... args) + + + T + swap + cpp/container/stack/swap + + (T... args) + + + T + size + cpp/container/stack/size + + (T... args) + + + T + empty + cpp/container/stack/empty + + (T... args) + + + T + pop + cpp/container/stack/pop + + (T... args) + + + T + emplace + cpp/container/stack/emplace + + (T... args) + + + T + ~stack + cpp/container/stack/~stack + + (T... args) + + + T + top + cpp/container/stack/top + + (T... args) + + + T + stack + cpp/container/stack/stack + + (T... args) + + + T + push + cpp/container/stack/push + + (T... args) + + + + std::uint_fast64_t + cpp/types/integer + + + std::is_reference + cpp/types/is_reference + + + std::ratio + cpp/numeric/ratio/ratio + + + std::shared_future + cpp/thread/shared_future + + T + ~shared_future + cpp/thread/shared_future/~shared_future + + (T... args) + + + T + operator= + cpp/thread/shared_future/operator= + + (T... args) + + + T + wait + cpp/thread/shared_future/wait + + (T... args) + + + T + wait_until + cpp/thread/shared_future/wait_until + + (T... args) + + + T + wait_for + cpp/thread/shared_future/wait_for + + (T... args) + + + T + shared_future + cpp/thread/shared_future/shared_future + + (T... args) + + + T + valid + cpp/thread/shared_future/valid + + (T... args) + + + T + get + cpp/thread/shared_future/get + + (T... args) + + + + std::u16streampos + cpp/io/fpos + + T + state + cpp/io/fpos/state + + (T... args) + + + + std::wistream + cpp/io/basic_istream + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + std::wistream::event_callback + + T + wistream + cpp/io/basic_istream/basic_istream + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ~wistream + cpp/io/basic_istream/~basic_istream + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::wistream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + std::wistream::sentry + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::wistream::event_callback + cpp/io/ios_base/event_callback + + + std::wistream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::wistream::sentry + cpp/io/basic_istream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::aligned_storage + cpp/types/aligned_storage + + + std::wstreambuf + cpp/io/basic_streambuf + + T + pptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + epptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + eback + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + setp + cpp/io/basic_streambuf/setp + + (T... args) + + + T + sputbackc + cpp/io/basic_streambuf/sputbackc + + (T... args) + + + T + getloc + cpp/io/basic_streambuf/getloc + + (T... args) + + + T + seekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + pubseekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + sungetc + cpp/io/basic_streambuf/sungetc + + (T... args) + + + T + sync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + xsputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + pbase + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + sgetc + cpp/io/basic_streambuf/sgetc + + (T... args) + + + T + pubimbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + showmanyc + cpp/io/basic_streambuf/showmanyc + + (T... args) + + + T + egptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + seekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + underflow + cpp/io/basic_streambuf/underflow + + (T... args) + + + T + setbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + gbump + cpp/io/basic_streambuf/gbump + + (T... args) + + + T + in_avail + cpp/io/basic_streambuf/in_avail + + (T... args) + + + T + swap + cpp/io/basic_streambuf/swap + + (T... args) + + + T + pbackfail + cpp/io/basic_streambuf/pbackfail + + (T... args) + + + T + wstreambuf + cpp/io/basic_streambuf/basic_streambuf + + (T... args) + + + T + sputc + cpp/io/basic_streambuf/sputc + + (T... args) + + + T + xsgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + uflow + cpp/io/basic_streambuf/uflow + + (T... args) + + + T + overflow + cpp/io/basic_streambuf/overflow + + (T... args) + + + T + sputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + sgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + sbumpc + cpp/io/basic_streambuf/sbumpc + + (T... args) + + + T + ~wstreambuf + cpp/io/basic_streambuf/~basic_streambuf + + (T... args) + + + T + operator= + cpp/io/basic_streambuf/operator= + + (T... args) + + + T + pbump + cpp/io/basic_streambuf/pbump + + (T... args) + + + T + pubsetbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + pubsync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + imbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + setg + cpp/io/basic_streambuf/setg + + (T... args) + + + T + snextc + cpp/io/basic_streambuf/snextc + + (T... args) + + + T + gptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + pubseekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + + std::binary_function + cpp/utility/functional/binary_function + + + std::out_of_range + cpp/error/out_of_range + + T + out_of_range + cpp/error/out_of_range + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::independent_bits_engine + cpp/numeric/random/independent_bits_engine + + T + discard + cpp/numeric/random/independent_bits_engine/discard + + (T... args) + + + T + max + cpp/numeric/random/independent_bits_engine/max + + (T... args) + + + T + independent_bits_engine + cpp/numeric/random/independent_bits_engine/independent_bits_engine + + (T... args) + + + T + operator() + cpp/numeric/random/independent_bits_engine/operator() + + (T... args) + + + T + base + cpp/numeric/random/independent_bits_engine/base + + (T... args) + + + T + seed + cpp/numeric/random/independent_bits_engine/seed + + (T... args) + + + T + min + cpp/numeric/random/independent_bits_engine/min + + (T... args) + + + + std::stringstream + cpp/io/basic_stringstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + str + cpp/io/basic_stringstream/str + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + stringstream + cpp/io/basic_stringstream/basic_stringstream + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + std::stringstream::sentry + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + std::stringstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::stringstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + operator= + cpp/io/basic_stringstream/operator= + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::stringstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::stringstream::event_callback + cpp/io/ios_base/event_callback + + + std::stringstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::tera + cpp/numeric/ratio/ratio + + + std::recursive_timed_mutex + cpp/thread/recursive_timed_mutex + + T + unlock + cpp/thread/recursive_timed_mutex/unlock + + (T... args) + + + T + native_handle + cpp/thread/recursive_timed_mutex/native_handle + + (T... args) + + + T + try_lock_until + cpp/thread/recursive_timed_mutex/try_lock_until + + (T... args) + + + T + try_lock_for + cpp/thread/recursive_timed_mutex/try_lock_for + + (T... args) + + + T + recursive_timed_mutex + cpp/thread/recursive_timed_mutex/recursive_timed_mutex + + (T... args) + + + T + lock + cpp/thread/recursive_timed_mutex/lock + + (T... args) + + + T + try_lock + cpp/thread/recursive_timed_mutex/try_lock + + (T... args) + + + + std::nano + cpp/numeric/ratio/ratio + + + std::unordered_multimap + cpp/container/unordered_multimap + + T + ~unordered_multimap + cpp/container/unordered_multimap/~unordered_multimap + + (T... args) + + + T + max_bucket_count + cpp/container/unordered_multimap/max_bucket_count + + (T... args) + + + T + bucket_count + cpp/container/unordered_multimap/bucket_count + + (T... args) + + + T + cbegin + cpp/container/unordered_multimap/begin + + (T... args) + + + T + erase + cpp/container/unordered_multimap/erase + + (T... args) + + + T + insert + cpp/container/unordered_multimap/insert + + (T... args) + + + T + unordered_multimap + cpp/container/unordered_multimap/unordered_multimap + + (T... args) + + + T + max_load_factor + cpp/container/unordered_multimap/max_load_factor + + (T... args) + + + T + end + cpp/container/unordered_multimap/end + + (T... args) + + + T + emplace_hint + cpp/container/unordered_multimap/emplace_hint + + (T... args) + + + T + end(int) + cpp/container/unordered_multimap/end2 + + (T... args) + + + T + key_eq + cpp/container/unordered_multimap/key_eq + + (T... args) + + + T + hash_function + cpp/container/unordered_multimap/hash_function + + (T... args) + + + T + find + cpp/container/unordered_multimap/find + + (T... args) + + + T + begin + cpp/container/unordered_multimap/begin + + (T... args) + + + T + cbegin(int) + cpp/container/unordered_multimap/begin2 + + (T... args) + + + T + swap + cpp/container/unordered_multimap/swap + + (T... args) + + + T + begin(int) + cpp/container/unordered_multimap/begin2 + + (T... args) + + + T + load_factor + cpp/container/unordered_multimap/load_factor + + (T... args) + + + T + size + cpp/container/unordered_multimap/size + + (T... args) + + + T + operator= + cpp/container/unordered_multimap/operator= + + (T... args) + + + T + cend + cpp/container/unordered_multimap/end + + (T... args) + + + T + reserve + cpp/container/unordered_multimap/reserve + + (T... args) + + + T + rehash + cpp/container/unordered_multimap/rehash + + (T... args) + + + T + bucket + cpp/container/unordered_multimap/bucket + + (T... args) + + + T + empty + cpp/container/unordered_multimap/empty + + (T... args) + + + T + get_allocator + cpp/container/unordered_multimap/get_allocator + + (T... args) + + + T + max_size + cpp/container/unordered_multimap/max_size + + (T... args) + + + T + cend(int) + cpp/container/unordered_multimap/end2 + + (T... args) + + + T + count + cpp/container/unordered_multimap/count + + (T... args) + + + T + clear + cpp/container/unordered_multimap/clear + + (T... args) + + + T + equal_range + cpp/container/unordered_multimap/equal_range + + (T... args) + + + T + emplace + cpp/container/unordered_multimap/emplace + + (T... args) + + + T + bucket_size + cpp/container/unordered_multimap/bucket_size + + (T... args) + + + + std::normal_distribution + cpp/numeric/random/normal_distribution + + T + min + cpp/numeric/random/normal_distribution/min + + (T... args) + + + T + stddev + cpp/numeric/random/normal_distribution/params + + (T... args) + + + T + reset + cpp/numeric/random/normal_distribution/reset + + (T... args) + + + T + mean + cpp/numeric/random/normal_distribution/params + + (T... args) + + + T + max + cpp/numeric/random/normal_distribution/max + + (T... args) + + + T + operator() + cpp/numeric/random/normal_distribution/operator() + + (T... args) + + + T + param + cpp/numeric/random/normal_distribution/param + + (T... args) + + + T + normal_distribution + cpp/numeric/random/normal_distribution/normal_distribution + + (T... args) + + + + std::minstd_rand + cpp/numeric/random/linear_congruential_engine + + T + discard + cpp/numeric/random/linear_congruential_engine/discard + + (T... args) + + + T + minstd_rand + cpp/numeric/random/linear_congruential_engine/linear_congruential_engine + + (T... args) + + + T + max + cpp/numeric/random/linear_congruential_engine/max + + (T... args) + + + T + operator() + cpp/numeric/random/linear_congruential_engine/operator() + + (T... args) + + + T + seed + cpp/numeric/random/linear_congruential_engine/seed + + (T... args) + + + T + min + cpp/numeric/random/linear_congruential_engine/min + + (T... args) + + + + std::is_signed + cpp/types/is_signed + + + std::is_move_constructible + cpp/types/is_move_constructible + + + std::unique_ptr + cpp/memory/unique_ptr + + T + unique_ptr + cpp/memory/unique_ptr/unique_ptr + + (T... args) + + + T + operator= + cpp/memory/unique_ptr/operator= + + (T... args) + + + T + swap + cpp/memory/unique_ptr/swap + + (T... args) + + + T + operator* + cpp/memory/unique_ptr/operator* + + (T... args) + + + T + ~unique_ptr + cpp/memory/unique_ptr/~unique_ptr + + (T... args) + + + T + operator-> + cpp/memory/unique_ptr/operator* + + (T... args) + + + T + release + cpp/memory/unique_ptr/release + + (T... args) + + + T + get_deleter + cpp/memory/unique_ptr/get_deleter + + (T... args) + + + T + operator bool + cpp/memory/unique_ptr/operator_bool + + (T... args) + + + T + get + cpp/memory/unique_ptr/get + + (T... args) + + + T + reset + cpp/memory/unique_ptr/reset + + (T... args) + + + + std::is_nothrow_copy_constructible + cpp/types/is_copy_constructible + + + std::forward_list + cpp/container/forward_list + + T + pop_front + cpp/container/forward_list/pop_front + + (T... args) + + + T + unique + cpp/container/forward_list/unique + + (T... args) + + + T + sort + cpp/container/forward_list/sort + + (T... args) + + + T + cbegin + cpp/container/forward_list/begin + + (T... args) + + + T + splice_after + cpp/container/forward_list/splice_after + + (T... args) + + + T + reverse + cpp/container/forward_list/reverse + + (T... args) + + + T + remove_if + cpp/container/forward_list/remove + + (T... args) + + + T + end + cpp/container/forward_list/end + + (T... args) + + + T + remove + cpp/container/forward_list/remove + + (T... args) + + + T + push_front + cpp/container/forward_list/push_front + + (T... args) + + + T + emplace_after + cpp/container/forward_list/emplace_after + + (T... args) + + + T + get_allocator + cpp/container/forward_list/get_allocator + + (T... args) + + + T + front + cpp/container/forward_list/front + + (T... args) + + + T + begin + cpp/container/forward_list/begin + + (T... args) + + + T + resize + cpp/container/forward_list/resize + + (T... args) + + + T + emplace_front + cpp/container/forward_list/emplace_front + + (T... args) + + + T + swap + cpp/container/forward_list/swap + + (T... args) + + + T + erase_after + cpp/container/forward_list/erase_after + + (T... args) + + + T + assign + cpp/container/forward_list/assign + + (T... args) + + + T + forward_list + cpp/container/forward_list/forward_list + + (T... args) + + + T + ~forward_list + cpp/container/forward_list/~forward_list + + (T... args) + + + T + before_begin + cpp/container/forward_list/before_begin + + (T... args) + + + T + cbefore_begin + cpp/container/forward_list/before_begin + + (T... args) + + + T + merge + cpp/container/forward_list/merge + + (T... args) + + + T + operator= + cpp/container/forward_list/operator= + + (T... args) + + + T + insert_after + cpp/container/forward_list/insert_after + + (T... args) + + + T + empty + cpp/container/forward_list/empty + + (T... args) + + + T + max_size + cpp/container/forward_list/max_size + + (T... args) + + + T + cend + cpp/container/forward_list/end + + (T... args) + + + T + clear + cpp/container/forward_list/clear + + (T... args) + + + + std::errc + cpp/error/errc + + + std::lconv + cpp/locale/lconv + + + std::strstreambuf + cpp/io/strstreambuf + + T + pptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + epptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + eback + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + setp + cpp/io/basic_streambuf/setp + + (T... args) + + + T + sputbackc + cpp/io/basic_streambuf/sputbackc + + (T... args) + + + T + sgetc + cpp/io/basic_streambuf/sgetc + + (T... args) + + + T + sungetc + cpp/io/basic_streambuf/sungetc + + (T... args) + + + T + pubseekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + seekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + str + cpp/io/strstreambuf/str + + (T... args) + + + T + sync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + xsputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + pbase + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + pubimbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + showmanyc + cpp/io/basic_streambuf/showmanyc + + (T... args) + + + T + egptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + seekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + underflow + cpp/io/basic_streambuf/underflow + + (T... args) + + + T + setbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + pcount + cpp/io/strstreambuf/pcount + + (T... args) + + + T + gbump + cpp/io/basic_streambuf/gbump + + (T... args) + + + T + in_avail + cpp/io/basic_streambuf/in_avail + + (T... args) + + + T + swap + cpp/io/basic_streambuf/swap + + (T... args) + + + T + pbackfail + cpp/io/basic_streambuf/pbackfail + + (T... args) + + + T + sputc + cpp/io/basic_streambuf/sputc + + (T... args) + + + T + xsgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + uflow + cpp/io/basic_streambuf/uflow + + (T... args) + + + T + ~strstreambuf + cpp/io/strstreambuf/~strstreambuf + + (T... args) + + + T + gptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + sputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + sgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + sbumpc + cpp/io/basic_streambuf/sbumpc + + (T... args) + + + T + overflow + cpp/io/basic_streambuf/overflow + + (T... args) + + + T + freeze + cpp/io/strstreambuf/freeze + + (T... args) + + + T + pbump + cpp/io/basic_streambuf/pbump + + (T... args) + + + T + pubsetbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + pubsync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + strstreambuf + cpp/io/strstreambuf/strstreambuf + + (T... args) + + + T + imbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + setg + cpp/io/basic_streambuf/setg + + (T... args) + + + T + snextc + cpp/io/basic_streambuf/snextc + + (T... args) + + + T + getloc + cpp/io/basic_streambuf/getloc + + (T... args) + + + T + pubseekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + + std::locale + cpp/locale/locale + + T + name + cpp/locale/locale/name + + (T... args) + + + T + combine + cpp/locale/locale/combine + + (T... args) + + + T + operator() + cpp/locale/locale/operator() + + (T... args) + + + T + classic + cpp/locale/locale/classic + + (T... args) + + + T + global + cpp/locale/locale/global + + (T... args) + + + T + operator!= + cpp/locale/locale/operator_cmp + + (T... args) + + + T + operator= + cpp/locale/locale/operator= + + (T... args) + + std::locale::facet + + T + operator== + cpp/locale/locale/operator_cmp + + (T... args) + + + T + locale + cpp/locale/locale/locale + + (T... args) + + std::locale::id + + T + ~locale + cpp/locale/locale/~locale + + (T... args) + + + + std::locale::facet + cpp/locale/locale/facet + + T + facet + cpp/locale/locale/facet/facet + + (T... args) + + + + std::locale::id + cpp/locale/locale/id + + T + id + cpp/locale/locale/id/id + + (T... args) + + + + std::equal_to + cpp/utility/functional/equal_to + + T + operator() + cpp/utility/functional/equal_to + + (T... args) + + + + std::divides + cpp/utility/functional/divides + + T + operator() + cpp/utility/functional/divides + + (T... args) + + + + std::collate_byname + cpp/locale/collate_byname + + T + hash + cpp/locale/collate/hash + + (T... args) + + + T + do_hash + cpp/locale/collate/hash + + (T... args) + + std::collate_byname::char_type + + T + do_transform + cpp/locale/collate/transform + + (T... args) + + + T + transform + cpp/locale/collate/transform + + (T... args) + + + T + do_compare + cpp/locale/collate/compare + + (T... args) + + + T + ~collate_byname + cpp/locale/collate_byname + + (T... args) + + std::collate_byname::string_type + + T + collate_byname + cpp/locale/collate_byname + + (T... args) + + + T + compare + cpp/locale/collate/compare + + (T... args) + + + + std::collate_byname::char_type + cpp/locale/collate + + + std::collate_byname::string_type + cpp/locale/collate + + + std::domain_error + cpp/error/domain_error + + T + domain_error + cpp/error/domain_error + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::is_empty + cpp/types/is_empty + + + std::is_nothrow_default_constructible + cpp/types/is_default_constructible + + + std::ratio_equal + cpp/numeric/ratio/ratio_equal + + + std::ostream + cpp/io/basic_ostream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + std::ostream::event_callback + + T + ostream + cpp/io/basic_ostream/basic_ostream + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + ~ostream + cpp/io/basic_ostream/~basic_ostream + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::ostream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + std::ostream::sentry + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::ostream::event_callback + cpp/io/ios_base/event_callback + + + std::ostream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::ostream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_ostream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + + std::streamsize + cpp/io/streamsize + + + std::shared_lock + cpp/thread/shared_lock + + T + mutex + cpp/thread/shared_lock/mutex + + (T... args) + + + T + swap + cpp/thread/shared_lock/swap + + (T... args) + + + T + shared_lock + cpp/thread/shared_lock/shared_lock + + (T... args) + + + T + try_lock_for + cpp/thread/shared_lock/try_lock_for + + (T... args) + + + T + release + cpp/thread/shared_lock/release + + (T... args) + + + T + lock + cpp/thread/shared_lock/lock + + (T... args) + + + T + operator bool + cpp/thread/shared_lock/operator_bool + + (T... args) + + + T + unlock + cpp/thread/shared_lock/unlock + + (T... args) + + + T + operator= + cpp/thread/shared_lock/operator= + + (T... args) + + + T + ~shared_lock + cpp/thread/shared_lock/~shared_lock + + (T... args) + + + T + try_lock_until + cpp/thread/shared_lock/try_lock_until + + (T... args) + + + T + try_lock + cpp/thread/shared_lock/try_lock + + (T... args) + + + T + owns_lock + cpp/thread/shared_lock/owns_lock + + (T... args) + + + + std::uint8_t + cpp/types/integer + + + std::enable_shared_from_this + cpp/memory/enable_shared_from_this + + T + enable_shared_from_this + cpp/memory/enable_shared_from_this/enable_shared_from_this + + (T... args) + + + T + operator= + cpp/memory/enable_shared_from_this/operator= + + (T... args) + + + T + shared_from_this + cpp/memory/enable_shared_from_this/shared_from_this + + (T... args) + + + T + ~enable_shared_from_this + cpp/memory/enable_shared_from_this/~enable_shared_from_this + + (T... args) + + + + std::ptrdiff_t + cpp/types/ptrdiff_t + + + std::int_fast8_t + cpp/types/integer + + + std::aligned_union + cpp/types/aligned_union + + + std::future + cpp/thread/future + + T + operator= + cpp/thread/future/operator= + + (T... args) + + + T + wait + cpp/thread/future/wait + + (T... args) + + + T + wait_until + cpp/thread/future/wait_until + + (T... args) + + + T + wait_for + cpp/thread/future/wait_for + + (T... args) + + + T + ~future + cpp/thread/future/~future + + (T... args) + + + T + share + cpp/thread/future/share + + (T... args) + + + T + future + cpp/thread/future/future + + (T... args) + + + T + valid + cpp/thread/future/valid + + (T... args) + + + T + get + cpp/thread/future/get + + (T... args) + + + + std::wcmatch + cpp/regex/match_results + + T + wcmatch + cpp/regex/match_results/match_results + + (T... args) + + + T + cbegin + cpp/regex/match_results/begin + + (T... args) + + + T + format + cpp/regex/match_results/format + + (T... args) + + + T + size + cpp/regex/match_results/size + + (T... args) + + + T + swap + cpp/regex/match_results/swap + + (T... args) + + + T + position + cpp/regex/match_results/position + + (T... args) + + + T + prefix + cpp/regex/match_results/prefix + + (T... args) + + + T + str + cpp/regex/match_results/str + + (T... args) + + + T + empty + cpp/regex/match_results/empty + + (T... args) + + + T + suffix + cpp/regex/match_results/suffix + + (T... args) + + + T + get_allocator + cpp/regex/match_results/get_allocator + + (T... args) + + + T + end + cpp/regex/match_results/end + + (T... args) + + + T + max_size + cpp/regex/match_results/max_size + + (T... args) + + + T + ~wcmatch + cpp/regex/match_results/~match_results + + (T... args) + + + T + ready + cpp/regex/match_results/ready + + (T... args) + + + T + cend + cpp/regex/match_results/end + + (T... args) + + + T + operator[] + cpp/regex/match_results/operator_at + + (T... args) + + + T + length + cpp/regex/match_results/length + + (T... args) + + + T + begin + cpp/regex/match_results/begin + + (T... args) + + + + std::overflow_error + cpp/error/overflow_error + + T + overflow_error + cpp/error/overflow_error + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::centi + cpp/numeric/ratio/ratio + + + std::wssub_match + cpp/regex/sub_match + + T + operator string_type + cpp/regex/sub_match/str + + (T... args) + + + T + str + cpp/regex/sub_match/str + + (T... args) + + + T + wssub_match + cpp/regex/sub_match/sub_match + + (T... args) + + + T + length + cpp/regex/sub_match/length + + (T... args) + + + T + compare + cpp/regex/sub_match/compare + + (T... args) + + + + std::is_nothrow_move_assignable + cpp/types/is_move_assignable + + + std::pair + cpp/utility/pair + + T + pair + cpp/utility/pair/pair + + (T... args) + + + T + swap + cpp/utility/pair/swap + + (T... args) + + + T + operator= + cpp/utility/pair/operator= + + (T... args) + + + + std::wsregex_token_iterator + cpp/regex/regex_token_iterator + + T + operator!= + cpp/regex/regex_token_iterator/operator_cmp + + (T... args) + + + T + operator= + cpp/regex/regex_token_iterator/operator= + + (T... args) + + + T + wsregex_token_iterator + cpp/regex/regex_token_iterator/regex_token_iterator + + (T... args) + + + T + operator-> + cpp/regex/regex_token_iterator/operator* + + (T... args) + + + T + operator++ + cpp/regex/regex_token_iterator/operator_arith + + (T... args) + + + T + operator== + cpp/regex/regex_token_iterator/operator_cmp + + (T... args) + + + T + operator* + cpp/regex/regex_token_iterator/operator* + + (T... args) + + + T + operator++(int) + cpp/regex/regex_token_iterator/operator_arith + + (T... args) + + + + std::weibull_distribution + cpp/numeric/random/weibull_distribution + + T + reset + cpp/numeric/random/weibull_distribution/reset + + (T... args) + + + T + a + cpp/numeric/random/weibull_distribution/params + + (T... args) + + + T + max + cpp/numeric/random/weibull_distribution/max + + (T... args) + + + T + weibull_distribution + cpp/numeric/random/weibull_distribution/weibull_distribution + + (T... args) + + + T + operator() + cpp/numeric/random/weibull_distribution/operator() + + (T... args) + + + T + param + cpp/numeric/random/weibull_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/weibull_distribution/min + + (T... args) + + + T + b + cpp/numeric/random/weibull_distribution/params + + (T... args) + + + + std::less + cpp/utility/functional/less + + T + operator() + cpp/utility/functional/less + + (T... args) + + + + std::multiplies + cpp/utility/functional/multiplies + + T + operator() + cpp/utility/functional/multiplies + + (T... args) + + + + std::is_enum + cpp/types/is_enum + + + std::unary_function + cpp/utility/functional/unary_function + + + std::error_code + cpp/error/error_code + + T + value + cpp/error/error_code/value + + (T... args) + + + T + operator bool + cpp/error/error_code/operator_bool + + (T... args) + + + T + assign + cpp/error/error_code/assign + + (T... args) + + + T + operator= + cpp/error/error_code/operator= + + (T... args) + + + T + error_code + cpp/error/error_code/error_code + + (T... args) + + + T + clear + cpp/error/error_code/clear + + (T... args) + + + T + default_error_condition + cpp/error/error_code/default_error_condition + + (T... args) + + + T + message + cpp/error/error_code/message + + (T... args) + + + T + category + cpp/error/error_code/category + + (T... args) + + + + std::yocto + cpp/numeric/ratio/ratio + + + std::streampos + cpp/io/fpos + + T + state + cpp/io/fpos/state + + (T... args) + + + + std::istream_iterator + cpp/iterator/istream_iterator + + + std::wifstream + cpp/io/basic_ifstream + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + + T + open + cpp/io/basic_ifstream/open + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + operator= + cpp/io/basic_ifstream/operator= + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + std::wifstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + close + cpp/io/basic_ifstream/close + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + std::wifstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + is_open + cpp/io/basic_ifstream/is_open + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + wifstream + cpp/io/basic_ifstream/basic_ifstream + + (T... args) + + std::wifstream::sentry + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::wifstream::event_callback + cpp/io/ios_base/event_callback + + + std::wifstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::wifstream::sentry + cpp/io/basic_istream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::moneypunct_byname + cpp/locale/moneypunct_byname + + T + do_curr_symbol + cpp/locale/moneypunct/curr_symbol + + (T... args) + + + T + do_decimal_point + cpp/locale/moneypunct/decimal_point + + (T... args) + + + T + thousands_sep + cpp/locale/moneypunct/thousands_sep + + (T... args) + + + T + moneypunct_byname + cpp/locale/moneypunct_byname + + (T... args) + + + T + curr_symbol + cpp/locale/moneypunct/curr_symbol + + (T... args) + + + T + do_thousands_sep + cpp/locale/moneypunct/thousands_sep + + (T... args) + + + T + positive_sign + cpp/locale/moneypunct/positive_sign + + (T... args) + + + T + frac_digits + cpp/locale/moneypunct/frac_digits + + (T... args) + + + T + do_negative_sign + cpp/locale/moneypunct/positive_sign + + (T... args) + + + T + pos_format + cpp/locale/moneypunct/pos_format + + (T... args) + + + T + do_pos_format + cpp/locale/moneypunct/pos_format + + (T... args) + + + T + neg_format + cpp/locale/moneypunct/pos_format + + (T... args) + + + T + negative_sign + cpp/locale/moneypunct/positive_sign + + (T... args) + + + T + grouping + cpp/locale/moneypunct/grouping + + (T... args) + + + T + do_frac_digits + cpp/locale/moneypunct/frac_digits + + (T... args) + + + T + decimal_point + cpp/locale/moneypunct/decimal_point + + (T... args) + + + T + do_neg_format + cpp/locale/moneypunct/pos_format + + (T... args) + + std::moneypunct_byname::string_type + std::moneypunct_byname::pattern + + T + do_positive_sign + cpp/locale/moneypunct/positive_sign + + (T... args) + + std::moneypunct_byname::char_type + + T + ~moneypunct_byname + cpp/locale/moneypunct_byname + + (T... args) + + + T + do_grouping + cpp/locale/moneypunct/grouping + + (T... args) + + + + std::moneypunct_byname::string_type + cpp/locale/moneypunct + + + std::moneypunct_byname::pattern + cpp/locale/money_base + + + std::moneypunct_byname::char_type + cpp/locale/moneypunct + + + std::terminate_handler + cpp/error/terminate_handler + + + std::ctype_base + cpp/locale/ctype_base + std::ctype_base::mask + + + std::ctype_base::mask + cpp/locale/ctype_base + + + std::reference_wrapper + cpp/utility/functional/reference_wrapper + + T + operator= + cpp/utility/functional/reference_wrapper/operator= + + (T... args) + + + T + operator() + cpp/utility/functional/reference_wrapper/operator() + + (T... args) + + + T + get + cpp/utility/functional/reference_wrapper/get + + (T... args) + + + T + reference_wrapper + cpp/utility/functional/reference_wrapper/reference_wrapper + + (T... args) + + + T + operator T& + cpp/utility/functional/reference_wrapper/get + + (T... args) + + + + std::ranlux48_base + cpp/numeric/random/subtract_with_carry_engine + + T + discard + cpp/numeric/random/subtract_with_carry_engine/discard + + (T... args) + + + T + ranlux48_base + cpp/numeric/random/subtract_with_carry_engine/subtract_with_carry_engine + + (T... args) + + + T + max + cpp/numeric/random/subtract_with_carry_engine/max + + (T... args) + + + T + operator() + cpp/numeric/random/subtract_with_carry_engine/operator() + + (T... args) + + + T + seed + cpp/numeric/random/subtract_with_carry_engine/seed + + (T... args) + + + T + min + cpp/numeric/random/subtract_with_carry_engine/min + + (T... args) + + + + std::bit_not + cpp/utility/functional/bit_not + + T + operator() + cpp/utility/functional/bit_not + + (T... args) + + + + std::int_fast16_t + cpp/types/integer + + + std::error_category + cpp/error/error_category + + T + name + cpp/error/error_category/name + + (T... args) + + + T + operator!= + cpp/error/error_category/operator_cmp + + (T... args) + + + T + operator< + cpp/error/error_category/operator_cmp + + (T... args) + + + T + error_category + cpp/error/error_category/error_category + + (T... args) + + + T + equivalent + cpp/error/error_category/equivalent + + (T... args) + + + T + operator== + cpp/error/error_category/operator_cmp + + (T... args) + + + T + ~error_category + cpp/error/error_category/~error_category + + (T... args) + + + T + default_error_condition + cpp/error/error_category/default_error_condition + + (T... args) + + + T + message + cpp/error/error_category/message + + (T... args) + + + + std::regex_traits + cpp/regex/regex_traits + + T + value + cpp/regex/regex_traits/value + + (T... args) + + + T + lookup_collatename + cpp/regex/regex_traits/lookup_collatename + + (T... args) + + + T + isctype + cpp/regex/regex_traits/isctype + + (T... args) + + + T + getloc + cpp/regex/regex_traits/getloc + + (T... args) + + + T + regex_traits + cpp/regex/regex_traits/regex_traits + + (T... args) + + + T + transform_primary + cpp/regex/regex_traits/transform_primary + + (T... args) + + + T + translate + cpp/regex/regex_traits/translate + + (T... args) + + + T + imbue + cpp/regex/regex_traits/imbue + + (T... args) + + + T + lookup_classname + cpp/regex/regex_traits/lookup_classname + + (T... args) + + + T + transform + cpp/regex/regex_traits/transform + + (T... args) + + + T + length + cpp/regex/regex_traits/length + + (T... args) + + + T + translate_nocase + cpp/regex/regex_traits/translate_nocase + + (T... args) + + + + std::regex_constants + + + + std::negative_binomial_distribution + cpp/numeric/random/negative_binomial_distribution + + T + p + cpp/numeric/random/negative_binomial_distribution/params + + (T... args) + + + T + negative_binomial_distribution + cpp/numeric/random/negative_binomial_distribution/negative_binomial_distribution + + (T... args) + + + T + min + cpp/numeric/random/negative_binomial_distribution/min + + (T... args) + + + T + max + cpp/numeric/random/negative_binomial_distribution/max + + (T... args) + + + T + param + cpp/numeric/random/negative_binomial_distribution/param + + (T... args) + + + T + reset + cpp/numeric/random/negative_binomial_distribution/reset + + (T... args) + + + T + k + cpp/numeric/random/negative_binomial_distribution/params + + (T... args) + + + + std::is_union + cpp/types/is_union + + + std::mt19937 + cpp/numeric/random/mersenne_twister_engine + + T + seed + cpp/numeric/random/mersenne_twister_engine/seed + + (T... args) + + + T + discard + cpp/numeric/random/mersenne_twister_engine/discard + + (T... args) + + + T + operator() + cpp/numeric/random/mersenne_twister_engine/operator() + + (T... args) + + + T + mt19937 + cpp/numeric/random/mersenne_twister_engine/mersenne_twister_engine + + (T... args) + + + T + max + cpp/numeric/random/mersenne_twister_engine/max + + (T... args) + + + T + min + cpp/numeric/random/mersenne_twister_engine/min + + (T... args) + + + + std::enable_if + cpp/types/enable_if + + + std::chi_squared_distribution + cpp/numeric/random/chi_squared_distribution + + T + n + cpp/numeric/random/chi_squared_distribution/n + + (T... args) + + + T + reset + cpp/numeric/random/chi_squared_distribution/reset + + (T... args) + + + T + max + cpp/numeric/random/chi_squared_distribution/max + + (T... args) + + + T + operator() + cpp/numeric/random/chi_squared_distribution/operator() + + (T... args) + + + T + param + cpp/numeric/random/chi_squared_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/chi_squared_distribution/min + + (T... args) + + + T + chi_squared_distribution + cpp/numeric/random/chi_squared_distribution/chi_squared_distribution + + (T... args) + + + + std::add_rvalue_reference + cpp/types/add_reference + + + std::basic_istream + cpp/io/basic_istream + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + std::basic_istream::event_callback + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + basic_istream + cpp/io/basic_istream/basic_istream + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + ~basic_istream + cpp/io/basic_istream/~basic_istream + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::basic_istream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + std::basic_istream::sentry + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::basic_istream::event_callback + cpp/io/ios_base/event_callback + + + std::basic_istream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::basic_istream::sentry + cpp/io/basic_istream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::ostream_iterator + cpp/iterator/ostream_iterator + + + std::is_trivially_copy_assignable + cpp/types/is_copy_assignable + + + std::clog + cpp/io/basic_ostream + + + std::is_scalar + cpp/types/is_scalar + + + std::uses_allocator + cpp/memory/uses_allocator + + + std::piecewise_linear_distribution + cpp/numeric/random/piecewise_linear_distribution + + T + piecewise_linear_distribution + cpp/numeric/random/piecewise_linear_distribution/piecewise_linear_distribution + + (T... args) + + + T + densities + cpp/numeric/random/piecewise_linear_distribution/params + + (T... args) + + + T + intervals + cpp/numeric/random/piecewise_linear_distribution/params + + (T... args) + + + T + reset + cpp/numeric/random/piecewise_linear_distribution/reset + + (T... args) + + + T + max + cpp/numeric/random/piecewise_linear_distribution/max + + (T... args) + + + T + operator() + cpp/numeric/random/piecewise_linear_distribution/operator() + + (T... args) + + + T + param + cpp/numeric/random/piecewise_linear_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/piecewise_linear_distribution/min + + (T... args) + + + + std::hash + cpp/utility/hash + + T + hash + cpp/utility/hash/hash + + (T... args) + + + T + operator() + cpp/utility/hash/operator() + + (T... args) + + + + std::shuffle_order_engine + cpp/numeric/random/shuffle_order_engine + + T + discard + cpp/numeric/random/shuffle_order_engine/discard + + (T... args) + + + T + shuffle_order_engine + cpp/numeric/random/shuffle_order_engine/shuffle_order_engine + + (T... args) + + + T + max + cpp/numeric/random/shuffle_order_engine/max + + (T... args) + + + T + operator() + cpp/numeric/random/shuffle_order_engine/operator() + + (T... args) + + + T + base + cpp/numeric/random/shuffle_order_engine/base + + (T... args) + + + T + seed + cpp/numeric/random/shuffle_order_engine/seed + + (T... args) + + + T + min + cpp/numeric/random/shuffle_order_engine/min + + (T... args) + + + + std::chrono + + std::chrono::minutes + + T + time_point_cast + cpp/chrono/time_point/time_point_cast + + (T... args) + + std::chrono::seconds + std::chrono::treat_as_floating_point + std::chrono::duration + std::chrono::milliseconds + std::chrono::steady_clock + std::chrono::system_clock + std::chrono::hours + std::chrono::time_point + std::chrono::high_resolution_clock + std::chrono::duration_values + std::chrono::microseconds + std::chrono::nanoseconds + + T + duration_cast + cpp/chrono/duration/duration_cast + + (T... args) + + + + std::chrono::minutes + cpp/chrono/duration + + T + operator--(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + minutes + cpp/chrono/duration/duration + + (T... args) + + + T + zero + cpp/chrono/duration/zero + + (T... args) + + + T + operator-- + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator+= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator- + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator/= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator++ + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator++(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator= + cpp/chrono/duration/operator= + + (T... args) + + + T + operator*= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + min + cpp/chrono/duration/min + + (T... args) + + + T + count + cpp/chrono/duration/count + + (T... args) + + + T + operator%= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + max + cpp/chrono/duration/max + + (T... args) + + + T + operator+ + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator-= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + + std::chrono::seconds + cpp/chrono/duration + + T + operator--(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + zero + cpp/chrono/duration/zero + + (T... args) + + + T + operator-- + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + count + cpp/chrono/duration/count + + (T... args) + + + T + operator+= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator- + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator/= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator++ + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator++(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator= + cpp/chrono/duration/operator= + + (T... args) + + + T + operator*= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + min + cpp/chrono/duration/min + + (T... args) + + + T + max + cpp/chrono/duration/max + + (T... args) + + + T + operator%= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + seconds + cpp/chrono/duration/duration + + (T... args) + + + T + operator+ + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator-= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + + std::chrono::treat_as_floating_point + cpp/chrono/treat_as_floating_point + + + std::chrono::duration + cpp/chrono/duration + + T + operator--(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + zero + cpp/chrono/duration/zero + + (T... args) + + + T + operator-- + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + count + cpp/chrono/duration/count + + (T... args) + + + T + operator+= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + duration + cpp/chrono/duration/duration + + (T... args) + + + T + operator/= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator++ + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator++(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator= + cpp/chrono/duration/operator= + + (T... args) + + + T + operator*= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + min + cpp/chrono/duration/min + + (T... args) + + + T + operator- + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator%= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + max + cpp/chrono/duration/max + + (T... args) + + + T + operator+ + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator-= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + + std::chrono::milliseconds + cpp/chrono/duration + + T + operator--(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + zero + cpp/chrono/duration/zero + + (T... args) + + + T + operator-- + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator+= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator- + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator/= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator++ + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + milliseconds + cpp/chrono/duration/duration + + (T... args) + + + T + operator++(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator= + cpp/chrono/duration/operator= + + (T... args) + + + T + operator*= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + min + cpp/chrono/duration/min + + (T... args) + + + T + count + cpp/chrono/duration/count + + (T... args) + + + T + operator%= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + max + cpp/chrono/duration/max + + (T... args) + + + T + operator+ + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator-= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + + std::chrono::steady_clock + cpp/chrono/steady_clock + + T + now + cpp/chrono/steady_clock/now + + (T... args) + + + + std::chrono::system_clock + cpp/chrono/system_clock + + T + now + cpp/chrono/system_clock/now + + (T... args) + + + T + to_time_t + cpp/chrono/system_clock/to_time_t + + (T... args) + + + T + from_time_t + cpp/chrono/system_clock/from_time_t + + (T... args) + + + + std::chrono::hours + cpp/chrono/duration + + T + operator--(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + zero + cpp/chrono/duration/zero + + (T... args) + + + T + operator-- + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator+= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator- + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator/= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator++ + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator++(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator= + cpp/chrono/duration/operator= + + (T... args) + + + T + operator*= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + hours + cpp/chrono/duration/duration + + (T... args) + + + T + min + cpp/chrono/duration/min + + (T... args) + + + T + count + cpp/chrono/duration/count + + (T... args) + + + T + operator%= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + max + cpp/chrono/duration/max + + (T... args) + + + T + operator+ + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator-= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + + std::chrono::time_point + cpp/chrono/time_point + + T + time_since_epoch + cpp/chrono/time_point/time_since_epoch + + (T... args) + + + T + min + cpp/chrono/time_point/min + + (T... args) + + + T + operator- + cpp/chrono/time_point/operator_arith + + (T... args) + + + T + max + cpp/chrono/time_point/max + + (T... args) + + + T + operator+ + cpp/chrono/time_point/operator_arith + + (T... args) + + + T + time_point + cpp/chrono/time_point/time_point + + (T... args) + + + + std::chrono::high_resolution_clock + cpp/chrono/high_resolution_clock + + T + now + cpp/chrono/high_resolution_clock/now + + (T... args) + + + + std::chrono::duration_values + cpp/chrono/duration_values + + T + max + cpp/chrono/duration_values/max + + (T... args) + + + T + zero + cpp/chrono/duration_values/zero + + (T... args) + + + T + min + cpp/chrono/duration_values/min + + (T... args) + + + + std::chrono::microseconds + cpp/chrono/duration + + T + operator--(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + zero + cpp/chrono/duration/zero + + (T... args) + + + T + operator-- + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + count + cpp/chrono/duration/count + + (T... args) + + + T + operator+= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator/= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator++ + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator++(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator= + cpp/chrono/duration/operator= + + (T... args) + + + T + operator*= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + min + cpp/chrono/duration/min + + (T... args) + + + T + operator- + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator%= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + max + cpp/chrono/duration/max + + (T... args) + + + T + microseconds + cpp/chrono/duration/duration + + (T... args) + + + T + operator+ + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator-= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + + std::chrono::nanoseconds + cpp/chrono/duration + + T + operator--(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + min + cpp/chrono/duration/min + + (T... args) + + + T + zero + cpp/chrono/duration/zero + + (T... args) + + + T + operator-- + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator+= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator- + cpp/chrono/duration/operator_arith + + (T... args) + + + T + operator/= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator++ + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator++(int) + cpp/chrono/duration/operator_arith2 + + (T... args) + + + T + operator= + cpp/chrono/duration/operator= + + (T... args) + + + T + operator*= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + operator+ + cpp/chrono/duration/operator_arith + + (T... args) + + + T + count + cpp/chrono/duration/count + + (T... args) + + + T + operator%= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + T + max + cpp/chrono/duration/max + + (T... args) + + + T + nanoseconds + cpp/chrono/duration/duration + + (T... args) + + + T + operator-= + cpp/chrono/duration/operator_arith3 + + (T... args) + + + + std::greater + cpp/utility/functional/greater + + T + operator() + cpp/utility/functional/greater + + (T... args) + + + + std::csub_match + cpp/regex/sub_match + + T + csub_match + cpp/regex/sub_match/sub_match + + (T... args) + + + T + operator string_type + cpp/regex/sub_match/str + + (T... args) + + + T + str + cpp/regex/sub_match/str + + (T... args) + + + T + length + cpp/regex/sub_match/length + + (T... args) + + + T + compare + cpp/regex/sub_match/compare + + (T... args) + + + + std::uintmax_t + cpp/types/integer + + + std::remove_pointer + cpp/types/remove_pointer + + + std::numeric_limits + cpp/types/numeric_limits + + T + lowest + cpp/types/numeric_limits/lowest + + (T... args) + + + T + infinity + cpp/types/numeric_limits/infinity + + (T... args) + + + T + signaling_NaN + cpp/types/numeric_limits/signaling_NaN + + (T... args) + + + T + quiet_NaN + cpp/types/numeric_limits/quiet_NaN + + (T... args) + + + T + denorm_min + cpp/types/numeric_limits/denorm_min + + (T... args) + + + T + max + cpp/types/numeric_limits/max + + (T... args) + + + T + round_error + cpp/types/numeric_limits/round_error + + (T... args) + + + T + min + cpp/types/numeric_limits/min + + (T... args) + + + T + epsilon + cpp/types/numeric_limits/epsilon + + (T... args) + + + + std::add_volatile + cpp/types/add_cv + + + std::once_flag + cpp/thread/once_flag + + T + once_flag + cpp/thread/once_flag + + (T... args) + + + + std::is_literal_type + cpp/types/is_literal_type + + + std::money_base + cpp/locale/money_base + std::money_base::pattern + + + std::money_base::pattern + cpp/locale/money_base + + + std::peta + cpp/numeric/ratio/ratio + + + std::is_placeholder + cpp/utility/functional/is_placeholder + + + std::add_const + cpp/types/add_cv + + + std::basic_stringbuf + cpp/io/basic_stringbuf + + T + pptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + epptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + eback + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + setp + cpp/io/basic_streambuf/setp + + (T... args) + + + T + sputbackc + cpp/io/basic_streambuf/sputbackc + + (T... args) + + + T + sgetc + cpp/io/basic_streambuf/sgetc + + (T... args) + + + T + sungetc + cpp/io/basic_streambuf/sungetc + + (T... args) + + + T + pubseekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + seekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + str + cpp/io/basic_stringbuf/str + + (T... args) + + + T + sync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + xsputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + pbase + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + pubimbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + showmanyc + cpp/io/basic_streambuf/showmanyc + + (T... args) + + + T + basic_stringbuf + cpp/io/basic_stringbuf/basic_stringbuf + + (T... args) + + + T + egptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + seekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + underflow + cpp/io/basic_streambuf/underflow + + (T... args) + + + T + setbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + gbump + cpp/io/basic_streambuf/gbump + + (T... args) + + + T + in_avail + cpp/io/basic_streambuf/in_avail + + (T... args) + + + T + swap + cpp/io/basic_streambuf/swap + + (T... args) + + + T + pbackfail + cpp/io/basic_streambuf/pbackfail + + (T... args) + + + T + sputc + cpp/io/basic_streambuf/sputc + + (T... args) + + + T + xsgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + uflow + cpp/io/basic_streambuf/uflow + + (T... args) + + + T + gptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + sputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + sgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + sbumpc + cpp/io/basic_streambuf/sbumpc + + (T... args) + + + T + overflow + cpp/io/basic_streambuf/overflow + + (T... args) + + + T + operator= + cpp/io/basic_stringbuf/operator= + + (T... args) + + + T + pbump + cpp/io/basic_streambuf/pbump + + (T... args) + + + T + pubsetbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + pubsync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + imbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + setg + cpp/io/basic_streambuf/setg + + (T... args) + + + T + snextc + cpp/io/basic_streambuf/snextc + + (T... args) + + + T + getloc + cpp/io/basic_streambuf/getloc + + (T... args) + + + T + pubseekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + + std::tm + cpp/chrono/c/tm + + + std::is_abstract + cpp/types/is_abstract + + + std::deque + cpp/container/deque + + T + pop_front + cpp/container/deque/pop_front + + (T... args) + + + T + push_back + cpp/container/deque/push_back + + (T... args) + + + T + shrink_to_fit + cpp/container/deque/shrink_to_fit + + (T... args) + + + T + crbegin + cpp/container/deque/rbegin + + (T... args) + + + T + erase + cpp/container/deque/erase + + (T... args) + + + T + insert + cpp/container/deque/insert + + (T... args) + + + T + ~deque + cpp/container/deque/~deque + + (T... args) + + + T + back + cpp/container/deque/back + + (T... args) + + + T + end + cpp/container/deque/end + + (T... args) + + + T + push_front + cpp/container/deque/push_front + + (T... args) + + + T + emplace_back + cpp/container/deque/emplace_back + + (T... args) + + + T + pop_back + cpp/container/deque/pop_back + + (T... args) + + + T + cbegin + cpp/container/deque/begin + + (T... args) + + + T + front + cpp/container/deque/front + + (T... args) + + + T + deque + cpp/container/deque/deque + + (T... args) + + + T + size + cpp/container/deque/size + + (T... args) + + + T + resize + cpp/container/deque/resize + + (T... args) + + + T + emplace_front + cpp/container/deque/emplace_front + + (T... args) + + + T + rbegin + cpp/container/deque/rbegin + + (T... args) + + + T + crend + cpp/container/deque/rend + + (T... args) + + + T + assign + cpp/container/deque/assign + + (T... args) + + + T + operator= + cpp/container/deque/operator= + + (T... args) + + + T + empty + cpp/container/deque/empty + + (T... args) + + + T + cend + cpp/container/deque/end + + (T... args) + + + T + swap + cpp/container/deque/swap + + (T... args) + + + T + max_size + cpp/container/deque/max_size + + (T... args) + + + T + rend + cpp/container/deque/rend + + (T... args) + + + T + get_allocator + cpp/container/deque/get_allocator + + (T... args) + + + T + clear + cpp/container/deque/clear + + (T... args) + + + T + at + cpp/container/deque/at + + (T... args) + + + T + emplace + cpp/container/deque/emplace + + (T... args) + + + T + operator[] + cpp/container/deque/operator_at + + (T... args) + + + T + begin + cpp/container/deque/begin + + (T... args) + + + + std::allocator + cpp/memory/allocator + + T + allocator + cpp/memory/allocator/allocator + + (T... args) + + + T + allocate + cpp/memory/allocator/allocate + + (T... args) + + + T + destroy + cpp/memory/allocator/destroy + + (T... args) + + + T + ~allocator + cpp/memory/allocator/~allocator + + (T... args) + + + T + max_size + cpp/memory/allocator/max_size + + (T... args) + + + T + address + cpp/memory/allocator/address + + (T... args) + + + T + deallocate + cpp/memory/allocator/deallocate + + (T... args) + + + T + construct + cpp/memory/allocator/construct + + (T... args) + + + + std::scoped_allocator_adaptor + cpp/memory/scoped_allocator_adaptor + + T + deallocate + cpp/memory/scoped_allocator_adaptor/deallocate + + (T... args) + + + T + scoped_allocator_adaptor + cpp/memory/scoped_allocator_adaptor/scoped_allocator_adaptor + + (T... args) + + + T + destroy + cpp/memory/scoped_allocator_adaptor/destroy + + (T... args) + + + T + construct + cpp/memory/scoped_allocator_adaptor/construct + + (T... args) + + + T + max_size + cpp/memory/scoped_allocator_adaptor/max_size + + (T... args) + + + T + inner_allocator + cpp/memory/scoped_allocator_adaptor/inner_allocator + + (T... args) + + + T + select_on_container_copy_construction + cpp/memory/scoped_allocator_adaptor/select_on_container_copy_construction + + (T... args) + + + T + allocate + cpp/memory/scoped_allocator_adaptor/allocate + + (T... args) + + + T + outer_allocator + cpp/memory/scoped_allocator_adaptor/outer_allocator + + (T... args) + + + T + ~scoped_allocator_adaptor + cpp/memory/scoped_allocator_adaptor/~scoped_allocator_adaptor + + (T... args) + + + + std::ssub_match + cpp/regex/sub_match + + T + operator string_type + cpp/regex/sub_match/str + + (T... args) + + + T + ssub_match + cpp/regex/sub_match/sub_match + + (T... args) + + + T + str + cpp/regex/sub_match/str + + (T... args) + + + T + length + cpp/regex/sub_match/length + + (T... args) + + + T + compare + cpp/regex/sub_match/compare + + (T... args) + + + + std::messages_byname + cpp/locale/messages_byname + + T + do_get + cpp/locale/messages/get + + (T... args) + + std::messages_byname::char_type + std::messages_byname::catalog + + T + ~messages_byname + cpp/locale/messages_byname + + (T... args) + + + T + messages_byname + cpp/locale/messages_byname + + (T... args) + + + T + do_open + cpp/locale/messages/open + + (T... args) + + + T + do_close + cpp/locale/messages/close + + (T... args) + + + T + open + cpp/locale/messages/open + + (T... args) + + std::messages_byname::string_type + + T + get + cpp/locale/messages/get + + (T... args) + + + T + close + cpp/locale/messages/close + + (T... args) + + + + std::messages_byname::char_type + cpp/locale/messages + + + std::messages_byname::catalog + cpp/locale/messages_base + + + std::messages_byname::string_type + cpp/locale/messages + + + std::promise + cpp/thread/promise + + T + set_exception + cpp/thread/promise/set_exception + + (T... args) + + + T + operator= + cpp/thread/promise/operator= + + (T... args) + + + T + swap + cpp/thread/promise/swap + + (T... args) + + + T + set_exception_at_thread_exit + cpp/thread/promise/set_exception_at_thread_exit + + (T... args) + + + T + set_value + cpp/thread/promise/set_value + + (T... args) + + + T + get_future + cpp/thread/promise/get_future + + (T... args) + + + T + promise + cpp/thread/promise/promise + + (T... args) + + + T + ~promise + cpp/thread/promise/~promise + + (T... args) + + + T + set_value_at_thread_exit + cpp/thread/promise/set_value_at_thread_exit + + (T... args) + + + + std::add_pointer + cpp/types/add_pointer + + + std::uintptr_t + cpp/types/integer + + + std::bit_and + cpp/utility/functional/bit_and + + T + operator() + cpp/utility/functional/bit_and + + (T... args) + + + + std::uniform_int_distribution + cpp/numeric/random/uniform_int_distribution + + T + min + cpp/numeric/random/uniform_int_distribution/min + + (T... args) + + + T + b + cpp/numeric/random/uniform_int_distribution/params + + (T... args) + + + T + a + cpp/numeric/random/uniform_int_distribution/params + + (T... args) + + + T + max + cpp/numeric/random/uniform_int_distribution/max + + (T... args) + + + T + operator() + cpp/numeric/random/uniform_int_distribution/operator() + + (T... args) + + + T + param + cpp/numeric/random/uniform_int_distribution/param + + (T... args) + + + T + reset + cpp/numeric/random/uniform_int_distribution/reset + + (T... args) + + + T + uniform_int_distribution + cpp/numeric/random/uniform_int_distribution/uniform_int_distribution + + (T... args) + + + + std::type_info + cpp/types/type_info + + T + operator!= + cpp/types/type_info/operator_cmp + + (T... args) + + + T + before + cpp/types/type_info/before + + (T... args) + + + T + name + cpp/types/type_info/name + + (T... args) + + + T + operator== + cpp/types/type_info/operator_cmp + + (T... args) + + + T + hash_code + cpp/types/type_info/hash_code + + (T... args) + + + + std::fisher_f_distribution + cpp/numeric/random/fisher_f_distribution + + T + fisher_f_distribution + cpp/numeric/random/fisher_f_distribution/fisher_f_distribution + + (T... args) + + + T + n + cpp/numeric/random/fisher_f_distribution/params + + (T... args) + + + T + reset + cpp/numeric/random/fisher_f_distribution/reset + + (T... args) + + + T + m + cpp/numeric/random/fisher_f_distribution/params + + (T... args) + + + T + operator() + cpp/numeric/random/fisher_f_distribution/operator() + + (T... args) + + + T + max + cpp/numeric/random/fisher_f_distribution/max + + (T... args) + + + T + param + cpp/numeric/random/fisher_f_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/fisher_f_distribution/min + + (T... args) + + + + std::strstream + cpp/io/strstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + str + cpp/io/strstream/str + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + pcount + cpp/io/strstream/pcount + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + std::strstream::sentry + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + std::strstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::strstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + strstream + cpp/io/strstream/strstream + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + freeze + cpp/io/strstream/freeze + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + ~strstream + cpp/io/strstream/~strstream + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::strstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::strstream::event_callback + cpp/io/ios_base/event_callback + + + std::strstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::time_get_byname + cpp/locale/time_get_byname + + T + do_get + cpp/locale/time_get/get + + (T... args) + + + T + do_get_monthname + cpp/locale/time_get/get_monthname + + (T... args) + + + T + get_weekday + cpp/locale/time_get/get_weekday + + (T... args) + + + T + do_get_time + cpp/locale/time_get/get_time + + (T... args) + + + T + time_get_byname + cpp/locale/time_get_byname + + (T... args) + + + T + do_get_year + cpp/locale/time_get/get_year + + (T... args) + + std::time_get_byname::iter_type + + T + get_monthname + cpp/locale/time_get/get_monthname + + (T... args) + + + T + ~time_get_byname + cpp/locale/time_get_byname + + (T... args) + + + T + get_time + cpp/locale/time_get/get_time + + (T... args) + + std::time_get_byname::char_type + + T + do_get_date + cpp/locale/time_get/get_date + + (T... args) + + + T + get_date + cpp/locale/time_get/get_date + + (T... args) + + + T + do_date_order + cpp/locale/time_get/date_order + + (T... args) + + + T + get_year + cpp/locale/time_get/get_year + + (T... args) + + + T + date_order + cpp/locale/time_get/date_order + + (T... args) + + + T + get + cpp/locale/time_get/get + + (T... args) + + + T + do_get_weekday + cpp/locale/time_get/get_weekday + + (T... args) + + + + std::time_get_byname::iter_type + cpp/locale/time_get + + + std::time_get_byname::char_type + cpp/locale/time_get + + + std::basic_streambuf + cpp/io/basic_streambuf + + T + pptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + epptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + eback + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + setp + cpp/io/basic_streambuf/setp + + (T... args) + + + T + sputbackc + cpp/io/basic_streambuf/sputbackc + + (T... args) + + + T + getloc + cpp/io/basic_streambuf/getloc + + (T... args) + + + T + seekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + pubseekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + sungetc + cpp/io/basic_streambuf/sungetc + + (T... args) + + + T + sync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + xsputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + pbase + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + sgetc + cpp/io/basic_streambuf/sgetc + + (T... args) + + + T + pubimbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + showmanyc + cpp/io/basic_streambuf/showmanyc + + (T... args) + + + T + egptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + seekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + underflow + cpp/io/basic_streambuf/underflow + + (T... args) + + + T + setbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + gbump + cpp/io/basic_streambuf/gbump + + (T... args) + + + T + in_avail + cpp/io/basic_streambuf/in_avail + + (T... args) + + + T + swap + cpp/io/basic_streambuf/swap + + (T... args) + + + T + basic_streambuf + cpp/io/basic_streambuf/basic_streambuf + + (T... args) + + + T + pbackfail + cpp/io/basic_streambuf/pbackfail + + (T... args) + + + T + sputc + cpp/io/basic_streambuf/sputc + + (T... args) + + + T + xsgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + uflow + cpp/io/basic_streambuf/uflow + + (T... args) + + + T + overflow + cpp/io/basic_streambuf/overflow + + (T... args) + + + T + sputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + sgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + sbumpc + cpp/io/basic_streambuf/sbumpc + + (T... args) + + + T + operator= + cpp/io/basic_streambuf/operator= + + (T... args) + + + T + pbump + cpp/io/basic_streambuf/pbump + + (T... args) + + + T + pubsetbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + pubsync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + imbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + setg + cpp/io/basic_streambuf/setg + + (T... args) + + + T + snextc + cpp/io/basic_streambuf/snextc + + (T... args) + + + T + gptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + pubseekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + ~basic_streambuf + cpp/io/basic_streambuf/~basic_streambuf + + (T... args) + + + + std::is_nothrow_constructible + cpp/types/is_constructible + + + std::queue + cpp/container/queue + + T + operator= + cpp/container/queue/operator= + + (T... args) + + + T + swap + cpp/container/queue/swap + + (T... args) + + + T + emplace + cpp/container/queue/emplace + + (T... args) + + + T + empty + cpp/container/queue/empty + + (T... args) + + + T + ~queue + cpp/container/queue/~queue + + (T... args) + + + T + pop + cpp/container/queue/pop + + (T... args) + + + T + front + cpp/container/queue/front + + (T... args) + + + T + push + cpp/container/queue/push + + (T... args) + + + T + queue + cpp/container/queue/queue + + (T... args) + + + T + back + cpp/container/queue/back + + (T... args) + + + T + size + cpp/container/queue/size + + (T... args) + + + + std::is_base_of + cpp/types/is_base_of + + + std::intmax_t + cpp/types/integer + + + std::ranlux24 + cpp/numeric/random/discard_block_engine + + T + discard + cpp/numeric/random/discard_block_engine/discard + + (T... args) + + + T + ranlux24 + cpp/numeric/random/discard_block_engine/discard_block_engine + + (T... args) + + + T + max + cpp/numeric/random/discard_block_engine/max + + (T... args) + + + T + operator() + cpp/numeric/random/discard_block_engine/operator() + + (T... args) + + + T + base + cpp/numeric/random/discard_block_engine/base + + (T... args) + + + T + seed + cpp/numeric/random/discard_block_engine/seed + + (T... args) + + + T + min + cpp/numeric/random/discard_block_engine/min + + (T... args) + + + + std::remove_cv + cpp/types/remove_cv + + + std::is_trivially_destructible + cpp/types/is_destructible + + + std::wcin + cpp/io/basic_istream + + + std::atomic + cpp/atomic/atomic + + T + store + cpp/atomic/atomic/store + + (T... args) + + + T + compare_exchange_strong + cpp/atomic/atomic/compare_exchange + + (T... args) + + + T + load + cpp/atomic/atomic/load + + (T... args) + + + T + operator--(int) + cpp/atomic/atomic/operator_arith + + (T... args) + + + T + operator+= + cpp/atomic/atomic/operator_arith2 + + (T... args) + + + T + fetch_or + cpp/atomic/atomic/fetch_or + + (T... args) + + + T + fetch_xor + cpp/atomic/atomic/fetch_xor + + (T... args) + + + T + operator^= + cpp/atomic/atomic/operator_arith2 + + (T... args) + + + T + operator|= + cpp/atomic/atomic/operator_arith2 + + (T... args) + + + T + compare_exchange_weak + cpp/atomic/atomic/compare_exchange + + (T... args) + + + T + operator-= + cpp/atomic/atomic/operator_arith2 + + (T... args) + + + T + fetch_add + cpp/atomic/atomic/fetch_add + + (T... args) + + + T + operator&= + cpp/atomic/atomic/operator_arith2 + + (T... args) + + + T + operator-- + cpp/atomic/atomic/operator_arith + + (T... args) + + + T + atomic + cpp/atomic/atomic/atomic + + (T... args) + + + T + fetch_and + cpp/atomic/atomic/fetch_and + + (T... args) + + + T + exchange + cpp/atomic/atomic/exchange + + (T... args) + + + T + operator T + cpp/atomic/atomic/operator_T + + (T... args) + + + T + operator++(int) + cpp/atomic/atomic/operator_arith + + (T... args) + + + T + operator= + cpp/atomic/atomic/operator= + + (T... args) + + + T + operator++ + cpp/atomic/atomic/operator_arith + + (T... args) + + + T + fetch_sub + cpp/atomic/atomic/fetch_sub + + (T... args) + + + T + is_lock_free + cpp/atomic/atomic/is_lock_free + + (T... args) + + + + std::basic_stringstream + cpp/io/basic_stringstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + str + cpp/io/basic_stringstream/str + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + basic_stringstream + cpp/io/basic_stringstream/basic_stringstream + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + std::basic_stringstream::sentry + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + std::basic_stringstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::basic_stringstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + operator= + cpp/io/basic_stringstream/operator= + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::basic_stringstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::basic_stringstream::event_callback + cpp/io/ios_base/event_callback + + + std::basic_stringstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::is_void + cpp/types/is_void + + + std::plus + cpp/utility/functional/plus + + T + operator() + cpp/utility/functional/plus + + (T... args) + + + + std::bitset + cpp/utility/bitset + + T + none + cpp/utility/bitset/all_any_none + + (T... args) + + + T + operator<< + cpp/utility/bitset/operator_ltltgtgt + + (T... args) + + + T + operator>> + cpp/utility/bitset/operator_ltltgtgt + + (T... args) + + std::bitset::reference + + T + reset + cpp/utility/bitset/reset + + (T... args) + + + T + count + cpp/utility/bitset/count + + (T... args) + + + T + operator<<= + cpp/utility/bitset/operator_ltltgtgt + + (T... args) + + + T + operator|= + cpp/utility/bitset/operator_logic + + (T... args) + + + T + operator&= + cpp/utility/bitset/operator_logic + + (T... args) + + + T + bitset + cpp/utility/bitset/bitset + + (T... args) + + + T + size + cpp/utility/bitset/size + + (T... args) + + + T + set + cpp/utility/bitset/set + + (T... args) + + + T + all + cpp/utility/bitset/all_any_none + + (T... args) + + + T + to_string + cpp/utility/bitset/to_string + + (T... args) + + + T + operator!= + cpp/utility/bitset/operator_cmp + + (T... args) + + + T + any + cpp/utility/bitset/all_any_none + + (T... args) + + + T + test + cpp/utility/bitset/test + + (T... args) + + + T + operator== + cpp/utility/bitset/operator_cmp + + (T... args) + + + T + operator>>= + cpp/utility/bitset/operator_ltltgtgt + + (T... args) + + + T + to_ulong + cpp/utility/bitset/to_ulong + + (T... args) + + + T + operator^= + cpp/utility/bitset/operator_logic + + (T... args) + + + T + operator~ + cpp/utility/bitset/operator_logic + + (T... args) + + + T + to_ullong + cpp/utility/bitset/to_ullong + + (T... args) + + + T + operator[] + cpp/utility/bitset/operator_at + + (T... args) + + + T + flip + cpp/utility/bitset/flip + + (T... args) + + + + std::bitset::reference + cpp/utility/bitset/reference + + + std::FILE + cpp/io/c + + + std::thread + cpp/thread/thread + + T + joinable + cpp/thread/thread/joinable + + (T... args) + + + T + operator= + cpp/thread/thread/operator= + + (T... args) + + + T + native_handle + cpp/thread/thread/native_handle + + (T... args) + + + T + ~thread + cpp/thread/thread/~thread + + (T... args) + + + T + swap + cpp/thread/thread/swap + + (T... args) + + + T + hardware_concurrency + cpp/thread/thread/hardware_concurrency + + (T... args) + + std::thread::id + + T + thread + cpp/thread/thread/thread + + (T... args) + + + T + join + cpp/thread/thread/join + + (T... args) + + + T + detach + cpp/thread/thread/detach + + (T... args) + + + T + get_id + cpp/thread/thread/get_id + + (T... args) + + + + std::thread::id + cpp/thread/thread/id + + T + operator!= + cpp/thread/thread/id/operator_cmp + + (T... args) + + + T + operator>= + cpp/thread/thread/id/operator_cmp + + (T... args) + + + T + operator<= + cpp/thread/thread/id/operator_cmp + + (T... args) + + + T + operator< + cpp/thread/thread/id/operator_cmp + + (T... args) + + + T + operator== + cpp/thread/thread/id/operator_cmp + + (T... args) + + + T + operator<< + cpp/thread/thread/id/operator_ltlt + + (T... args) + + + T + id + cpp/thread/thread/id/id + + (T... args) + + + T + operator> + cpp/thread/thread/id/operator_cmp + + (T... args) + + + + std::future_error + cpp/thread/future_error + + T + code + cpp/thread/future_error/code + + (T... args) + + + T + future_error + cpp/thread/future_error/future_error + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::time_base + cpp/locale/time_base + + + std::alignment_of + cpp/types/alignment_of + + + std::time_put + cpp/locale/time_put + std::time_put::char_type + std::time_put::iter_type + + T + do_put + cpp/locale/time_put/put + + (T... args) + + + T + ~time_put + cpp/locale/time_put/~time_put + + (T... args) + + + T + put + cpp/locale/time_put/put + + (T... args) + + + T + time_put + cpp/locale/time_put/time_put + + (T... args) + + + + std::time_put::char_type + cpp/locale/time_put + + + std::time_put::iter_type + cpp/locale/time_put + + + std::bit_or + cpp/utility/functional/bit_or + + T + operator() + cpp/utility/functional/bit_or + + (T... args) + + + + std::pointer_traits + cpp/memory/pointer_traits + + T + pointer_to + cpp/memory/pointer_traits/pointer_to + + (T... args) + + + + std::basic_string + cpp/string/basic_string + + T + push_back + cpp/string/basic_string/push_back + + (T... args) + + + T + shrink_to_fit + cpp/string/basic_string/shrink_to_fit + + (T... args) + + + T + rfind + cpp/string/basic_string/rfind + + (T... args) + + + T + begin + cpp/string/basic_string/begin + + (T... args) + + + T + erase + cpp/string/basic_string/erase + + (T... args) + + + T + append + cpp/string/basic_string/append + + (T... args) + + + T + data + cpp/string/basic_string/data + + (T... args) + + + T + insert + cpp/string/basic_string/insert + + (T... args) + + + T + assign + cpp/string/basic_string/assign + + (T... args) + + + T + find_first_not_of + cpp/string/basic_string/find_first_not_of + + (T... args) + + + T + back + cpp/string/basic_string/back + + (T... args) + + + T + end + cpp/string/basic_string/end + + (T... args) + + + T + resize + cpp/string/basic_string/resize + + (T... args) + + + T + copy + cpp/string/basic_string/copy + + (T... args) + + + T + find_last_of + cpp/string/basic_string/find_last_of + + (T... args) + + + T + pop_back + cpp/string/basic_string/pop_back + + (T... args) + + + T + cbegin + cpp/string/basic_string/begin + + (T... args) + + + T + replace + cpp/string/basic_string/replace + + (T... args) + + + T + front + cpp/string/basic_string/front + + (T... args) + + + T + find + cpp/string/basic_string/find + + (T... args) + + + T + compare + cpp/string/basic_string/compare + + (T... args) + + + T + crbegin + cpp/string/basic_string/rbegin + + (T... args) + + + T + at + cpp/string/basic_string/at + + (T... args) + + + T + find_first_of + cpp/string/basic_string/find_first_of + + (T... args) + + + T + rbegin + cpp/string/basic_string/rbegin + + (T... args) + + + T + crend + cpp/string/basic_string/rend + + (T... args) + + + T + size + cpp/string/basic_string/size + + (T... args) + + + T + operator= + cpp/string/basic_string/operator= + + (T... args) + + + T + find_last_not_of + cpp/string/basic_string/find_last_not_of + + (T... args) + + + T + reserve + cpp/string/basic_string/reserve + + (T... args) + + + T + capacity + cpp/string/basic_string/capacity + + (T... args) + + + T + c_str + cpp/string/basic_string/c_str + + (T... args) + + + T + empty + cpp/string/basic_string/empty + + (T... args) + + + T + cend + cpp/string/basic_string/end + + (T... args) + + + T + substr + cpp/string/basic_string/substr + + (T... args) + + + T + max_size + cpp/string/basic_string/max_size + + (T... args) + + + T + rend + cpp/string/basic_string/rend + + (T... args) + + + T + get_allocator + cpp/string/basic_string/get_allocator + + (T... args) + + + T + clear + cpp/string/basic_string/clear + + (T... args) + + + T + swap + cpp/string/basic_string/swap + + (T... args) + + + T + operator[] + cpp/string/basic_string/operator_at + + (T... args) + + + T + length + cpp/string/basic_string/size + + (T... args) + + + T + basic_string + cpp/string/basic_string/basic_string + + (T... args) + + + + std::priority_queue + cpp/container/priority_queue + + T + empty + cpp/container/priority_queue/empty + + (T... args) + + + T + swap + cpp/container/priority_queue/swap + + (T... args) + + + T + priority_queue + cpp/container/priority_queue/priority_queue + + (T... args) + + + T + size + cpp/container/priority_queue/size + + (T... args) + + + T + operator= + cpp/container/priority_queue/operator= + + (T... args) + + + T + pop + cpp/container/priority_queue/pop + + (T... args) + + + T + emplace + cpp/container/priority_queue/emplace + + (T... args) + + + T + push + cpp/container/priority_queue/push + + (T... args) + + + T + top + cpp/container/priority_queue/top + + (T... args) + + + T + ~priority_queue + cpp/container/priority_queue/~priority_queue + + (T... args) + + + + std::exa + cpp/numeric/ratio/ratio + + + std::wostringstream + cpp/io/basic_ostringstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + str + cpp/io/basic_ostringstream/str + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + std::wostringstream::event_callback + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + wostringstream + cpp/io/basic_ostringstream/basic_ostringstream + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::wostringstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + operator= + cpp/io/basic_ostringstream/operator= + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + std::wostringstream::sentry + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::wostringstream::event_callback + cpp/io/ios_base/event_callback + + + std::wostringstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::wostringstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_ostream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + + std::is_default_constructible + cpp/types/is_default_constructible + + + std::cregex_iterator + cpp/regex/regex_iterator + + T + operator!= + cpp/regex/regex_iterator/operator_cmp + + (T... args) + + + T + operator= + cpp/regex/regex_iterator/operator= + + (T... args) + + + T + cregex_iterator + cpp/regex/regex_iterator/regex_iterator + + (T... args) + + + T + operator-> + cpp/regex/regex_iterator/operator* + + (T... args) + + + T + operator++ + cpp/regex/regex_iterator/operator_arith + + (T... args) + + + T + operator== + cpp/regex/regex_iterator/operator_cmp + + (T... args) + + + T + operator* + cpp/regex/regex_iterator/operator* + + (T... args) + + + T + operator++(int) + cpp/regex/regex_iterator/operator_arith + + (T... args) + + + + std::wstring + cpp/string/basic_string + + T + push_back + cpp/string/basic_string/push_back + + (T... args) + + + T + shrink_to_fit + cpp/string/basic_string/shrink_to_fit + + (T... args) + + + T + rfind + cpp/string/basic_string/rfind + + (T... args) + + + T + begin + cpp/string/basic_string/begin + + (T... args) + + + T + erase + cpp/string/basic_string/erase + + (T... args) + + + T + append + cpp/string/basic_string/append + + (T... args) + + + T + data + cpp/string/basic_string/data + + (T... args) + + + T + insert + cpp/string/basic_string/insert + + (T... args) + + + T + assign + cpp/string/basic_string/assign + + (T... args) + + + T + find_first_not_of + cpp/string/basic_string/find_first_not_of + + (T... args) + + + T + back + cpp/string/basic_string/back + + (T... args) + + + T + end + cpp/string/basic_string/end + + (T... args) + + + T + resize + cpp/string/basic_string/resize + + (T... args) + + + T + copy + cpp/string/basic_string/copy + + (T... args) + + + T + find_last_of + cpp/string/basic_string/find_last_of + + (T... args) + + + T + pop_back + cpp/string/basic_string/pop_back + + (T... args) + + + T + replace + cpp/string/basic_string/replace + + (T... args) + + + T + wstring + cpp/string/basic_string/basic_string + + (T... args) + + + T + front + cpp/string/basic_string/front + + (T... args) + + + T + find + cpp/string/basic_string/find + + (T... args) + + + T + compare + cpp/string/basic_string/compare + + (T... args) + + + T + crbegin + cpp/string/basic_string/rbegin + + (T... args) + + + T + cbegin + cpp/string/basic_string/begin + + (T... args) + + + T + find_first_of + cpp/string/basic_string/find_first_of + + (T... args) + + + T + rbegin + cpp/string/basic_string/rbegin + + (T... args) + + + T + crend + cpp/string/basic_string/rend + + (T... args) + + + T + size + cpp/string/basic_string/size + + (T... args) + + + T + operator= + cpp/string/basic_string/operator= + + (T... args) + + + T + find_last_not_of + cpp/string/basic_string/find_last_not_of + + (T... args) + + + T + reserve + cpp/string/basic_string/reserve + + (T... args) + + + T + capacity + cpp/string/basic_string/capacity + + (T... args) + + + T + c_str + cpp/string/basic_string/c_str + + (T... args) + + + T + empty + cpp/string/basic_string/empty + + (T... args) + + + T + cend + cpp/string/basic_string/end + + (T... args) + + + T + substr + cpp/string/basic_string/substr + + (T... args) + + + T + max_size + cpp/string/basic_string/max_size + + (T... args) + + + T + rend + cpp/string/basic_string/rend + + (T... args) + + + T + get_allocator + cpp/string/basic_string/get_allocator + + (T... args) + + + T + clear + cpp/string/basic_string/clear + + (T... args) + + + T + at + cpp/string/basic_string/at + + (T... args) + + + T + swap + cpp/string/basic_string/swap + + (T... args) + + + T + operator[] + cpp/string/basic_string/operator_at + + (T... args) + + + T + length + cpp/string/basic_string/size + + (T... args) + + + + std::remove_all_extents + cpp/types/remove_all_extents + + + std::istrstream + cpp/io/istrstream + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + ~istrstream + cpp/io/istrstream/~istrstream + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + str + cpp/io/istrstream/str + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + std::istrstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + std::istrstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + istrstream + cpp/io/istrstream/istrstream + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + std::istrstream::sentry + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::istrstream::event_callback + cpp/io/ios_base/event_callback + + + std::istrstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::istrstream::sentry + cpp/io/basic_istream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::unary_negate + cpp/utility/functional/unary_negate + + T + operator() + cpp/utility/functional/unary_negate + + (T... args) + + + T + unary_negate + cpp/utility/functional/unary_negate + + (T... args) + + + + std::unordered_multiset + cpp/container/unordered_multiset + + T + max_bucket_count + cpp/container/unordered_multiset/max_bucket_count + + (T... args) + + + T + cbegin + cpp/container/unordered_multiset/begin + + (T... args) + + + T + erase + cpp/container/unordered_multiset/erase + + (T... args) + + + T + insert + cpp/container/unordered_multiset/insert + + (T... args) + + + T + bucket_count + cpp/container/unordered_multiset/bucket_count + + (T... args) + + + T + max_load_factor + cpp/container/unordered_multiset/max_load_factor + + (T... args) + + + T + end + cpp/container/unordered_multiset/end + + (T... args) + + + T + emplace_hint + cpp/container/unordered_multiset/emplace_hint + + (T... args) + + + T + unordered_multiset + cpp/container/unordered_multiset/unordered_multiset + + (T... args) + + + T + end(int) + cpp/container/unordered_multiset/end2 + + (T... args) + + + T + key_eq + cpp/container/unordered_multiset/key_eq + + (T... args) + + + T + hash_function + cpp/container/unordered_multiset/hash_function + + (T... args) + + + T + equal_range + cpp/container/unordered_multiset/equal_range + + (T... args) + + + T + begin + cpp/container/unordered_multiset/begin + + (T... args) + + + T + cbegin(int) + cpp/container/unordered_multiset/begin2 + + (T... args) + + + T + swap + cpp/container/unordered_multiset/swap + + (T... args) + + + T + ~unordered_multiset + cpp/container/unordered_multiset/~unordered_multiset + + (T... args) + + + T + load_factor + cpp/container/unordered_multiset/load_factor + + (T... args) + + + T + size + cpp/container/unordered_multiset/size + + (T... args) + + + T + operator= + cpp/container/unordered_multiset/operator= + + (T... args) + + + T + cend + cpp/container/unordered_multiset/end + + (T... args) + + + T + reserve + cpp/container/unordered_multiset/reserve + + (T... args) + + + T + rehash + cpp/container/unordered_multiset/rehash + + (T... args) + + + T + bucket + cpp/container/unordered_multiset/bucket + + (T... args) + + + T + find + cpp/container/unordered_multiset/find + + (T... args) + + + T + empty + cpp/container/unordered_multiset/empty + + (T... args) + + + T + get_allocator + cpp/container/unordered_multiset/get_allocator + + (T... args) + + + T + max_size + cpp/container/unordered_multiset/max_size + + (T... args) + + + T + cend(int) + cpp/container/unordered_multiset/end2 + + (T... args) + + + T + count + cpp/container/unordered_multiset/count + + (T... args) + + + T + clear + cpp/container/unordered_multiset/clear + + (T... args) + + + T + begin(int) + cpp/container/unordered_multiset/begin2 + + (T... args) + + + T + emplace + cpp/container/unordered_multiset/emplace + + (T... args) + + + T + bucket_size + cpp/container/unordered_multiset/bucket_size + + (T... args) + + + + std::basic_ostream + cpp/io/basic_ostream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + std::basic_ostream::event_callback + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::basic_ostream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + basic_ostream + cpp/io/basic_ostream/basic_ostream + + (T... args) + + + T + ~basic_ostream + cpp/io/basic_ostream/~basic_ostream + + (T... args) + + std::basic_ostream::sentry + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::basic_ostream::event_callback + cpp/io/ios_base/event_callback + + + std::basic_ostream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::basic_ostream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_ostream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + + std::wsregex_iterator + cpp/regex/regex_iterator + + T + wsregex_iterator + cpp/regex/regex_iterator/regex_iterator + + (T... args) + + + T + operator= + cpp/regex/regex_iterator/operator= + + (T... args) + + + T + operator== + cpp/regex/regex_iterator/operator_cmp + + (T... args) + + + T + operator-> + cpp/regex/regex_iterator/operator* + + (T... args) + + + T + operator++ + cpp/regex/regex_iterator/operator_arith + + (T... args) + + + T + operator* + cpp/regex/regex_iterator/operator* + + (T... args) + + + T + operator!= + cpp/regex/regex_iterator/operator_cmp + + (T... args) + + + T + operator++(int) + cpp/regex/regex_iterator/operator_arith + + (T... args) + + + + std::uint_fast16_t + cpp/types/integer + + + std::is_nothrow_assignable + cpp/types/is_assignable + + + std::moneypunct + cpp/locale/moneypunct + + T + do_curr_symbol + cpp/locale/moneypunct/curr_symbol + + (T... args) + + + T + do_decimal_point + cpp/locale/moneypunct/decimal_point + + (T... args) + + + T + thousands_sep + cpp/locale/moneypunct/thousands_sep + + (T... args) + + + T + do_pos_format + cpp/locale/moneypunct/pos_format + + (T... args) + + + T + curr_symbol + cpp/locale/moneypunct/curr_symbol + + (T... args) + + + T + positive_sign + cpp/locale/moneypunct/positive_sign + + (T... args) + + + T + frac_digits + cpp/locale/moneypunct/frac_digits + + (T... args) + + + T + do_negative_sign + cpp/locale/moneypunct/positive_sign + + (T... args) + + + T + ~moneypunct + cpp/locale/moneypunct/~moneypunct + + (T... args) + + + T + pos_format + cpp/locale/moneypunct/pos_format + + (T... args) + + + T + do_thousands_sep + cpp/locale/moneypunct/thousands_sep + + (T... args) + + + T + neg_format + cpp/locale/moneypunct/pos_format + + (T... args) + + + T + negative_sign + cpp/locale/moneypunct/positive_sign + + (T... args) + + + T + grouping + cpp/locale/moneypunct/grouping + + (T... args) + + + T + do_frac_digits + cpp/locale/moneypunct/frac_digits + + (T... args) + + + T + decimal_point + cpp/locale/moneypunct/decimal_point + + (T... args) + + + T + do_neg_format + cpp/locale/moneypunct/pos_format + + (T... args) + + std::moneypunct::string_type + std::moneypunct::pattern + + T + do_positive_sign + cpp/locale/moneypunct/positive_sign + + (T... args) + + std::moneypunct::char_type + + T + moneypunct + cpp/locale/moneypunct/moneypunct + + (T... args) + + + T + do_grouping + cpp/locale/moneypunct/grouping + + (T... args) + + + + std::moneypunct::string_type + cpp/locale/moneypunct + + + std::moneypunct::pattern + cpp/locale/money_base + + + std::moneypunct::char_type + cpp/locale/moneypunct + + + std::type_index + cpp/types/type_index + + T + operator!= + cpp/types/type_index/operator_cmp + + (T... args) + + + T + hash_code + cpp/types/type_index/hash_code + + (T... args) + + + T + operator<= + cpp/types/type_index/operator_cmp + + (T... args) + + + T + operator< + cpp/types/type_index/operator_cmp + + (T... args) + + + T + operator== + cpp/types/type_index/operator_cmp + + (T... args) + + + T + operator>= + cpp/types/type_index/operator_cmp + + (T... args) + + + T + type_index + cpp/types/type_index/type_index + + (T... args) + + + T + name + cpp/types/type_index/name + + (T... args) + + + T + operator> + cpp/types/type_index/operator_cmp + + (T... args) + + + + std::is_standard_layout + cpp/types/is_standard_layout + + + std::timed_mutex + cpp/thread/timed_mutex + + T + unlock + cpp/thread/timed_mutex/unlock + + (T... args) + + + T + native_handle + cpp/thread/timed_mutex/native_handle + + (T... args) + + + T + try_lock_until + cpp/thread/timed_mutex/try_lock_until + + (T... args) + + + T + try_lock_for + cpp/thread/timed_mutex/try_lock_for + + (T... args) + + + T + lock + cpp/thread/timed_mutex/lock + + (T... args) + + + T + try_lock + cpp/thread/timed_mutex/try_lock + + (T... args) + + + T + timed_mutex + cpp/thread/timed_mutex/timed_mutex + + (T... args) + + + + std::bad_exception + cpp/error/bad_exception + + + std::int_fast64_t + cpp/types/integer + + + std::function + cpp/utility/functional/function + + T + operator= + cpp/utility/functional/function/operator= + + (T... args) + + + T + swap + cpp/utility/functional/function/swap + + (T... args) + + + T + assign + cpp/utility/functional/function/assign + + (T... args) + + + T + target + cpp/utility/functional/function/target + + (T... args) + + + T + operator() + cpp/utility/functional/function/operator() + + (T... args) + + + T + target_type + cpp/utility/functional/function/target_type + + (T... args) + + + T + function + cpp/utility/functional/function/function + + (T... args) + + + T + operator bool + cpp/utility/functional/function/operator_bool + + (T... args) + + + T + ~function + cpp/utility/functional/function/~function + + (T... args) + + + + std::bad_cast + cpp/types/bad_cast + + T + bad_cast + cpp/types/bad_cast/bad_cast + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::error_condition + cpp/error/error_condition + + T + error_condition + cpp/error/error_condition/error_condition + + (T... args) + + + T + operator= + cpp/error/error_condition/operator= + + (T... args) + + + T + operator bool + cpp/error/error_condition/operator_bool + + (T... args) + + + T + assign + cpp/error/error_condition/assign + + (T... args) + + + T + value + cpp/error/error_condition/value + + (T... args) + + + T + clear + cpp/error/error_condition/clear + + (T... args) + + + T + message + cpp/error/error_condition/message + + (T... args) + + + T + category + cpp/error/error_condition/category + + (T... args) + + + + std::filebuf + cpp/io/basic_filebuf + + T + eback + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + setp + cpp/io/basic_streambuf/setp + + (T... args) + + + T + pbackfail + cpp/io/basic_streambuf/pbackfail + + (T... args) + + + T + seekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + pbase + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + egptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + underflow + cpp/io/basic_streambuf/underflow + + (T... args) + + + T + setbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + gbump + cpp/io/basic_streambuf/gbump + + (T... args) + + + T + xsgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + is_open + cpp/io/basic_filebuf/is_open + + (T... args) + + + T + sputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + pptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + seekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + pubsync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + pubseekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + filebuf + cpp/io/basic_filebuf/basic_filebuf + + (T... args) + + + T + pbump + cpp/io/basic_streambuf/pbump + + (T... args) + + + T + pubseekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + sputbackc + cpp/io/basic_streambuf/sputbackc + + (T... args) + + + T + in_avail + cpp/io/basic_streambuf/in_avail + + (T... args) + + + T + getloc + cpp/io/basic_streambuf/getloc + + (T... args) + + + T + sungetc + cpp/io/basic_streambuf/sungetc + + (T... args) + + + T + epptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + close + cpp/io/basic_filebuf/close + + (T... args) + + + T + sync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + xsputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + setg + cpp/io/basic_streambuf/setg + + (T... args) + + + T + pubimbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + showmanyc + cpp/io/basic_streambuf/showmanyc + + (T... args) + + + T + open + cpp/io/basic_filebuf/open + + (T... args) + + + T + sgetc + cpp/io/basic_streambuf/sgetc + + (T... args) + + + T + swap + cpp/io/basic_streambuf/swap + + (T... args) + + + T + sputc + cpp/io/basic_streambuf/sputc + + (T... args) + + + T + overflow + cpp/io/basic_streambuf/overflow + + (T... args) + + + T + uflow + cpp/io/basic_streambuf/uflow + + (T... args) + + + T + sgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + sbumpc + cpp/io/basic_streambuf/sbumpc + + (T... args) + + + T + ~filebuf + cpp/io/basic_filebuf/~basic_filebuf + + (T... args) + + + T + operator= + cpp/io/basic_filebuf/operator= + + (T... args) + + + T + pubsetbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + imbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + snextc + cpp/io/basic_streambuf/snextc + + (T... args) + + + T + gptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + + std::int_least16_t + cpp/types/integer + + + std::istreambuf_iterator + cpp/iterator/istreambuf_iterator + + + std::u16string + cpp/string/basic_string + + T + push_back + cpp/string/basic_string/push_back + + (T... args) + + + T + shrink_to_fit + cpp/string/basic_string/shrink_to_fit + + (T... args) + + + T + rfind + cpp/string/basic_string/rfind + + (T... args) + + + T + begin + cpp/string/basic_string/begin + + (T... args) + + + T + erase + cpp/string/basic_string/erase + + (T... args) + + + T + append + cpp/string/basic_string/append + + (T... args) + + + T + data + cpp/string/basic_string/data + + (T... args) + + + T + insert + cpp/string/basic_string/insert + + (T... args) + + + T + assign + cpp/string/basic_string/assign + + (T... args) + + + T + find_first_not_of + cpp/string/basic_string/find_first_not_of + + (T... args) + + + T + back + cpp/string/basic_string/back + + (T... args) + + + T + end + cpp/string/basic_string/end + + (T... args) + + + T + resize + cpp/string/basic_string/resize + + (T... args) + + + T + copy + cpp/string/basic_string/copy + + (T... args) + + + T + find_last_of + cpp/string/basic_string/find_last_of + + (T... args) + + + T + pop_back + cpp/string/basic_string/pop_back + + (T... args) + + + T + replace + cpp/string/basic_string/replace + + (T... args) + + + T + front + cpp/string/basic_string/front + + (T... args) + + + T + substr + cpp/string/basic_string/substr + + (T... args) + + + T + find + cpp/string/basic_string/find + + (T... args) + + + T + compare + cpp/string/basic_string/compare + + (T... args) + + + T + crbegin + cpp/string/basic_string/rbegin + + (T... args) + + + T + cbegin + cpp/string/basic_string/begin + + (T... args) + + + T + find_first_of + cpp/string/basic_string/find_first_of + + (T... args) + + + T + rbegin + cpp/string/basic_string/rbegin + + (T... args) + + + T + crend + cpp/string/basic_string/rend + + (T... args) + + + T + size + cpp/string/basic_string/size + + (T... args) + + + T + operator= + cpp/string/basic_string/operator= + + (T... args) + + + T + find_last_not_of + cpp/string/basic_string/find_last_not_of + + (T... args) + + + T + reserve + cpp/string/basic_string/reserve + + (T... args) + + + T + capacity + cpp/string/basic_string/capacity + + (T... args) + + + T + c_str + cpp/string/basic_string/c_str + + (T... args) + + + T + empty + cpp/string/basic_string/empty + + (T... args) + + + T + cend + cpp/string/basic_string/end + + (T... args) + + + T + u16string + cpp/string/basic_string/basic_string + + (T... args) + + + T + max_size + cpp/string/basic_string/max_size + + (T... args) + + + T + rend + cpp/string/basic_string/rend + + (T... args) + + + T + get_allocator + cpp/string/basic_string/get_allocator + + (T... args) + + + T + clear + cpp/string/basic_string/clear + + (T... args) + + + T + at + cpp/string/basic_string/at + + (T... args) + + + T + swap + cpp/string/basic_string/swap + + (T... args) + + + T + operator[] + cpp/string/basic_string/operator_at + + (T... args) + + + T + length + cpp/string/basic_string/size + + (T... args) + + + + std::is_error_condition_enum + cpp/error/error_condition/is_error_condition_enum + + + std::is_nothrow_destructible + cpp/types/is_destructible + + + std::wiostream + cpp/io/basic_iostream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + std::wiostream::sentry + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + std::wiostream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + wiostream + cpp/io/basic_iostream/basic_iostream + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::wiostream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + ~wiostream + cpp/io/basic_iostream/~basic_iostream + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::wiostream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::wiostream::event_callback + cpp/io/ios_base/event_callback + + + std::wiostream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::allocator_arg_t + cpp/memory/allocator_arg_t + + + std::rel_ops + + + T + operator!= + cpp/utility/rel_ops/operator_cmp + + (T... args) + + + T + operator>= + cpp/utility/rel_ops/operator_cmp + + (T... args) + + + T + operator<= + cpp/utility/rel_ops/operator_cmp + + (T... args) + + + T + operator> + cpp/utility/rel_ops/operator_cmp + + (T... args) + + + + std::uint_least32_t + cpp/types/integer + + + std::collate + cpp/locale/collate + + T + hash + cpp/locale/collate/hash + + (T... args) + + + T + do_hash + cpp/locale/collate/hash + + (T... args) + + + T + collate + cpp/locale/collate/collate + + (T... args) + + std::collate::char_type + + T + ~collate + cpp/locale/collate/~collate + + (T... args) + + + T + do_transform + cpp/locale/collate/transform + + (T... args) + + + T + transform + cpp/locale/collate/transform + + (T... args) + + + T + do_compare + cpp/locale/collate/compare + + (T... args) + + std::collate::string_type + + T + compare + cpp/locale/collate/compare + + (T... args) + + + + std::collate::char_type + cpp/locale/collate + + + std::collate::string_type + cpp/locale/collate + + + std::remove_const + cpp/types/remove_cv + + + std::u32string + cpp/string/basic_string + + T + push_back + cpp/string/basic_string/push_back + + (T... args) + + + T + shrink_to_fit + cpp/string/basic_string/shrink_to_fit + + (T... args) + + + T + rfind + cpp/string/basic_string/rfind + + (T... args) + + + T + begin + cpp/string/basic_string/begin + + (T... args) + + + T + erase + cpp/string/basic_string/erase + + (T... args) + + + T + append + cpp/string/basic_string/append + + (T... args) + + + T + data + cpp/string/basic_string/data + + (T... args) + + + T + insert + cpp/string/basic_string/insert + + (T... args) + + + T + u32string + cpp/string/basic_string/basic_string + + (T... args) + + + T + find_first_not_of + cpp/string/basic_string/find_first_not_of + + (T... args) + + + T + back + cpp/string/basic_string/back + + (T... args) + + + T + end + cpp/string/basic_string/end + + (T... args) + + + T + resize + cpp/string/basic_string/resize + + (T... args) + + + T + copy + cpp/string/basic_string/copy + + (T... args) + + + T + find_last_of + cpp/string/basic_string/find_last_of + + (T... args) + + + T + pop_back + cpp/string/basic_string/pop_back + + (T... args) + + + T + cbegin + cpp/string/basic_string/begin + + (T... args) + + + T + replace + cpp/string/basic_string/replace + + (T... args) + + + T + front + cpp/string/basic_string/front + + (T... args) + + + T + find + cpp/string/basic_string/find + + (T... args) + + + T + compare + cpp/string/basic_string/compare + + (T... args) + + + T + crbegin + cpp/string/basic_string/rbegin + + (T... args) + + + T + size + cpp/string/basic_string/size + + (T... args) + + + T + find_first_of + cpp/string/basic_string/find_first_of + + (T... args) + + + T + rbegin + cpp/string/basic_string/rbegin + + (T... args) + + + T + crend + cpp/string/basic_string/rend + + (T... args) + + + T + assign + cpp/string/basic_string/assign + + (T... args) + + + T + operator= + cpp/string/basic_string/operator= + + (T... args) + + + T + find_last_not_of + cpp/string/basic_string/find_last_not_of + + (T... args) + + + T + reserve + cpp/string/basic_string/reserve + + (T... args) + + + T + capacity + cpp/string/basic_string/capacity + + (T... args) + + + T + c_str + cpp/string/basic_string/c_str + + (T... args) + + + T + empty + cpp/string/basic_string/empty + + (T... args) + + + T + cend + cpp/string/basic_string/end + + (T... args) + + + T + substr + cpp/string/basic_string/substr + + (T... args) + + + T + max_size + cpp/string/basic_string/max_size + + (T... args) + + + T + rend + cpp/string/basic_string/rend + + (T... args) + + + T + get_allocator + cpp/string/basic_string/get_allocator + + (T... args) + + + T + clear + cpp/string/basic_string/clear + + (T... args) + + + T + at + cpp/string/basic_string/at + + (T... args) + + + T + swap + cpp/string/basic_string/swap + + (T... args) + + + T + operator[] + cpp/string/basic_string/operator_at + + (T... args) + + + T + length + cpp/string/basic_string/size + + (T... args) + + + + std::uint_fast32_t + cpp/types/integer + + + std::is_lvalue_reference + cpp/types/is_lvalue_reference + + + std::complex + cpp/numeric/complex + + T + operator= + cpp/numeric/complex/operator= + + (T... args) + + + T + complex + cpp/numeric/complex/complex + + (T... args) + + + T + operator-= + cpp/numeric/complex/operator_arith + + (T... args) + + + T + imag + cpp/numeric/complex/imag + + (T... args) + + + T + operator+= + cpp/numeric/complex/operator_arith + + (T... args) + + + T + operator/= + cpp/numeric/complex/operator_arith + + (T... args) + + + T + operator*= + cpp/numeric/complex/operator_arith + + (T... args) + + + T + real + cpp/numeric/complex/real + + (T... args) + + + + std::ofstream + cpp/io/basic_ofstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + std::ofstream::event_callback + + T + open + cpp/io/basic_ofstream/open + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + close + cpp/io/basic_ofstream/close + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::ofstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + is_open + cpp/io/basic_ofstream/is_open + + (T... args) + + + T + operator= + cpp/io/basic_ofstream/operator= + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + std::ofstream::sentry + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + ofstream + cpp/io/basic_ofstream/basic_ofstream + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::ofstream::event_callback + cpp/io/ios_base/event_callback + + + std::ofstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::ofstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_ostream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + + std::insert_iterator + cpp/iterator/insert_iterator + + + std::bad_array_length + cpp/memory/new/bad_array_length + + T + bad_array_length + cpp/memory/new/bad_array_length + + (T... args) + + + T + what + cpp/memory/new/bad_alloc + + (T... args) + + + + std::this_thread + + + T + yield + cpp/thread/yield + + (T... args) + + + T + sleep_for + cpp/thread/sleep_for + + (T... args) + + + T + sleep_until + cpp/thread/sleep_until + + (T... args) + + + T + get_id + cpp/thread/get_id + + (T... args) + + + + std::is_trivially_copyable + cpp/types/is_trivially_copyable + + + std::basic_istringstream + cpp/io/basic_istringstream + + T + basic_istringstream + cpp/io/basic_istringstream/basic_istringstream + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + str + cpp/io/basic_istringstream/str + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + std::basic_istringstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + std::basic_istringstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + operator= + cpp/io/basic_istringstream/operator= + + (T... args) + + std::basic_istringstream::sentry + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::basic_istringstream::event_callback + cpp/io/ios_base/event_callback + + + std::basic_istringstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::basic_istringstream::sentry + cpp/io/basic_istream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::basic_ifstream + cpp/io/basic_ifstream + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + basic_ifstream + cpp/io/basic_ifstream/basic_ifstream + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + + T + open + cpp/io/basic_ifstream/open + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + std::basic_ifstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + close + cpp/io/basic_ifstream/close + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + std::basic_ifstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + is_open + cpp/io/basic_ifstream/is_open + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + operator= + cpp/io/basic_ifstream/operator= + + (T... args) + + std::basic_ifstream::sentry + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::basic_ifstream::event_callback + cpp/io/ios_base/event_callback + + + std::basic_ifstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::basic_ifstream::sentry + cpp/io/basic_istream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::list + cpp/container/list + + T + pop_front + cpp/container/list/pop_front + + (T... args) + + + T + push_back + cpp/container/list/push_back + + (T... args) + + + T + splice + cpp/container/list/splice + + (T... args) + + + T + crbegin + cpp/container/list/rbegin + + (T... args) + + + T + erase + cpp/container/list/erase + + (T... args) + + + T + emplace_front + cpp/container/list/emplace_front + + (T... args) + + + T + insert + cpp/container/list/insert + + (T... args) + + + T + reverse + cpp/container/list/reverse + + (T... args) + + + T + back + cpp/container/list/back + + (T... args) + + + T + end + cpp/container/list/end + + (T... args) + + + T + remove + cpp/container/list/remove + + (T... args) + + + T + list + cpp/container/list/list + + (T... args) + + + T + emplace_back + cpp/container/list/emplace_back + + (T... args) + + + T + pop_back + cpp/container/list/pop_back + + (T... args) + + + T + cbegin + cpp/container/list/begin + + (T... args) + + + T + front + cpp/container/list/front + + (T... args) + + + T + unique + cpp/container/list/unique + + (T... args) + + + T + size + cpp/container/list/size + + (T... args) + + + T + resize + cpp/container/list/resize + + (T... args) + + + T + push_front + cpp/container/list/push_front + + (T... args) + + + T + rbegin + cpp/container/list/rbegin + + (T... args) + + + T + crend + cpp/container/list/rend + + (T... args) + + + T + assign + cpp/container/list/assign + + (T... args) + + + T + operator= + cpp/container/list/operator= + + (T... args) + + + T + sort + cpp/container/list/sort + + (T... args) + + + T + ~list + cpp/container/list/~list + + (T... args) + + + T + merge + cpp/container/list/merge + + (T... args) + + + T + empty + cpp/container/list/empty + + (T... args) + + + T + remove_if + cpp/container/list/remove + + (T... args) + + + T + cend + cpp/container/list/end + + (T... args) + + + T + swap + cpp/container/list/swap + + (T... args) + + + T + max_size + cpp/container/list/max_size + + (T... args) + + + T + rend + cpp/container/list/rend + + (T... args) + + + T + get_allocator + cpp/container/list/get_allocator + + (T... args) + + + T + clear + cpp/container/list/clear + + (T... args) + + + T + emplace + cpp/container/list/emplace + + (T... args) + + + T + begin + cpp/container/list/begin + + (T... args) + + + + std::minus + cpp/utility/functional/minus + + T + operator() + cpp/utility/functional/minus + + (T... args) + + + + std::map + cpp/container/map + + T + begin + cpp/container/map/begin + + (T... args) + + + T + erase + cpp/container/map/erase + + (T... args) + + + T + insert + cpp/container/map/insert + + (T... args) + + + T + swap + cpp/container/map/swap + + (T... args) + + + T + end + cpp/container/map/end + + (T... args) + + + T + emplace_hint + cpp/container/map/emplace_hint + + (T... args) + + + T + key_comp + cpp/container/map/key_comp + + (T... args) + + std::map::value_compare + + T + cbegin + cpp/container/map/begin + + (T... args) + + + T + count + cpp/container/map/count + + (T... args) + + + T + find + cpp/container/map/find + + (T... args) + + + T + map + cpp/container/map/map + + (T... args) + + + T + crbegin + cpp/container/map/rbegin + + (T... args) + + + T + at + cpp/container/map/at + + (T... args) + + + T + upper_bound + cpp/container/map/upper_bound + + (T... args) + + + T + rbegin + cpp/container/map/rbegin + + (T... args) + + + T + crend + cpp/container/map/rend + + (T... args) + + + T + size + cpp/container/map/size + + (T... args) + + + T + operator= + cpp/container/map/operator= + + (T... args) + + + T + ~map + cpp/container/map/~map + + (T... args) + + + T + value_comp + cpp/container/map/value_comp + + (T... args) + + + T + empty + cpp/container/map/empty + + (T... args) + + + T + lower_bound + cpp/container/map/lower_bound + + (T... args) + + + T + cend + cpp/container/map/end + + (T... args) + + + T + max_size + cpp/container/map/max_size + + (T... args) + + + T + rend + cpp/container/map/rend + + (T... args) + + + T + get_allocator + cpp/container/map/get_allocator + + (T... args) + + + T + clear + cpp/container/map/clear + + (T... args) + + + T + equal_range + cpp/container/map/equal_range + + (T... args) + + + T + emplace + cpp/container/map/emplace + + (T... args) + + + T + operator[] + cpp/container/map/operator_at + + (T... args) + + + + std::map::value_compare + cpp/container/map/value_compare + + + std::linear_congruential_engine + cpp/numeric/random/linear_congruential_engine + + T + discard + cpp/numeric/random/linear_congruential_engine/discard + + (T... args) + + + T + linear_congruential_engine + cpp/numeric/random/linear_congruential_engine/linear_congruential_engine + + (T... args) + + + T + max + cpp/numeric/random/linear_congruential_engine/max + + (T... args) + + + T + operator() + cpp/numeric/random/linear_congruential_engine/operator() + + (T... args) + + + T + seed + cpp/numeric/random/linear_congruential_engine/seed + + (T... args) + + + T + min + cpp/numeric/random/linear_congruential_engine/min + + (T... args) + + + + std::codecvt_utf16 + cpp/locale/codecvt_utf16 + std::codecvt_utf16::extern_type + + T + out + cpp/locale/codecvt/out + + (T... args) + + + T + do_length + cpp/locale/codecvt/length + + (T... args) + + + T + do_unshift + cpp/locale/codecvt/unshift + + (T... args) + + + T + do_encoding + cpp/locale/codecvt/encoding + + (T... args) + + + T + do_in + cpp/locale/codecvt/in + + (T... args) + + + T + unshift + cpp/locale/codecvt/unshift + + (T... args) + + + T + max_length + cpp/locale/codecvt/max_length + + (T... args) + + std::codecvt_utf16::state_type + + T + encoding + cpp/locale/codecvt/encoding + + (T... args) + + + T + always_noconv + cpp/locale/codecvt/always_noconv + + (T... args) + + + T + do_out + cpp/locale/codecvt/out + + (T... args) + + + T + do_max_length + cpp/locale/codecvt/max_length + + (T... args) + + + T + do_always_noconv + cpp/locale/codecvt/always_noconv + + (T... args) + + + T + in + cpp/locale/codecvt/in + + (T... args) + + std::codecvt_utf16::intern_type + + T + length + cpp/locale/codecvt/length + + (T... args) + + + + std::codecvt_utf16::extern_type + cpp/locale/codecvt + + + std::codecvt_utf16::state_type + cpp/locale/codecvt + + + std::codecvt_utf16::intern_type + cpp/locale/codecvt + + + std::cmatch + cpp/regex/match_results + + T + cbegin + cpp/regex/match_results/begin + + (T... args) + + + T + format + cpp/regex/match_results/format + + (T... args) + + + T + size + cpp/regex/match_results/size + + (T... args) + + + T + swap + cpp/regex/match_results/swap + + (T... args) + + + T + position + cpp/regex/match_results/position + + (T... args) + + + T + ~cmatch + cpp/regex/match_results/~match_results + + (T... args) + + + T + prefix + cpp/regex/match_results/prefix + + (T... args) + + + T + str + cpp/regex/match_results/str + + (T... args) + + + T + empty + cpp/regex/match_results/empty + + (T... args) + + + T + suffix + cpp/regex/match_results/suffix + + (T... args) + + + T + get_allocator + cpp/regex/match_results/get_allocator + + (T... args) + + + T + end + cpp/regex/match_results/end + + (T... args) + + + T + max_size + cpp/regex/match_results/max_size + + (T... args) + + + T + cmatch + cpp/regex/match_results/match_results + + (T... args) + + + T + ready + cpp/regex/match_results/ready + + (T... args) + + + T + cend + cpp/regex/match_results/end + + (T... args) + + + T + operator[] + cpp/regex/match_results/operator_at + + (T... args) + + + T + length + cpp/regex/match_results/length + + (T... args) + + + T + begin + cpp/regex/match_results/begin + + (T... args) + + + + std::defer_lock_t + cpp/thread/lock_tag_t + + + std::exception + cpp/error/exception + + T + what + cpp/error/exception/what + + (T... args) + + + T + ~exception + cpp/error/exception/~exception + + (T... args) + + + T + operator= + cpp/error/exception/operator= + + (T... args) + + + T + exception + cpp/error/exception/exception + + (T... args) + + + + std::front_insert_iterator + cpp/iterator/front_insert_iterator + + + std::zetta + cpp/numeric/ratio/ratio + + + std::streambuf + cpp/io/basic_streambuf + + T + pptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + epptr + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + eback + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + setp + cpp/io/basic_streambuf/setp + + (T... args) + + + T + sputbackc + cpp/io/basic_streambuf/sputbackc + + (T... args) + + + T + getloc + cpp/io/basic_streambuf/getloc + + (T... args) + + + T + seekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + imbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + sungetc + cpp/io/basic_streambuf/sungetc + + (T... args) + + + T + sync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + xsputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + pbase + cpp/io/basic_streambuf/pptr + + (T... args) + + + T + sgetc + cpp/io/basic_streambuf/sgetc + + (T... args) + + + T + pubimbue + cpp/io/basic_streambuf/pubimbue + + (T... args) + + + T + showmanyc + cpp/io/basic_streambuf/showmanyc + + (T... args) + + + T + snextc + cpp/io/basic_streambuf/snextc + + (T... args) + + + T + egptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + seekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + T + underflow + cpp/io/basic_streambuf/underflow + + (T... args) + + + T + setbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + gbump + cpp/io/basic_streambuf/gbump + + (T... args) + + + T + in_avail + cpp/io/basic_streambuf/in_avail + + (T... args) + + + T + swap + cpp/io/basic_streambuf/swap + + (T... args) + + + T + pbackfail + cpp/io/basic_streambuf/pbackfail + + (T... args) + + + T + sputc + cpp/io/basic_streambuf/sputc + + (T... args) + + + T + xsgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + uflow + cpp/io/basic_streambuf/uflow + + (T... args) + + + T + overflow + cpp/io/basic_streambuf/overflow + + (T... args) + + + T + sputn + cpp/io/basic_streambuf/sputn + + (T... args) + + + T + sgetn + cpp/io/basic_streambuf/sgetn + + (T... args) + + + T + sbumpc + cpp/io/basic_streambuf/sbumpc + + (T... args) + + + T + ~streambuf + cpp/io/basic_streambuf/~basic_streambuf + + (T... args) + + + T + operator= + cpp/io/basic_streambuf/operator= + + (T... args) + + + T + pbump + cpp/io/basic_streambuf/pbump + + (T... args) + + + T + pubsetbuf + cpp/io/basic_streambuf/pubsetbuf + + (T... args) + + + T + pubsync + cpp/io/basic_streambuf/pubsync + + (T... args) + + + T + pubseekoff + cpp/io/basic_streambuf/pubseekoff + + (T... args) + + + T + setg + cpp/io/basic_streambuf/setg + + (T... args) + + + T + streambuf + cpp/io/basic_streambuf/basic_streambuf + + (T... args) + + + T + gptr + cpp/io/basic_streambuf/gptr + + (T... args) + + + T + pubseekpos + cpp/io/basic_streambuf/pubseekpos + + (T... args) + + + + std::experimental + + + T + make_optional + cpp/experimental/optional/make_optional + + (T... args) + + std::experimental::optional + + + std::experimental::optional + cpp/experimental/optional + + T + operator= + cpp/experimental/optional/operator= + + (T... args) + + + T + operator bool + cpp/experimental/optional/operator_bool + + (T... args) + + + T + optional + cpp/experimental/optional/optional + + (T... args) + + + T + ~optional + cpp/experimental/optional/~optional + + (T... args) + + + T + operator-> + cpp/experimental/optional/operator* + + (T... args) + + + T + value + cpp/experimental/optional/value + + (T... args) + + + T + value_or + cpp/experimental/optional/value_or + + (T... args) + + + T + operator* + cpp/experimental/optional/operator* + + (T... args) + + + T + emplace + cpp/experimental/optional/emplace + + (T... args) + + + T + swap + cpp/experimental/optional/swap + + (T... args) + + + + std::num_put + cpp/locale/num_put + + T + num_put + cpp/locale/num_put/num_put + + (T... args) + + std::num_put::char_type + + T + ~num_put + cpp/locale/num_put/~num_put + + (T... args) + + + T + do_put + cpp/locale/num_put/put + + (T... args) + + + T + put + cpp/locale/num_put/put + + (T... args) + + std::num_put::iter_type + + + std::num_put::char_type + cpp/locale/num_put + + + std::num_put::iter_type + cpp/locale/num_put + + + std::owner_less + cpp/memory/owner_less + + T + operator() + cpp/memory/owner_less + + (T... args) + + + + std::extent + cpp/types/extent + + + std::bad_optional_access + cpp/utility/bad_optional_access + + T + bad_optional_access + cpp/utility/bad_optional_access + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::yotta + cpp/numeric/ratio/ratio + + + std::wcregex_token_iterator + cpp/regex/regex_token_iterator + + T + operator!= + cpp/regex/regex_token_iterator/operator_cmp + + (T... args) + + + T + operator= + cpp/regex/regex_token_iterator/operator= + + (T... args) + + + T + operator== + cpp/regex/regex_token_iterator/operator_cmp + + (T... args) + + + T + operator-> + cpp/regex/regex_token_iterator/operator* + + (T... args) + + + T + operator++ + cpp/regex/regex_token_iterator/operator_arith + + (T... args) + + + T + operator* + cpp/regex/regex_token_iterator/operator* + + (T... args) + + + T + operator++(int) + cpp/regex/regex_token_iterator/operator_arith + + (T... args) + + + T + wcregex_token_iterator + cpp/regex/regex_token_iterator/regex_token_iterator + + (T... args) + + + + std::uint64_t + cpp/types/integer + + + std::messages + cpp/locale/messages + + T + do_get + cpp/locale/messages/get + + (T... args) + + + T + do_close + cpp/locale/messages/close + + (T... args) + + std::messages::char_type + + T + get + cpp/locale/messages/get + + (T... args) + + + T + ~messages + cpp/locale/messages/~messages + + (T... args) + + + T + do_open + cpp/locale/messages/open + + (T... args) + + + T + messages + cpp/locale/messages/messages + + (T... args) + + + T + open + cpp/locale/messages/open + + (T... args) + + std::messages::string_type + std::messages::catalog + + T + close + cpp/locale/messages/close + + (T... args) + + + + std::messages::char_type + cpp/locale/messages + + + std::messages::string_type + cpp/locale/messages + + + std::messages::catalog + cpp/locale/messages_base + + + std::regex_token_iterator + cpp/regex/regex_token_iterator + + T + regex_token_iterator + cpp/regex/regex_token_iterator/regex_token_iterator + + (T... args) + + + T + operator= + cpp/regex/regex_token_iterator/operator= + + (T... args) + + + T + operator== + cpp/regex/regex_token_iterator/operator_cmp + + (T... args) + + + T + operator-> + cpp/regex/regex_token_iterator/operator* + + (T... args) + + + T + operator++ + cpp/regex/regex_token_iterator/operator_arith + + (T... args) + + + T + operator* + cpp/regex/regex_token_iterator/operator* + + (T... args) + + + T + operator!= + cpp/regex/regex_token_iterator/operator_cmp + + (T... args) + + + T + operator++(int) + cpp/regex/regex_token_iterator/operator_arith + + (T... args) + + + + std::move_iterator + cpp/iterator/move_iterator + + + std::messages_base + cpp/locale/messages_base + std::messages_base::catalog + + + std::messages_base::catalog + cpp/locale/messages_base + + + std::istringstream + cpp/io/basic_istringstream + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + str + cpp/io/basic_istringstream/str + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + istringstream + cpp/io/basic_istringstream/basic_istringstream + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + std::istringstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + std::istringstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + operator= + cpp/io/basic_istringstream/operator= + + (T... args) + + std::istringstream::sentry + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::istringstream::event_callback + cpp/io/ios_base/event_callback + + + std::istringstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::istringstream::sentry + cpp/io/basic_istream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::giga + cpp/numeric/ratio/ratio + + + std::integer_sequence + cpp/utility/integer_sequence + + + std::has_virtual_destructor + cpp/types/has_virtual_destructor + + + std::max_align_t + cpp/types/max_align_t + + + std::remove_volatile + cpp/types/remove_cv + + + std::underlying_type + cpp/types/underlying_type + + + std::hecto + cpp/numeric/ratio/ratio + + + std::is_member_object_pointer + cpp/types/is_member_object_pointer + + + std::exception_ptr + cpp/error/exception_ptr + + + std::nested_exception + cpp/error/nested_exception + + T + operator= + cpp/error/nested_exception/operator= + + (T... args) + + + T + ~nested_exception + cpp/error/nested_exception/~nested_exception + + (T... args) + + + T + rethrow_nested + cpp/error/nested_exception/rethrow_nested + + (T... args) + + + T + nested_exception + cpp/error/nested_exception/nested_exception + + (T... args) + + + T + nested_ptr + cpp/error/nested_exception/nested_ptr + + (T... args) + + + + std::random_access_iterator_tag + cpp/iterator/iterator_tags + + + std::ctype + cpp/locale/ctype + + T + do_toupper + cpp/locale/ctype/toupper + + (T... args) + + + T + toupper + cpp/locale/ctype/toupper + + (T... args) + + + T + scan_is + cpp/locale/ctype/scan_is + + (T... args) + + + T + narrow + cpp/locale/ctype/narrow + + (T... args) + + + T + ~ctype + cpp/locale/ctype/~ctype + + (T... args) + + + T + do_narrow + cpp/locale/ctype/narrow + + (T... args) + + + T + widen + cpp/locale/ctype/widen + + (T... args) + + + T + is + cpp/locale/ctype/is + + (T... args) + + + T + do_scan_is + cpp/locale/ctype/scan_is + + (T... args) + + + T + tolower + cpp/locale/ctype/tolower + + (T... args) + + + T + do_is + cpp/locale/ctype/is + + (T... args) + + + T + do_tolower + cpp/locale/ctype/tolower + + (T... args) + + std::ctype::mask + + T + do_widen + cpp/locale/ctype/widen + + (T... args) + + + T + ctype + cpp/locale/ctype/ctype + + (T... args) + + + + std::ctype::mask + cpp/locale/ctype_base + + + std::time_t + cpp/chrono/c/time_t + + + std::knuth_b + cpp/numeric/random/shuffle_order_engine + + T + discard + cpp/numeric/random/shuffle_order_engine/discard + + (T... args) + + + T + max + cpp/numeric/random/shuffle_order_engine/max + + (T... args) + + + T + knuth_b + cpp/numeric/random/shuffle_order_engine/shuffle_order_engine + + (T... args) + + + T + operator() + cpp/numeric/random/shuffle_order_engine/operator() + + (T... args) + + + T + base + cpp/numeric/random/shuffle_order_engine/base + + (T... args) + + + T + seed + cpp/numeric/random/shuffle_order_engine/seed + + (T... args) + + + T + min + cpp/numeric/random/shuffle_order_engine/min + + (T... args) + + + + std::auto_ptr + cpp/memory/auto_ptr + + T + release + cpp/memory/auto_ptr/release + + (T... args) + + + T + operator* + cpp/memory/auto_ptr/operator* + + (T... args) + + + T + operator auto_ptr<Y> + cpp/memory/auto_ptr/operator_auto_ptr + + (T... args) + + + T + reset + cpp/memory/auto_ptr/reset + + (T... args) + + + T + operator-> + cpp/memory/auto_ptr/operator* + + (T... args) + + + T + operator= + cpp/memory/auto_ptr/operator= + + (T... args) + + + T + auto_ptr + cpp/memory/auto_ptr/auto_ptr + + (T... args) + + + T + ~auto_ptr + cpp/memory/auto_ptr/~auto_ptr + + (T... args) + + + T + get + cpp/memory/auto_ptr/get + + (T... args) + + + + std::minstd_rand0 + cpp/numeric/random/linear_congruential_engine + + T + discard + cpp/numeric/random/linear_congruential_engine/discard + + (T... args) + + + T + max + cpp/numeric/random/linear_congruential_engine/max + + (T... args) + + + T + operator() + cpp/numeric/random/linear_congruential_engine/operator() + + (T... args) + + + T + seed + cpp/numeric/random/linear_congruential_engine/seed + + (T... args) + + + T + min + cpp/numeric/random/linear_congruential_engine/min + + (T... args) + + + T + minstd_rand0 + cpp/numeric/random/linear_congruential_engine/linear_congruential_engine + + (T... args) + + + + std::sregex_token_iterator + cpp/regex/regex_token_iterator + + T + operator!= + cpp/regex/regex_token_iterator/operator_cmp + + (T... args) + + + T + operator= + cpp/regex/regex_token_iterator/operator= + + (T... args) + + + T + sregex_token_iterator + cpp/regex/regex_token_iterator/regex_token_iterator + + (T... args) + + + T + operator== + cpp/regex/regex_token_iterator/operator_cmp + + (T... args) + + + T + operator-> + cpp/regex/regex_token_iterator/operator* + + (T... args) + + + T + operator++ + cpp/regex/regex_token_iterator/operator_arith + + (T... args) + + + T + operator* + cpp/regex/regex_token_iterator/operator* + + (T... args) + + + T + operator++(int) + cpp/regex/regex_token_iterator/operator_arith + + (T... args) + + + + std::logical_not + cpp/utility/functional/logical_not + + T + operator() + cpp/utility/functional/logical_not + + (T... args) + + + + std::fpos_t + cpp/io/c + + + std::istream + cpp/io/basic_istream + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + ~istream + cpp/io/basic_istream/~basic_istream + + (T... args) + + + T + istream + cpp/io/basic_istream/basic_istream + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + std::istream::event_callback + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::istream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + std::istream::sentry + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::istream::event_callback + cpp/io/ios_base/event_callback + + + std::istream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::istream::sentry + cpp/io/basic_istream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::seed_seq + cpp/numeric/random/seed_seq + + T + generate + cpp/numeric/random/seed_seq/generate + + (T... args) + + + T + param + cpp/numeric/random/seed_seq/param + + (T... args) + + + T + size + cpp/numeric/random/seed_seq/size + + (T... args) + + + T + seed_seq + cpp/numeric/random/seed_seq/seed_seq + + (T... args) + + + + std::default_delete + cpp/memory/default_delete + + T + default_delete + cpp/memory/default_delete + + (T... args) + + + T + operator() + cpp/memory/default_delete + + (T... args) + + + + std::femto + cpp/numeric/ratio/ratio + + + std::clock_t + cpp/chrono/c/clock_t + + + std::true_type + cpp/types/integral_constant + + + std::mbstate_t + cpp/string/multibyte/mbstate_t + + + std::ostrstream + cpp/io/ostrstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + str + cpp/io/ostrstream/str + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + std::ostrstream::event_callback + + T + pcount + cpp/io/ostrstream/pcount + + (T... args) + + + T + ostrstream + cpp/io/ostrstream/ostrstream + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::ostrstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + freeze + cpp/io/ostrstream/freeze + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + ~ostrstream + cpp/io/ostrstream/~ostrstream + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + std::ostrstream::sentry + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::ostrstream::event_callback + cpp/io/ios_base/event_callback + + + std::ostrstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::ostrstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_ostream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + + std::gamma_distribution + cpp/numeric/random/gamma_distribution + + T + gamma_distribution + cpp/numeric/random/gamma_distribution/gamma_distribution + + (T... args) + + + T + max + cpp/numeric/random/gamma_distribution/max + + (T... args) + + + T + operator() + cpp/numeric/random/gamma_distribution/operator() + + (T... args) + + + T + reset + cpp/numeric/random/gamma_distribution/reset + + (T... args) + + + T + alpha + cpp/numeric/random/gamma_distribution/params + + (T... args) + + + T + beta + cpp/numeric/random/gamma_distribution/params + + (T... args) + + + T + param + cpp/numeric/random/gamma_distribution/param + + (T... args) + + + T + min + cpp/numeric/random/gamma_distribution/min + + (T... args) + + + + std::bad_weak_ptr + cpp/memory/bad_weak_ptr + + T + bad_weak_ptr + cpp/memory/bad_weak_ptr/bad_weak_ptr + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::output_iterator_tag + cpp/iterator/iterator_tags + + + std::micro + cpp/numeric/ratio/ratio + + + std::is_trivial + cpp/types/is_trivial + + + std::packaged_task + cpp/thread/packaged_task + + T + operator= + cpp/thread/packaged_task/operator= + + (T... args) + + + T + swap + cpp/thread/packaged_task/swap + + (T... args) + + + T + reset + cpp/thread/packaged_task/reset + + (T... args) + + + T + packaged_task + cpp/thread/packaged_task/packaged_task + + (T... args) + + + T + make_ready_at_thread_exit + cpp/thread/packaged_task/make_ready_at_thread_exit + + (T... args) + + + T + operator() + cpp/thread/packaged_task/operator() + + (T... args) + + + T + get_future + cpp/thread/packaged_task/get_future + + (T... args) + + + T + valid + cpp/thread/packaged_task/valid + + (T... args) + + + T + ~packaged_task + cpp/thread/packaged_task/~packaged_task + + (T... args) + + + + std::unordered_set + cpp/container/unordered_set + + T + max_bucket_count + cpp/container/unordered_set/max_bucket_count + + (T... args) + + + T + cbegin + cpp/container/unordered_set/begin + + (T... args) + + + T + erase + cpp/container/unordered_set/erase + + (T... args) + + + T + insert + cpp/container/unordered_set/insert + + (T... args) + + + T + bucket_count + cpp/container/unordered_set/bucket_count + + (T... args) + + + T + max_load_factor + cpp/container/unordered_set/max_load_factor + + (T... args) + + + T + end + cpp/container/unordered_set/end + + (T... args) + + + T + emplace_hint + cpp/container/unordered_set/emplace_hint + + (T... args) + + + T + end(int) + cpp/container/unordered_set/end2 + + (T... args) + + + T + ~unordered_set + cpp/container/unordered_set/~unordered_set + + (T... args) + + + T + key_eq + cpp/container/unordered_set/key_eq + + (T... args) + + + T + hash_function + cpp/container/unordered_set/hash_function + + (T... args) + + + T + find + cpp/container/unordered_set/find + + (T... args) + + + T + clear + cpp/container/unordered_set/clear + + (T... args) + + + T + begin + cpp/container/unordered_set/begin + + (T... args) + + + T + cbegin(int) + cpp/container/unordered_set/begin2 + + (T... args) + + + T + swap + cpp/container/unordered_set/swap + + (T... args) + + + T + begin(int) + cpp/container/unordered_set/begin2 + + (T... args) + + + T + load_factor + cpp/container/unordered_set/load_factor + + (T... args) + + + T + size + cpp/container/unordered_set/size + + (T... args) + + + T + operator= + cpp/container/unordered_set/operator= + + (T... args) + + + T + cend + cpp/container/unordered_set/end + + (T... args) + + + T + reserve + cpp/container/unordered_set/reserve + + (T... args) + + + T + rehash + cpp/container/unordered_set/rehash + + (T... args) + + + T + bucket + cpp/container/unordered_set/bucket + + (T... args) + + + T + empty + cpp/container/unordered_set/empty + + (T... args) + + + T + get_allocator + cpp/container/unordered_set/get_allocator + + (T... args) + + + T + max_size + cpp/container/unordered_set/max_size + + (T... args) + + + T + cend(int) + cpp/container/unordered_set/end2 + + (T... args) + + + T + count + cpp/container/unordered_set/count + + (T... args) + + + T + unordered_set + cpp/container/unordered_set/unordered_set + + (T... args) + + + T + equal_range + cpp/container/unordered_set/equal_range + + (T... args) + + + T + emplace + cpp/container/unordered_set/emplace + + (T... args) + + + T + bucket_size + cpp/container/unordered_set/bucket_size + + (T... args) + + + + std::is_volatile + cpp/types/is_volatile + + + std::wfstream + cpp/io/basic_fstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + open + cpp/io/basic_fstream/open + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + std::wfstream::sentry + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + wfstream + cpp/io/basic_fstream/basic_fstream + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + std::wfstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + close + cpp/io/basic_fstream/close + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::wfstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + is_open + cpp/io/basic_fstream/is_open + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + operator= + cpp/io/basic_fstream/operator= + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::wfstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::wfstream::event_callback + cpp/io/ios_base/event_callback + + + std::wfstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::multimap + cpp/container/multimap + + T + multimap + cpp/container/multimap/multimap + + (T... args) + + + T + begin + cpp/container/multimap/begin + + (T... args) + + + T + erase + cpp/container/multimap/erase + + (T... args) + + + T + insert + cpp/container/multimap/insert + + (T... args) + + + T + swap + cpp/container/multimap/swap + + (T... args) + + + T + end + cpp/container/multimap/end + + (T... args) + + + T + ~multimap + cpp/container/multimap/~multimap + + (T... args) + + + T + emplace_hint + cpp/container/multimap/emplace_hint + + (T... args) + + + T + key_comp + cpp/container/multimap/key_comp + + (T... args) + + std::multimap::value_compare + + T + cbegin + cpp/container/multimap/begin + + (T... args) + + + T + count + cpp/container/multimap/count + + (T... args) + + + T + find + cpp/container/multimap/find + + (T... args) + + + T + crbegin + cpp/container/multimap/rbegin + + (T... args) + + + T + upper_bound + cpp/container/multimap/upper_bound + + (T... args) + + + T + rbegin + cpp/container/multimap/rbegin + + (T... args) + + + T + crend + cpp/container/multimap/rend + + (T... args) + + + T + size + cpp/container/multimap/size + + (T... args) + + + T + operator= + cpp/container/multimap/operator= + + (T... args) + + + T + value_comp + cpp/container/multimap/value_comp + + (T... args) + + + T + empty + cpp/container/multimap/empty + + (T... args) + + + T + lower_bound + cpp/container/multimap/lower_bound + + (T... args) + + + T + cend + cpp/container/multimap/end + + (T... args) + + + T + max_size + cpp/container/multimap/max_size + + (T... args) + + + T + rend + cpp/container/multimap/rend + + (T... args) + + + T + get_allocator + cpp/container/multimap/get_allocator + + (T... args) + + + T + clear + cpp/container/multimap/clear + + (T... args) + + + T + equal_range + cpp/container/multimap/equal_range + + (T... args) + + + T + emplace + cpp/container/multimap/emplace + + (T... args) + + + + std::multimap::value_compare + cpp/container/multimap/value_compare + + + std::atomic_flag + cpp/atomic/atomic_flag + + T + operator= + cpp/atomic/atomic_flag/operator= + + (T... args) + + + T + clear + cpp/atomic/atomic_flag/clear + + (T... args) + + + T + atomic_flag + cpp/atomic/atomic_flag/atomic_flag + + (T... args) + + + T + test_and_set + cpp/atomic/atomic_flag/test_and_set + + (T... args) + + + + std::numpunct_byname + cpp/locale/numpunct_byname + + T + grouping + cpp/locale/numpunct/grouping + + (T... args) + + + T + do_decimal_point + cpp/locale/numpunct/decimal_point + + (T... args) + + + T + thousands_sep + cpp/locale/numpunct/thousands_sep + + (T... args) + + + T + falsename + cpp/locale/numpunct/truefalsename + + (T... args) + + + T + do_falsename + cpp/locale/numpunct/truefalsename + + (T... args) + + std::numpunct_byname::string_type + + T + numpunct_byname + cpp/locale/numpunct_byname + + (T... args) + + + T + truename + cpp/locale/numpunct/truefalsename + + (T... args) + + std::numpunct_byname::char_type + + T + do_truename + cpp/locale/numpunct/truefalsename + + (T... args) + + + T + do_grouping + cpp/locale/numpunct/grouping + + (T... args) + + + T + decimal_point + cpp/locale/numpunct/decimal_point + + (T... args) + + + T + do_thousands_sep + cpp/locale/numpunct/thousands_sep + + (T... args) + + + T + ~numpunct_byname + cpp/locale/numpunct_byname + + (T... args) + + + + std::numpunct_byname::string_type + cpp/locale/numpunct + + + std::numpunct_byname::char_type + cpp/locale/numpunct + + + std::binomial_distribution + cpp/numeric/random/binomial_distribution + + T + t + cpp/numeric/random/binomial_distribution/params + + (T... args) + + + T + binomial_distribution + cpp/numeric/random/binomial_distribution/binomial_distribution + + (T... args) + + + T + reset + cpp/numeric/random/binomial_distribution/reset + + (T... args) + + + T + max + cpp/numeric/random/binomial_distribution/max + + (T... args) + + + T + p + cpp/numeric/random/binomial_distribution/params + + (T... args) + + + T + min + cpp/numeric/random/binomial_distribution/min + + (T... args) + + + T + param + cpp/numeric/random/binomial_distribution/param + + (T... args) + + + + std::basic_iostream + cpp/io/basic_iostream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + ~basic_iostream + cpp/io/basic_iostream/~basic_iostream + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + std::basic_iostream::sentry + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + std::basic_iostream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + basic_iostream + cpp/io/basic_iostream/basic_iostream + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::basic_iostream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::basic_iostream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::basic_iostream::event_callback + cpp/io/ios_base/event_callback + + + std::basic_iostream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::wofstream + cpp/io/basic_ofstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + std::wofstream::event_callback + + T + open + cpp/io/basic_ofstream/open + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + wofstream + cpp/io/basic_ofstream/basic_ofstream + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + close + cpp/io/basic_ofstream/close + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::wofstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + is_open + cpp/io/basic_ofstream/is_open + + (T... args) + + + T + operator= + cpp/io/basic_ofstream/operator= + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + std::wofstream::sentry + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::wofstream::event_callback + cpp/io/ios_base/event_callback + + + std::wofstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::wofstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_ostream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_ostream/sentry + + (T... args) + + + + std::fpos + cpp/io/fpos + + T + state + cpp/io/fpos/state + + (T... args) + + + + std::underflow_error + cpp/error/underflow_error + + T + underflow_error + cpp/error/underflow_error + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::cauchy_distribution + cpp/numeric/random/cauchy_distribution + + T + min + cpp/numeric/random/cauchy_distribution/min + + (T... args) + + + T + reset + cpp/numeric/random/cauchy_distribution/reset + + (T... args) + + + T + a + cpp/numeric/random/cauchy_distribution/params + + (T... args) + + + T + max + cpp/numeric/random/cauchy_distribution/max + + (T... args) + + + T + operator() + cpp/numeric/random/cauchy_distribution/operator() + + (T... args) + + + T + param + cpp/numeric/random/cauchy_distribution/param + + (T... args) + + + T + cauchy_distribution + cpp/numeric/random/cauchy_distribution/cauchy_distribution + + (T... args) + + + T + b + cpp/numeric/random/cauchy_distribution/params + + (T... args) + + + + std::is_trivially_copy_constructible + cpp/types/is_copy_constructible + + + std::conditional + cpp/types/conditional + + + std::is_pod + cpp/types/is_pod + + + std::int_least8_t + cpp/types/integer + + + std::streamoff + cpp/io/streamoff + + + std::is_move_assignable + cpp/types/is_move_assignable + + + std::int_least32_t + cpp/types/integer + + + std::wstringstream + cpp/io/basic_stringstream + + T + seekp + cpp/io/basic_ostream/seekp + + (T... args) + + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + str + cpp/io/basic_stringstream/str + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + tellp + cpp/io/basic_ostream/tellp + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + std::wstringstream::sentry + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + operator<< + cpp/io/basic_ostream/operator_ltlt + + (T... args) + + std::wstringstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + write + cpp/io/basic_ostream/write + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + std::wstringstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + flush + cpp/io/basic_ostream/flush + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + operator= + cpp/io/basic_stringstream/operator= + + (T... args) + + + T + wstringstream + cpp/io/basic_stringstream/basic_stringstream + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + put + cpp/io/basic_ostream/put + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::wstringstream::sentry + cpp/io/basic_ostream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::wstringstream::event_callback + cpp/io/ios_base/event_callback + + + std::wstringstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::subtract_with_carry_engine + cpp/numeric/random/subtract_with_carry_engine + + T + discard + cpp/numeric/random/subtract_with_carry_engine/discard + + (T... args) + + + T + subtract_with_carry_engine + cpp/numeric/random/subtract_with_carry_engine/subtract_with_carry_engine + + (T... args) + + + T + max + cpp/numeric/random/subtract_with_carry_engine/max + + (T... args) + + + T + operator() + cpp/numeric/random/subtract_with_carry_engine/operator() + + (T... args) + + + T + seed + cpp/numeric/random/subtract_with_carry_engine/seed + + (T... args) + + + T + min + cpp/numeric/random/subtract_with_carry_engine/min + + (T... args) + + + + std::regex_error + cpp/regex/regex_error + + T + code + cpp/regex/regex_error/code + + (T... args) + + + T + regex_error + cpp/regex/regex_error/regex_error + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::is_constructible + cpp/types/is_constructible + + + std::piecewise_construct_t + cpp/utility/piecewise_construct_t + + + std::mutex + cpp/thread/mutex + + T + mutex + cpp/thread/mutex/mutex + + (T... args) + + + T + unlock + cpp/thread/mutex/unlock + + (T... args) + + + T + lock + cpp/thread/mutex/lock + + (T... args) + + + T + try_lock + cpp/thread/mutex/try_lock + + (T... args) + + + T + native_handle + cpp/thread/mutex/native_handle + + (T... args) + + + + std::system_error + cpp/error/system_error + + T + code + cpp/error/system_error/code + + (T... args) + + + T + system_error + cpp/error/system_error/system_error + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::wistringstream + cpp/io/basic_istringstream + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + str + cpp/io/basic_istringstream/str + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + wistringstream + cpp/io/basic_istringstream/basic_istringstream + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + std::wistringstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + std::wistringstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + operator= + cpp/io/basic_istringstream/operator= + + (T... args) + + std::wistringstream::sentry + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::wistringstream::event_callback + cpp/io/ios_base/event_callback + + + std::wistringstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::wistringstream::sentry + cpp/io/basic_istream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::is_floating_point + cpp/types/is_floating_point + + + std::ratio_not_equal + cpp/numeric/ratio/ratio_not_equal + + + std::ratio_multiply + cpp/numeric/ratio/ratio_multiply + + + std::result_of + cpp/types/result_of + + + std::is_fundamental + cpp/types/is_fundamental + + + std::ifstream + cpp/io/basic_ifstream + + T + setstate + cpp/io/basic_ios/setstate + + (T... args) + + + T + getloc + cpp/io/ios_base/getloc + + (T... args) + + + T + precision + cpp/io/ios_base/precision + + (T... args) + + + T + flags + cpp/io/ios_base/flags + + (T... args) + + + T + widen + cpp/io/basic_ios/widen + + (T... args) + + + T + readsome + cpp/io/basic_istream/readsome + + (T... args) + + + T + fill + cpp/io/basic_ios/fill + + (T... args) + + + T + setf + cpp/io/ios_base/setf + + (T... args) + + + T + tie + cpp/io/basic_ios/tie + + (T... args) + + + T + open + cpp/io/basic_ifstream/open + + (T... args) + + + T + operator bool + cpp/io/basic_ios/operator_bool + + (T... args) + + + T + copyfmt + cpp/io/basic_ios/copyfmt + + (T... args) + + + T + sync_with_stdio + cpp/io/ios_base/sync_with_stdio + + (T... args) + + + T + gcount + cpp/io/basic_istream/gcount + + (T... args) + + + T + get + cpp/io/basic_istream/get + + (T... args) + + + T + xalloc + cpp/io/ios_base/xalloc + + (T... args) + + + T + read + cpp/io/basic_istream/read + + (T... args) + + + T + getline + cpp/io/basic_istream/getline + + (T... args) + + + T + exceptions + cpp/io/basic_ios/exceptions + + (T... args) + + + T + iword + cpp/io/ios_base/iword + + (T... args) + + + T + unget + cpp/io/basic_istream/unget + + (T... args) + + std::ifstream::event_callback + + T + narrow + cpp/io/basic_ios/narrow + + (T... args) + + + T + ifstream + cpp/io/basic_ifstream/basic_ifstream + + (T... args) + + + T + good + cpp/io/basic_ios/good + + (T... args) + + + T + operator! + cpp/io/basic_ios/operator! + + (T... args) + + + T + close + cpp/io/basic_ifstream/close + + (T... args) + + + T + sync + cpp/io/basic_istream/sync + + (T... args) + + + T + putback + cpp/io/basic_istream/putback + + (T... args) + + + T + ignore + cpp/io/basic_istream/ignore + + (T... args) + + + T + unsetf + cpp/io/ios_base/unsetf + + (T... args) + + + T + width + cpp/io/ios_base/width + + (T... args) + + + T + rdstate + cpp/io/basic_ios/rdstate + + (T... args) + + + T + seekg + cpp/io/basic_istream/seekg + + (T... args) + + std::ifstream::failure + + T + move + cpp/io/basic_ios/move + + (T... args) + + + T + eof + cpp/io/basic_ios/eof + + (T... args) + + + T + register_callback + cpp/io/ios_base/register_callback + + (T... args) + + + T + pword + cpp/io/ios_base/pword + + (T... args) + + + T + swap + cpp/io/basic_ios/swap + + (T... args) + + + T + tellg + cpp/io/basic_istream/tellg + + (T... args) + + + T + operator>> + cpp/io/basic_istream/operator_gtgt + + (T... args) + + + T + set_rdbuf + cpp/io/basic_ios/set_rdbuf + + (T... args) + + + T + fail + cpp/io/basic_ios/fail + + (T... args) + + + T + is_open + cpp/io/basic_ifstream/is_open + + (T... args) + + + T + peek + cpp/io/basic_istream/peek + + (T... args) + + + T + operator= + cpp/io/basic_ifstream/operator= + + (T... args) + + std::ifstream::sentry + + T + rdbuf + cpp/io/basic_ios/rdbuf + + (T... args) + + + T + imbue + cpp/io/basic_ios/imbue + + (T... args) + + + T + bad + cpp/io/basic_ios/bad + + (T... args) + + + T + clear + cpp/io/basic_ios/clear + + (T... args) + + + T + init + cpp/io/basic_ios/init + + (T... args) + + + + std::ifstream::event_callback + cpp/io/ios_base/event_callback + + + std::ifstream::failure + cpp/io/ios_base/failure + + T + failure + cpp/io/ios_base/failure + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::ifstream::sentry + cpp/io/basic_istream/sentry + + T + ~sentry + cpp/io/basic_istream/sentry + + (T... args) + + + T + operator bool + cpp/io/basic_istream/sentry + + (T... args) + + + T + sentry + cpp/io/basic_istream/sentry + + (T... args) + + + + std::u32streampos + cpp/io/fpos + + T + state + cpp/io/fpos/state + + (T... args) + + + + std::length_error + cpp/error/length_error + + T + length_error + cpp/error/length_error + + (T... args) + + + T + what + cpp/error/exception/what + + (T... args) + + + + std::sub_match + cpp/regex/sub_match + + T + operator string_type + cpp/regex/sub_match/str + + (T... args) + + + T + sub_match + cpp/regex/sub_match/sub_match + + (T... args) + + + T + str + cpp/regex/sub_match/str + + (T... args) + + + T + length + cpp/regex/sub_match/length + + (T... args) + + + T + compare + cpp/regex/sub_match/compare + + (T... args) + + + + std::common_type + cpp/types/common_type + + + std::shared_timed_mutex + cpp/thread/shared_timed_mutex + + T + unlock + cpp/thread/shared_timed_mutex/unlock + + (T... args) + + + T + unlock_shared + cpp/thread/shared_timed_mutex/unlock_shared + + (T... args) + + + T + try_lock_until + cpp/thread/shared_timed_mutex/try_lock_until + + (T... args) + + + T + try_lock_for + cpp/thread/shared_timed_mutex/try_lock_for + + (T... args) + + + T + try_lock_shared_until + cpp/thread/shared_timed_mutex/try_lock_shared_until + + (T... args) + + + T + shared_timed_mutex + cpp/thread/shared_timed_mutex/shared_timed_mutex + + (T... args) + + + T + lock_shared + cpp/thread/shared_timed_mutex/lock_shared + + (T... args) + + + T + lock + cpp/thread/shared_timed_mutex/lock + + (T... args) + + + T + try_lock + cpp/thread/shared_timed_mutex/try_lock + + (T... args) + + + T + try_lock_shared + cpp/thread/shared_timed_mutex/try_lock_shared + + (T... args) + + + T + try_lock_shared_for + cpp/thread/shared_timed_mutex/try_lock_shared_for + + (T... args) + + + + std::array + cpp/container/array + + T + max_size + cpp/container/array/max_size + + (T... args) + + + T + rbegin + cpp/container/array/rbegin + + (T... args) + + + T + crend + cpp/container/array/rend + + (T... args) + + + T + crbegin + cpp/container/array/rbegin + + (T... args) + + + T + swap + cpp/container/array/swap + + (T... args) + + + T + data + cpp/container/array/data + + (T... args) + + + T + back + cpp/container/array/back + + (T... args) + + + T + end + cpp/container/array/end + + (T... args) + + + T + fill + cpp/container/array/fill + + (T... args) + + + T + empty + cpp/container/array/empty + + (T... args) + + + T + cend + cpp/container/array/end + + (T... args) + + + T + size + cpp/container/array/size + + (T... args) + + + T + cbegin + cpp/container/array/begin + + (T... args) + + + T + rend + cpp/container/array/rend + + (T... args) + + + T + front + cpp/container/array/front + + (T... args) + + + T + at + cpp/container/array/at + + (T... args) + + + T + operator[] + cpp/container/array/operator_at + + (T... args) + + + T + begin + cpp/container/array/begin + + (T... args) + + + + std::random_device + cpp/numeric/random/random_device + + T + operator() + cpp/numeric/random/random_device/operator() + + (T... args) + + + T + random_device + cpp/numeric/random/random_device/random_device + + (T... args) + + + T + entropy + cpp/numeric/random/random_device/entropy + + (T... args) + + + T + min + cpp/numeric/random/random_device/min + + (T... args) + + + T + max + cpp/numeric/random/random_device/max + + (T... args) + + + + std::default_random_engine + cpp/numeric/random + + + std::raw_storage_iterator + cpp/memory/raw_storage_iterator + + T + operator= + cpp/memory/raw_storage_iterator/operator= + + (T... args) + + + T + raw_storage_iterator + cpp/memory/raw_storage_iterator/raw_storage_iterator + + (T... args) + + + T + operator* + cpp/memory/raw_storage_iterator/operator* + + (T... args) + + + T + operator++ + cpp/memory/raw_storage_iterator/operator_arith + + (T... args) + + + + std::is_convertible + cpp/types/is_convertible + + + std::uint16_t + cpp/types/integer + + + std::is_array + cpp/types/is_array + + + std::mega + cpp/numeric/ratio/ratio + + + std::numpunct + cpp/locale/numpunct + + T + grouping + cpp/locale/numpunct/grouping + + (T... args) + + + T + do_decimal_point + cpp/locale/numpunct/decimal_point + + (T... args) + + + T + thousands_sep + cpp/locale/numpunct/thousands_sep + + (T... args) + + + T + numpunct + cpp/locale/numpunct/numpunct + + (T... args) + + + T + do_falsename + cpp/locale/numpunct/truefalsename + + (T... args) + + std::numpunct::string_type + + T + do_grouping + cpp/locale/numpunct/grouping + + (T... args) + + + T + truename + cpp/locale/numpunct/truefalsename + + (T... args) + + std::numpunct::char_type + + T + falsename + cpp/locale/numpunct/truefalsename + + (T... args) + + + T + do_truename + cpp/locale/numpunct/truefalsename + + (T... args) + + + T + ~numpunct + cpp/locale/numpunct/~numpunct + + (T... args) + + + T + decimal_point + cpp/locale/numpunct/decimal_point + + (T... args) + + + T + do_thousands_sep + cpp/locale/numpunct/thousands_sep + + (T... args) + + + + std::numpunct::string_type + cpp/locale/numpunct + + + std::numpunct::char_type + cpp/locale/numpunct + + + std::money_put + cpp/locale/money_put + std::money_put::char_type + std::money_put::pattern + + T + do_put + cpp/locale/money_put/put + + (T... args) + + + T + money_put + cpp/locale/money_put/money_put + + (T... args) + + + T + ~money_put + cpp/locale/money_put/~money_put + + (T... args) + + + T + put + cpp/locale/money_put/put + + (T... args) + + std::money_put::string_type + std::money_put::iter_type + + + std::money_put::char_type + cpp/locale/money_put + + + std::money_put::pattern + cpp/locale/money_base + + + std::money_put::string_type + cpp/locale/money_put + + + std::money_put::iter_type + cpp/locale/money_put + + + std::new_handler + cpp/memory/new/new_handler + + + std::is_member_function_pointer + cpp/types/is_member_function_pointer + + + va_list + cpp/utility/variadic/va_list + + diff --git a/dynamic_programming/0-1 Knapsack.cpp b/dynamic_programming/0-1 Knapsack.cpp deleted file mode 100644 index 9348372b210..00000000000 --- a/dynamic_programming/0-1 Knapsack.cpp +++ /dev/null @@ -1,71 +0,0 @@ -//0-1 Knapsack problem - Dynamic programming -//#include -#include -using namespace std; - -//void Print(int res[20][20], int i, int j, int capacity) -//{ -// if(i==0 || j==0) -// { -// return; -// } -// if(res[i-1][j]==res[i][j-1]) -// { -// if(i<=capacity) -// { -// cout<res[i][j-1]) -// { -// Print(res, i-1,j, capacity); -// } -// else if(res[i][j-1]>res[i-1][j]) -// { -// Print(res, i,j-1, capacity); -// } -//} - -int Knapsack(int capacity, int n, int weight[], int value[]) -{ - int res[20][20]; - for (int i = 0; i < n + 1; ++i) - { - for (int j = 0; j < capacity + 1; ++j) - { - if (i == 0 || j == 0) - res[i][j] = 0; - else if (weight[i - 1] <= j) - res[i][j] = max(value[i - 1] + res[i - 1][j - weight[i - 1]], res[i - 1][j]); - else - res[i][j] = res[i - 1][j]; - } - } - // Print(res, n, capacity, capacity); - // cout<<"\n"; - return res[n][capacity]; -} -int main() -{ - int n; - cout << "Enter number of items: "; - cin >> n; - int weight[n], value[n]; - cout << "Enter weights: "; - for (int i = 0; i < n; ++i) - { - cin >> weight[i]; - } - cout << "Enter values: "; - for (int i = 0; i < n; ++i) - { - cin >> value[i]; - } - int capacity; - cout << "Enter capacity: "; - cin >> capacity; - cout << Knapsack(capacity, n, weight, value); - return 0; -} diff --git a/dynamic_programming/0_1_knapsack.cpp b/dynamic_programming/0_1_knapsack.cpp new file mode 100644 index 00000000000..7ea0c04c626 --- /dev/null +++ b/dynamic_programming/0_1_knapsack.cpp @@ -0,0 +1,66 @@ +// 0-1 Knapsack problem - Dynamic programming +//#include +#include +using namespace std; + +// void Print(int res[20][20], int i, int j, int capacity) +//{ +// if(i==0 || j==0) +// { +// return; +// } +// if(res[i-1][j]==res[i][j-1]) +// { +// if(i<=capacity) +// { +// cout<res[i][j-1]) +// { +// Print(res, i-1,j, capacity); +// } +// else if(res[i][j-1]>res[i-1][j]) +// { +// Print(res, i,j-1, capacity); +// } +//} + +int Knapsack(int capacity, int n, int weight[], int value[]) { + int res[20][20]; + for (int i = 0; i < n + 1; ++i) { + for (int j = 0; j < capacity + 1; ++j) { + if (i == 0 || j == 0) + res[i][j] = 0; + else if (weight[i - 1] <= j) + res[i][j] = max(value[i - 1] + res[i - 1][j - weight[i - 1]], + res[i - 1][j]); + else + res[i][j] = res[i - 1][j]; + } + } + // Print(res, n, capacity, capacity); + // cout<<"\n"; + return res[n][capacity]; +} +int main() { + int n; + cout << "Enter number of items: "; + cin >> n; + int weight[n], value[n]; + cout << "Enter weights: "; + for (int i = 0; i < n; ++i) { + cin >> weight[i]; + } + cout << "Enter values: "; + for (int i = 0; i < n; ++i) { + cin >> value[i]; + } + int capacity; + cout << "Enter capacity: "; + cin >> capacity; + cout << Knapsack(capacity, n, weight, value); + return 0; +} diff --git a/dynamic_programming/Bellman-Ford.cpp b/dynamic_programming/Bellman-Ford.cpp deleted file mode 100644 index 7c36d96df4a..00000000000 --- a/dynamic_programming/Bellman-Ford.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include -#include - -using namespace std; - -//Wrapper class for storing an edge -class Edge -{ -public: - int src, dst, weight; -}; - -//Wrapper class for storing a graph -class Graph -{ -public: - int vertexNum, edgeNum; - Edge *edges; - - //Constructs a graph with V vertices and E edges - Graph(int V, int E) - { - this->vertexNum = V; - this->edgeNum = E; - this->edges = (Edge *)malloc(E * sizeof(Edge)); - } - - //Adds the given edge to the graph - void addEdge(int src, int dst, int weight) - { - static int edgeInd = 0; - if (edgeInd < this->edgeNum) - { - Edge newEdge; - newEdge.src = src; - newEdge.dst = dst; - newEdge.weight = weight; - this->edges[edgeInd++] = newEdge; - } - } -}; - -//Utility function to print distances -void print(int dist[], int V) -{ - cout << "\nVertex Distance" << endl; - for (int i = 0; i < V; i++) - { - if (dist[i] != INT_MAX) - cout << i << "\t" << dist[i] << endl; - else - cout << i << "\tINF" << endl; - } -} - -//The main function that finds the shortest path from given source -//to all other vertices using Bellman-Ford.It also detects negative -//weight cycle -void BellmanFord(Graph graph, int src) -{ - int V = graph.vertexNum; - int E = graph.edgeNum; - int dist[V]; - - //Initialize distances array as INF for all except source - //Intialize source as zero - for (int i = 0; i < V; i++) - dist[i] = INT_MAX; - dist[src] = 0; - - //Calculate shortest path distance from source to all edges - //A path can contain maximum (|V|-1) edges - for (int i = 0; i <= V - 1; i++) - for (int j = 0; j < E; j++) - { - int u = graph.edges[j].src; - int v = graph.edges[j].dst; - int w = graph.edges[j].weight; - - if (dist[u] != INT_MAX && dist[u] + w < dist[v]) - dist[v] = dist[u] + w; - } - - //Iterate inner loop once more to check for negative cycle - for (int j = 0; j < E; j++) - { - int u = graph.edges[j].src; - int v = graph.edges[j].dst; - int w = graph.edges[j].weight; - - if (dist[u] != INT_MAX && dist[u] + w < dist[v]) - { - cout << "Graph contains negative weight cycle. Hence, shortest distance not guaranteed." << endl; - return; - } - } - - print(dist, V); - - return; -} - -//Driver Function -int main() -{ - int V, E, gsrc; - int src, dst, weight; - cout << "Enter number of vertices: "; - cin >> V; - cout << "Enter number of edges: "; - cin >> E; - Graph G(V, E); - for (int i = 0; i < E; i++) - { - cout << "\nEdge " << i + 1 << "\nEnter source: "; - cin >> src; - cout << "Enter destination: "; - cin >> dst; - cout << "Enter weight: "; - cin >> weight; - G.addEdge(src, dst, weight); - } - cout << "\nEnter source: "; - cin >> gsrc; - BellmanFord(G, gsrc); - - return 0; -} diff --git a/dynamic_programming/Coin-Change.cpp b/dynamic_programming/Coin-Change.cpp deleted file mode 100644 index c8acad48e4f..00000000000 --- a/dynamic_programming/Coin-Change.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -using namespace std; - -// Function to find the Minimum number of coins required to get Sum S -int findMinCoins(int arr[], int n, int N) -{ - // dp[i] = no of coins required to get a total of i - int dp[N + 1]; - - // 0 coins are needed for 0 sum - - dp[0] = 0; - - for (int i = 1; i <= N; i++) - { - // initialize minimum number of coins needed to infinity - dp[i] = INT_MAX; - int res = INT_MAX; - - // do for each coin - for (int c = 0; c < n; c++) - { - if (i - arr[c] >= 0) // check if coins doesn't become negative by including it - res = dp[i - arr[c]]; - - // if total can be reached by including current coin c, - // update minimum number of coins needed dp[i] - if (res != INT_MAX) - dp[i] = min(dp[i], res + 1); - } - } - - // The Minimum No of Coins Required for N = dp[N] - return dp[N]; -} - -int main() -{ - // No of Coins We Have - int arr[] = {1, 2, 3, 4}; - int n = sizeof(arr) / sizeof(arr[0]); - - // Total Change Required - int N = 15; - - cout << "Minimum Number of Coins Required " << findMinCoins(arr, n, N) << "\n"; - - return 0; -} \ No newline at end of file diff --git a/dynamic_programming/Cut Rod.cpp b/dynamic_programming/Cut Rod.cpp deleted file mode 100644 index afca3dced8b..00000000000 --- a/dynamic_programming/Cut Rod.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/*Given a rod of length n inches and an array of prices that -contains prices of all pieces of size smaller than n. Determine -the maximum value obtainable by cutting up the rod and selling -the pieces.*/ - -#include -using namespace std; -int cutrod(int p[], int n) -{ - int r[n + 1]; - r[0] = 0; - for (int j = 0; j < n; j++) - { - int q = INT_MIN; - for (int i = 0; i <= j; i++) - { - q = max(q, p[i] + r[j - i]); - } - r[j + 1] = q; - } - return r[n]; -} -int main() -{ - int price[] = {1, 5, 8, 9, 10, 17, 17, 20, 24, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50}; - cout << cutrod(price, 30); - return 0; -} diff --git a/dynamic_programming/Fibonacci_Bottom_Up.cpp b/dynamic_programming/Fibonacci_Bottom_Up.cpp deleted file mode 100644 index ab5b5b41f2a..00000000000 --- a/dynamic_programming/Fibonacci_Bottom_Up.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -using namespace std; -int fib(int n) -{ - int res[3]; - res[0] = 0; - res[1] = 1; - for (int i = 2; i <= n; i++) - { - res[2] = res[1] + res[0]; - res[0] = res[1]; - res[1] = res[2]; - } - return res[1]; -} -int main(int argc, char const *argv[]) -{ - int n; - cout << "Enter n: "; - cin >> n; - cout << "Fibonacci number is "; - cout << fib(n) << endl; - return 0; -} diff --git a/dynamic_programming/Fibonacci_Top_Down.cpp b/dynamic_programming/Fibonacci_Top_Down.cpp deleted file mode 100644 index 9d76366f783..00000000000 --- a/dynamic_programming/Fibonacci_Top_Down.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -using namespace std; -int arr[1000000]; -int fib(int n) -{ - if (arr[n] == -1) - { - if (n <= 1) - arr[n] = n; - else - arr[n] = fib(n - 1) + fib(n - 2); - } - return arr[n]; -} -int main(int argc, char const *argv[]) -{ - int n; - cout << "Enter n: "; - cin >> n; - for (int i = 0; i < n + 1; ++i) - { - arr[i] = -1; - } - cout << "Fibonacci number is " << fib(n) << endl; - return 0; -} \ No newline at end of file diff --git a/dynamic_programming/Floyd-Warshall.cpp b/dynamic_programming/Floyd-Warshall.cpp deleted file mode 100644 index 93ccff62f38..00000000000 --- a/dynamic_programming/Floyd-Warshall.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include -#include -#include - -using namespace std; - -//Wrapper class for storing a graph -class Graph -{ -public: - int vertexNum; - int **edges; - - //Constructs a graph with V vertices and E edges - Graph(int V) - { - this->vertexNum = V; - this->edges = (int **)malloc(V * sizeof(int *)); - for (int i = 0; i < V; i++) - { - this->edges[i] = (int *)malloc(V * sizeof(int)); - for (int j = 0; j < V; j++) - this->edges[i][j] = INT_MAX; - this->edges[i][i] = 0; - } - } - - //Adds the given edge to the graph - void addEdge(int src, int dst, int weight) - { - this->edges[src][dst] = weight; - } -}; - -//Utility function to print distances -void print(int dist[], int V) -{ - cout << "\nThe Distance matrix for Floyd - Warshall" << endl; - for (int i = 0; i < V; i++) - { - for (int j = 0; j < V; j++) - { - - if (dist[i * V + j] != INT_MAX) - cout << dist[i * V + j] << "\t"; - else - cout << "INF" - << "\t"; - } - cout << endl; - } -} - -//The main function that finds the shortest path from a vertex -//to all other vertices using Floyd-Warshall Algorithm. -void FloydWarshall(Graph graph) -{ - int V = graph.vertexNum; - int dist[V][V]; - - //Initialise distance array - for (int i = 0; i < V; i++) - for (int j = 0; j < V; j++) - dist[i][j] = graph.edges[i][j]; - - //Calculate distances - for (int k = 0; k < V; k++) - //Choose an intermediate vertex - - for (int i = 0; i < V; i++) - //Choose a source vertex for given intermediate - - for (int j = 0; j < V; j++) - //Choose a destination vertex for above source vertex - - if (dist[i][k] != INT_MAX && dist[k][j] != INT_MAX && dist[i][k] + dist[k][j] < dist[i][j]) - //If the distance through intermediate vertex is less than direct edge then update value in distance array - dist[i][j] = dist[i][k] + dist[k][j]; - - //Convert 2d array to 1d array for print - int dist1d[V * V]; - for (int i = 0; i < V; i++) - for (int j = 0; j < V; j++) - dist1d[i * V + j] = dist[i][j]; - - print(dist1d, V); -} - -//Driver Function -int main() -{ - int V, E; - int src, dst, weight; - cout << "Enter number of vertices: "; - cin >> V; - cout << "Enter number of edges: "; - cin >> E; - Graph G(V); - for (int i = 0; i < E; i++) - { - cout << "\nEdge " << i + 1 << "\nEnter source: "; - cin >> src; - cout << "Enter destination: "; - cin >> dst; - cout << "Enter weight: "; - cin >> weight; - G.addEdge(src, dst, weight); - } - FloydWarshall(G); - - return 0; -} diff --git a/dynamic_programming/Longest Common Subsequence.cpp b/dynamic_programming/Longest Common Subsequence.cpp deleted file mode 100644 index af50720b4e3..00000000000 --- a/dynamic_programming/Longest Common Subsequence.cpp +++ /dev/null @@ -1,82 +0,0 @@ -//Longest common subsequence - Dynamic Programming -#include -using namespace std; - -void Print(int trace[20][20], int m, int n, string a) -{ - if (m == 0 || n == 0) - { - return; - } - if (trace[m][n] == 1) - { - Print(trace, m - 1, n - 1, a); - cout << a[m - 1]; - } - else if (trace[m][n] == 2) - { - Print(trace, m - 1, n, a); - } - else if (trace[m][n] == 3) - { - Print(trace, m, n - 1, a); - } -} - -int lcs(string a, string b) -{ - int m = a.length(), n = b.length(); - int res[m + 1][n + 1]; - int trace[20][20]; - - // fills up the arrays with zeros. - for (int i = 0; i < m + 1; i++) - { - for (int j = 0; j < n + 1; j++) - { - res[i][j] = 0; - trace[i][j] = 0; - } - } - - for (int i = 0; i < m + 1; ++i) - { - for (int j = 0; j < n + 1; ++j) - { - if (i == 0 || j == 0) - { - res[i][j] = 0; - trace[i][j] = 0; - } - - else if (a[i - 1] == b[j - 1]) - { - res[i][j] = 1 + res[i - 1][j - 1]; - trace[i][j] = 1; // 1 means trace the matrix in upper left diagonal direction. - } - else - { - if (res[i - 1][j] > res[i][j - 1]) - { - res[i][j] = res[i - 1][j]; - trace[i][j] = 2; // 2 means trace the matrix in upwards direction. - } - else - { - res[i][j] = res[i][j - 1]; - trace[i][j] = 3; // means trace the matrix in left direction. - } - } - } - } - Print(trace, m, n, a); - return res[m][n]; -} - -int main() -{ - string a, b; - cin >> a >> b; - cout << lcs(a, b); - return 0; -} diff --git a/dynamic_programming/Longest Increasing Subsequence (nlogn).cpp b/dynamic_programming/Longest Increasing Subsequence (nlogn).cpp deleted file mode 100644 index 5ee24e6a78b..00000000000 --- a/dynamic_programming/Longest Increasing Subsequence (nlogn).cpp +++ /dev/null @@ -1,46 +0,0 @@ -//Program to calculate length of longest increasing subsequence in an array -// in O(n log n) -// tested on : https://cses.fi/problemset/task/1145/ - -#include - -using namespace std; -int LIS(int arr[], int n) -{ - set < int > active; // The current built LIS. - active.insert(arr[0]); - // Loop through every element. - for (int i = 1; i < n; ++i) - { - auto get = active.lower_bound(arr[i]); - if (get == active.end()) - { - active.insert(arr[i]); - } // current element is the greatest so LIS increases by 1. - else - { - int val = * get; // we find the position where arr[i] will be in the LIS. If it is in the LIS already we do nothing - if (val > arr[i]) - { - // else we remove the bigger element and add a smaller element (which is arr[i]) and continue; - active.erase(get); - active.insert(arr[i]); - } - } - } - return active.size(); // size of the LIS. -} -int main(int argc, char const * argv[]) -{ - int n; - cout << "Enter size of array: "; - cin >> n; - int a[n]; - cout << "Enter array elements: "; - for (int i = 0; i < n; ++i) - { - cin >> a[i]; - } - cout << LIS(a, n) << endl; - return 0; -} diff --git a/dynamic_programming/Longest Increasing Subsequence.cpp b/dynamic_programming/Longest Increasing Subsequence.cpp deleted file mode 100644 index 49c54a941af..00000000000 --- a/dynamic_programming/Longest Increasing Subsequence.cpp +++ /dev/null @@ -1,39 +0,0 @@ -//Program to calculate length of longest increasing subsequence in an array -#include -using namespace std; -int LIS(int a[], int n) -{ - int lis[n]; - for (int i = 0; i < n; ++i) - { - lis[i] = 1; - } - for (int i = 0; i < n; ++i) - { - for (int j = 0; j < i; ++j) - { - if (a[i] > a[j] && lis[i] < lis[j] + 1) - lis[i] = lis[j] + 1; - } - } - int res = 0; - for (int i = 0; i < n; ++i) - { - res = max(res, lis[i]); - } - return res; -} -int main(int argc, char const *argv[]) -{ - int n; - cout << "Enter size of array: "; - cin >> n; - int a[n]; - cout << "Enter array elements: "; - for (int i = 0; i < n; ++i) - { - cin >> a[i]; - } - cout << LIS(a, n) << endl; - return 0; -} \ No newline at end of file diff --git a/dynamic_programming/Matrix-Chain-Multiplication.cpp b/dynamic_programming/Matrix-Chain-Multiplication.cpp deleted file mode 100644 index 1e885bd7e4c..00000000000 --- a/dynamic_programming/Matrix-Chain-Multiplication.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include -using namespace std; - -#define MAX 10 - -// dp table to store the solution for already computed sub problems -int dp[MAX][MAX]; - -// Function to find the most efficient way to multiply the given sequence of matrices -int MatrixChainMultiplication(int dim[], int i, int j) -{ - // base case: one matrix - if (j <= i + 1) - return 0; - - // stores minimum number of scalar multiplications (i.e., cost) - // needed to compute the matrix M[i+1]...M[j] = M[i..j] - int min = INT_MAX; - - // if dp[i][j] is not calculated (calculate it!!) - - if (dp[i][j] == 0) - { - // take the minimum over each possible position at which the - // sequence of matrices can be split - - for (int k = i + 1; k <= j - 1; k++) - { - // recur for M[i+1]..M[k] to get a i x k matrix - int cost = MatrixChainMultiplication(dim, i, k); - - // recur for M[k+1]..M[j] to get a k x j matrix - cost += MatrixChainMultiplication(dim, k, j); - - // cost to multiply two (i x k) and (k x j) matrix - cost += dim[i] * dim[k] * dim[j]; - - if (cost < min) - min = cost; // store the minimum cost - } - dp[i][j] = min; - } - - // return min cost to multiply M[j+1]..M[j] - return dp[i][j]; -} - -// main function -int main() -{ - // Matrix i has Dimensions dim[i-1] & dim[i] for i=1..n - // input is 10 x 30 matrix, 30 x 5 matrix, 5 x 60 matrix - int dim[] = {10, 30, 5, 60}; - int n = sizeof(dim) / sizeof(dim[0]); - - // Function Calling: MatrixChainMultiplications(dimensions_array, starting, ending); - - cout << "Minimum cost is " << MatrixChainMultiplication(dim, 0, n - 1) << "\n"; - - return 0; -} \ No newline at end of file diff --git a/dynamic_programming/armstrong_number.cpp b/dynamic_programming/armstrong_number.cpp index 4dba89a27f8..270a705f7b4 100644 --- a/dynamic_programming/armstrong_number.cpp +++ b/dynamic_programming/armstrong_number.cpp @@ -1,21 +1,21 @@ // Program to check whether a number is an armstrong number or not #include -using std::cout; using std::cin; +using std::cout; int main() { - int n, k, d, s = 0; - cout << "Enter a number:"; - cin >> n; - k = n; - while (k != 0) { - d = k % 10; - s += d * d * d; - k /= 10; - } - if (s == n) - cout << n << "is an armstrong number"; - else - cout << n << "is not an armstrong number"; + int n, k, d, s = 0; + cout << "Enter a number:"; + cin >> n; + k = n; + while (k != 0) { + d = k % 10; + s += d * d * d; + k /= 10; + } + if (s == n) + cout << n << "is an armstrong number"; + else + cout << n << "is not an armstrong number"; } diff --git a/dynamic_programming/bellman_ford.cpp b/dynamic_programming/bellman_ford.cpp new file mode 100644 index 00000000000..c96f3fd8eea --- /dev/null +++ b/dynamic_programming/bellman_ford.cpp @@ -0,0 +1,116 @@ +#include +#include + +using namespace std; + +// Wrapper class for storing an edge +class Edge { + public: + int src, dst, weight; +}; + +// Wrapper class for storing a graph +class Graph { + public: + int vertexNum, edgeNum; + Edge *edges; + + // Constructs a graph with V vertices and E edges + Graph(int V, int E) { + this->vertexNum = V; + this->edgeNum = E; + this->edges = (Edge *)malloc(E * sizeof(Edge)); + } + + // Adds the given edge to the graph + void addEdge(int src, int dst, int weight) { + static int edgeInd = 0; + if (edgeInd < this->edgeNum) { + Edge newEdge; + newEdge.src = src; + newEdge.dst = dst; + newEdge.weight = weight; + this->edges[edgeInd++] = newEdge; + } + } +}; + +// Utility function to print distances +void print(int dist[], int V) { + cout << "\nVertex Distance" << endl; + for (int i = 0; i < V; i++) { + if (dist[i] != INT_MAX) + cout << i << "\t" << dist[i] << endl; + else + cout << i << "\tINF" << endl; + } +} + +// The main function that finds the shortest path from given source +// to all other vertices using Bellman-Ford.It also detects negative +// weight cycle +void BellmanFord(Graph graph, int src) { + int V = graph.vertexNum; + int E = graph.edgeNum; + int dist[V]; + + // Initialize distances array as INF for all except source + // Intialize source as zero + for (int i = 0; i < V; i++) dist[i] = INT_MAX; + dist[src] = 0; + + // Calculate shortest path distance from source to all edges + // A path can contain maximum (|V|-1) edges + for (int i = 0; i <= V - 1; i++) + for (int j = 0; j < E; j++) { + int u = graph.edges[j].src; + int v = graph.edges[j].dst; + int w = graph.edges[j].weight; + + if (dist[u] != INT_MAX && dist[u] + w < dist[v]) + dist[v] = dist[u] + w; + } + + // Iterate inner loop once more to check for negative cycle + for (int j = 0; j < E; j++) { + int u = graph.edges[j].src; + int v = graph.edges[j].dst; + int w = graph.edges[j].weight; + + if (dist[u] != INT_MAX && dist[u] + w < dist[v]) { + cout << "Graph contains negative weight cycle. Hence, shortest " + "distance not guaranteed." + << endl; + return; + } + } + + print(dist, V); + + return; +} + +// Driver Function +int main() { + int V, E, gsrc; + int src, dst, weight; + cout << "Enter number of vertices: "; + cin >> V; + cout << "Enter number of edges: "; + cin >> E; + Graph G(V, E); + for (int i = 0; i < E; i++) { + cout << "\nEdge " << i + 1 << "\nEnter source: "; + cin >> src; + cout << "Enter destination: "; + cin >> dst; + cout << "Enter weight: "; + cin >> weight; + G.addEdge(src, dst, weight); + } + cout << "\nEnter source: "; + cin >> gsrc; + BellmanFord(G, gsrc); + + return 0; +} diff --git a/dynamic_programming/Catalan-Numbers.cpp b/dynamic_programming/catalan_numbers.cpp similarity index 85% rename from dynamic_programming/Catalan-Numbers.cpp rename to dynamic_programming/catalan_numbers.cpp index 4d73cd51a2e..f5edaa916eb 100644 --- a/dynamic_programming/Catalan-Numbers.cpp +++ b/dynamic_programming/catalan_numbers.cpp @@ -9,10 +9,9 @@ #include using namespace std; -int *cat; // global array to hold catalan numbers +int *cat; // global array to hold catalan numbers -unsigned long int catalan_dp(int n) -{ +unsigned long int catalan_dp(int n) { /** Using the tabulation technique in dynamic programming, this function computes the first `n+1` Catalan numbers @@ -29,19 +28,17 @@ unsigned long int catalan_dp(int n) cat[0] = cat[1] = 1; // Compute the remaining numbers from index 2 to index n, using tabulation - for (int i = 2; i <= n; i++) - { + for (int i = 2; i <= n; i++) { cat[i] = 0; for (int j = 0; j < i; j++) - cat[i] += cat[j] * cat[i - j - 1]; // applying the definition here + cat[i] += cat[j] * cat[i - j - 1]; // applying the definition here } // Return the result return cat[n]; } -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int n; cout << "Enter n: "; cin >> n; @@ -49,8 +46,7 @@ int main(int argc, char *argv[]) cat = new int[n + 1]; cout << "Catalan numbers from 0 to " << n << " are:\n"; - for (int i = 0; i <= n; i++) - { + for (int i = 0; i <= n; i++) { cout << "catalan (" << i << ") = " << catalan_dp(i) << endl; // NOTE: Since `cat` is a global array, calling `catalan_dp` // repeatedly will not recompute the the values already computed diff --git a/dynamic_programming/coin_change.cpp b/dynamic_programming/coin_change.cpp new file mode 100644 index 00000000000..8c8fc3dfb68 --- /dev/null +++ b/dynamic_programming/coin_change.cpp @@ -0,0 +1,48 @@ +#include +#include +using namespace std; + +// Function to find the Minimum number of coins required to get Sum S +int findMinCoins(int arr[], int n, int N) { + // dp[i] = no of coins required to get a total of i + int dp[N + 1]; + + // 0 coins are needed for 0 sum + + dp[0] = 0; + + for (int i = 1; i <= N; i++) { + // initialize minimum number of coins needed to infinity + dp[i] = INT_MAX; + int res = INT_MAX; + + // do for each coin + for (int c = 0; c < n; c++) { + if (i - arr[c] >= + 0) // check if coins doesn't become negative by including it + res = dp[i - arr[c]]; + + // if total can be reached by including current coin c, + // update minimum number of coins needed dp[i] + if (res != INT_MAX) + dp[i] = min(dp[i], res + 1); + } + } + + // The Minimum No of Coins Required for N = dp[N] + return dp[N]; +} + +int main() { + // No of Coins We Have + int arr[] = {1, 2, 3, 4}; + int n = sizeof(arr) / sizeof(arr[0]); + + // Total Change Required + int N = 15; + + cout << "Minimum Number of Coins Required " << findMinCoins(arr, n, N) + << "\n"; + + return 0; +} \ No newline at end of file diff --git a/dynamic_programming/cut_rod.cpp b/dynamic_programming/cut_rod.cpp new file mode 100644 index 00000000000..136c78dbbab --- /dev/null +++ b/dynamic_programming/cut_rod.cpp @@ -0,0 +1,25 @@ +/*Given a rod of length n inches and an array of prices that +contains prices of all pieces of size smaller than n. Determine +the maximum value obtainable by cutting up the rod and selling +the pieces.*/ + +#include +using namespace std; +int cutrod(int p[], int n) { + int r[n + 1]; + r[0] = 0; + for (int j = 0; j < n; j++) { + int q = INT_MIN; + for (int i = 0; i <= j; i++) { + q = max(q, p[i] + r[j - i]); + } + r[j + 1] = q; + } + return r[n]; +} +int main() { + int price[] = {1, 5, 8, 9, 10, 17, 17, 20, 24, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50}; + cout << cutrod(price, 30); + return 0; +} diff --git a/dynamic_programming/Edit Distance.cpp b/dynamic_programming/edit_distance.cpp similarity index 60% rename from dynamic_programming/Edit Distance.cpp rename to dynamic_programming/edit_distance.cpp index 996d3272c7e..889b080cb93 100644 --- a/dynamic_programming/Edit Distance.cpp +++ b/dynamic_programming/edit_distance.cpp @@ -7,7 +7,7 @@ * a. Insert * b. Remove * c. Replace - * All of the above operations are + * All of the above operations are * of equal cost */ @@ -15,31 +15,27 @@ #include using namespace std; -int min(int x, int y, int z) -{ - return min(min(x, y), z); -} +int min(int x, int y, int z) { return min(min(x, y), z); } /* A Naive recursive C++ program to find * minimum number of operations to convert * str1 to str2. * O(3^m) */ -int editDist(string str1, string str2, int m, int n) -{ +int editDist(string str1, string str2, int m, int n) { if (m == 0) return n; if (n == 0) return m; - //If last characters are same then continue - //for the rest of them. + // If last characters are same then continue + // for the rest of them. if (str1[m - 1] == str2[n - 1]) return editDist(str1, str2, m - 1, n - 1); - //If last not same, then 3 possibilities - //a.Insert b.Remove c. Replace - //Get min of three and continue for rest. + // If last not same, then 3 possibilities + // a.Insert b.Remove c. Replace + // Get min of three and continue for rest. return 1 + min(editDist(str1, str2, m, n - 1), editDist(str1, str2, m - 1, n), editDist(str1, str2, m - 1, n - 1)); @@ -48,33 +44,29 @@ int editDist(string str1, string str2, int m, int n) /* A DP based program * O(m x n) */ -int editDistDP(string str1, string str2, int m, int n) -{ - - //Create Table for SubProblems +int editDistDP(string str1, string str2, int m, int n) { + // Create Table for SubProblems int dp[m + 1][n + 1]; - //Fill d[][] in bottom up manner - for (int i = 0; i <= m; i++) - { - for (int j = 0; j <= n; j++) - { - //If str1 empty. Then add all of str2 + // Fill d[][] in bottom up manner + for (int i = 0; i <= m; i++) { + for (int j = 0; j <= n; j++) { + // If str1 empty. Then add all of str2 if (i == 0) dp[i][j] = j; - //If str2 empty. Then add all of str1 + // If str2 empty. Then add all of str1 else if (j == 0) dp[i][j] = i; - //If character same. Recur for remaining + // If character same. Recur for remaining else if (str1[i - 1] == str2[j - 1]) dp[i][j] = dp[i - 1][j - 1]; else - dp[i][j] = 1 + min(dp[i][j - 1], //Insert - dp[i - 1][j], //Remove - dp[i - 1][j - 1] //Replace + dp[i][j] = 1 + min(dp[i][j - 1], // Insert + dp[i - 1][j], // Remove + dp[i - 1][j - 1] // Replace ); } } @@ -82,8 +74,7 @@ int editDistDP(string str1, string str2, int m, int n) return dp[m][n]; } -int main() -{ +int main() { string str1 = "sunday"; string str2 = "saturday"; diff --git a/dynamic_programming/Egg-Dropping-Puzzle.cpp b/dynamic_programming/egg_dropping_puzzle.cpp similarity index 63% rename from dynamic_programming/Egg-Dropping-Puzzle.cpp rename to dynamic_programming/egg_dropping_puzzle.cpp index a441f29cbdf..7a769ea472e 100644 --- a/dynamic_programming/Egg-Dropping-Puzzle.cpp +++ b/dynamic_programming/egg_dropping_puzzle.cpp @@ -1,35 +1,29 @@ -/* Function to get minimun number of trials needed - * in worst case with n eggs and k floors +/* Function to get minimun number of trials needed + * in worst case with n eggs and k floors */ -#include #include +#include using namespace std; -int eggDrop(int n, int k) -{ +int eggDrop(int n, int k) { int eggFloor[n + 1][k + 1]; int result; - for (int i = 1; i <= n; i++) - { - eggFloor[i][1] = 1; //n eggs..1 Floor - eggFloor[i][0] = 0; //n eggs..0 Floor + for (int i = 1; i <= n; i++) { + eggFloor[i][1] = 1; // n eggs..1 Floor + eggFloor[i][0] = 0; // n eggs..0 Floor } // Only one egg available - for (int j = 1; j <= k; j++) - { + for (int j = 1; j <= k; j++) { eggFloor[1][j] = j; } - for (int i = 2; i <= n; i++) - { - for (int j = 2; j <= k; j++) - { + for (int i = 2; i <= n; i++) { + for (int j = 2; j <= k; j++) { eggFloor[i][j] = INT_MAX; - for (int x = 1; x <= j; x++) - { + for (int x = 1; x <= j; x++) { // 1+max(eggBreak[one less egg, lower floors], // eggDoesntBreak[same # of eggs, upper floors]); result = 1 + max(eggFloor[i - 1][x - 1], eggFloor[i][j - x]); @@ -42,8 +36,7 @@ int eggDrop(int n, int k) return eggFloor[n][k]; } -int main() -{ +int main() { int n, k; cout << "Enter number of eggs and floors: "; cin >> n >> k; diff --git a/dynamic_programming/fibonacci_bottom_up.cpp b/dynamic_programming/fibonacci_bottom_up.cpp new file mode 100644 index 00000000000..555f15282f4 --- /dev/null +++ b/dynamic_programming/fibonacci_bottom_up.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; +int fib(int n) { + int res[3]; + res[0] = 0; + res[1] = 1; + for (int i = 2; i <= n; i++) { + res[2] = res[1] + res[0]; + res[0] = res[1]; + res[1] = res[2]; + } + return res[1]; +} +int main(int argc, char const *argv[]) { + int n; + cout << "Enter n: "; + cin >> n; + cout << "Fibonacci number is "; + cout << fib(n) << endl; + return 0; +} diff --git a/dynamic_programming/fibonacci_top_down.cpp b/dynamic_programming/fibonacci_top_down.cpp new file mode 100644 index 00000000000..3c0c9a1a323 --- /dev/null +++ b/dynamic_programming/fibonacci_top_down.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; +int arr[1000000]; +int fib(int n) { + if (arr[n] == -1) { + if (n <= 1) + arr[n] = n; + else + arr[n] = fib(n - 1) + fib(n - 2); + } + return arr[n]; +} +int main(int argc, char const *argv[]) { + int n; + cout << "Enter n: "; + cin >> n; + for (int i = 0; i < n + 1; ++i) { + arr[i] = -1; + } + cout << "Fibonacci number is " << fib(n) << endl; + return 0; +} \ No newline at end of file diff --git a/dynamic_programming/floyd_warshall.cpp b/dynamic_programming/floyd_warshall.cpp new file mode 100644 index 00000000000..d193ebbd589 --- /dev/null +++ b/dynamic_programming/floyd_warshall.cpp @@ -0,0 +1,107 @@ +#include +#include +#include + +using std::cin; +using std::cout; +using std::endl; + +// Wrapper class for storing a graph +class Graph { + public: + int vertexNum; + int **edges; + + // Constructs a graph with V vertices and E edges + Graph(int V) { + this->vertexNum = V; + this->edges = new int *[V]; + for (int i = 0; i < V; i++) { + this->edges[i] = new int[V]; + for (int j = 0; j < V; j++) this->edges[i][j] = INT_MAX; + this->edges[i][i] = 0; + } + } + + ~Graph() { + for (int i = 0; i < vertexNum; i++) delete[] edges[i]; + delete[] edges; + } + + // Adds the given edge to the graph + void addEdge(int src, int dst, int weight) { + this->edges[src][dst] = weight; + } +}; + +// Utility function to print distances +void print(int dist[], int V) { + cout << "\nThe Distance matrix for Floyd - Warshall" << endl; + for (int i = 0; i < V; i++) { + for (int j = 0; j < V; j++) { + if (dist[i * V + j] != INT_MAX) + cout << dist[i * V + j] << "\t"; + else + cout << "INF" + << "\t"; + } + cout << endl; + } +} + +// The main function that finds the shortest path from a vertex +// to all other vertices using Floyd-Warshall Algorithm. +void FloydWarshall(Graph graph) { + int V = graph.vertexNum; + int dist[V][V]; + + // Initialise distance array + for (int i = 0; i < V; i++) + for (int j = 0; j < V; j++) dist[i][j] = graph.edges[i][j]; + + // Calculate distances + for (int k = 0; k < V; k++) + // Choose an intermediate vertex + + for (int i = 0; i < V; i++) + // Choose a source vertex for given intermediate + + for (int j = 0; j < V; j++) + // Choose a destination vertex for above source vertex + + if (dist[i][k] != INT_MAX && dist[k][j] != INT_MAX && + dist[i][k] + dist[k][j] < dist[i][j]) + // If the distance through intermediate vertex is less than + // direct edge then update value in distance array + dist[i][j] = dist[i][k] + dist[k][j]; + + // Convert 2d array to 1d array for print + int dist1d[V * V]; + for (int i = 0; i < V; i++) + for (int j = 0; j < V; j++) dist1d[i * V + j] = dist[i][j]; + + print(dist1d, V); +} + +// Driver Function +int main() { + int V, E; + int src, dst, weight; + cout << "Enter number of vertices: "; + cin >> V; + cout << "Enter number of edges: "; + cin >> E; + Graph G(V); + for (int i = 0; i < E; i++) { + cout << "\nEdge " << i + 1 << "\nEnter source: "; + cin >> src; + cout << "Enter destination: "; + cin >> dst; + cout << "Enter weight: "; + cin >> weight; + G.addEdge(src, dst, weight); + } + FloydWarshall(G); + + return 0; +} diff --git a/dynamic_programming/kadane.cpp b/dynamic_programming/kadane.cpp index bf2aa76ac9b..b5272756bcf 100644 --- a/dynamic_programming/kadane.cpp +++ b/dynamic_programming/kadane.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include int maxSubArraySum(int a[], int size) { int max_so_far = INT_MIN, max_ending_here = 0; @@ -15,7 +15,6 @@ int maxSubArraySum(int a[], int size) { return max_so_far; } - int main() { int n, i; std::cout << "Enter the number of elements \n"; diff --git a/dynamic_programming/longest_common_string.cpp b/dynamic_programming/longest_common_string.cpp index c1e89d6dbf2..81fa8a0026a 100644 --- a/dynamic_programming/longest_common_string.cpp +++ b/dynamic_programming/longest_common_string.cpp @@ -1,65 +1,53 @@ #include using namespace std; -int max(int a,int b) -{ - return (a > b) ? a : b; -} - -int main() -{ - char str1[]="DEFBCD"; - char str2[]="ABDEFJ"; - int i,j,k; - int n=strlen(str1)+1; - int m=strlen(str2)+1; - //cout< b) ? a : b; } + +int main() { + char str1[] = "DEFBCD"; + char str2[] = "ABDEFJ"; + int i, j, k; + int n = strlen(str1) + 1; + int m = strlen(str2) + 1; + // cout<ma) - { - ma=a[i][j]; - indi=i; - indj=j; + for(j=0;j ma) { + ma = a[i][j]; + indi = i; + indj = j; } } } - cout< +using namespace std; + +void Print(int trace[20][20], int m, int n, string a) { + if (m == 0 || n == 0) { + return; + } + if (trace[m][n] == 1) { + Print(trace, m - 1, n - 1, a); + cout << a[m - 1]; + } else if (trace[m][n] == 2) { + Print(trace, m - 1, n, a); + } else if (trace[m][n] == 3) { + Print(trace, m, n - 1, a); + } +} + +int lcs(string a, string b) { + int m = a.length(), n = b.length(); + int res[m + 1][n + 1]; + int trace[20][20]; + + // fills up the arrays with zeros. + for (int i = 0; i < m + 1; i++) { + for (int j = 0; j < n + 1; j++) { + res[i][j] = 0; + trace[i][j] = 0; + } + } + + for (int i = 0; i < m + 1; ++i) { + for (int j = 0; j < n + 1; ++j) { + if (i == 0 || j == 0) { + res[i][j] = 0; + trace[i][j] = 0; + } + + else if (a[i - 1] == b[j - 1]) { + res[i][j] = 1 + res[i - 1][j - 1]; + trace[i][j] = 1; // 1 means trace the matrix in upper left + // diagonal direction. + } else { + if (res[i - 1][j] > res[i][j - 1]) { + res[i][j] = res[i - 1][j]; + trace[i][j] = + 2; // 2 means trace the matrix in upwards direction. + } else { + res[i][j] = res[i][j - 1]; + trace[i][j] = + 3; // means trace the matrix in left direction. + } + } + } + } + Print(trace, m, n, a); + return res[m][n]; +} + +int main() { + string a, b; + cin >> a >> b; + cout << lcs(a, b); + return 0; +} diff --git a/dynamic_programming/longest_increasing_subsequence.cpp b/dynamic_programming/longest_increasing_subsequence.cpp new file mode 100644 index 00000000000..b6a798aa050 --- /dev/null +++ b/dynamic_programming/longest_increasing_subsequence.cpp @@ -0,0 +1,32 @@ +// Program to calculate length of longest increasing subsequence in an array +#include +using namespace std; +int LIS(int a[], int n) { + int lis[n]; + for (int i = 0; i < n; ++i) { + lis[i] = 1; + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < i; ++j) { + if (a[i] > a[j] && lis[i] < lis[j] + 1) + lis[i] = lis[j] + 1; + } + } + int res = 0; + for (int i = 0; i < n; ++i) { + res = max(res, lis[i]); + } + return res; +} +int main(int argc, char const *argv[]) { + int n; + cout << "Enter size of array: "; + cin >> n; + int a[n]; + cout << "Enter array elements: "; + for (int i = 0; i < n; ++i) { + cin >> a[i]; + } + cout << LIS(a, n) << endl; + return 0; +} \ No newline at end of file diff --git a/dynamic_programming/longest_increasing_subsequence_(nlogn).cpp b/dynamic_programming/longest_increasing_subsequence_(nlogn).cpp new file mode 100644 index 00000000000..5bc72345c23 --- /dev/null +++ b/dynamic_programming/longest_increasing_subsequence_(nlogn).cpp @@ -0,0 +1,41 @@ +// Program to calculate length of longest increasing subsequence in an array +// in O(n log n) +// tested on : https://cses.fi/problemset/task/1145/ + +#include + +using namespace std; +int LIS(int arr[], int n) { + set active; // The current built LIS. + active.insert(arr[0]); + // Loop through every element. + for (int i = 1; i < n; ++i) { + auto get = active.lower_bound(arr[i]); + if (get == active.end()) { + active.insert(arr[i]); + } // current element is the greatest so LIS increases by 1. + else { + int val = *get; // we find the position where arr[i] will be in the + // LIS. If it is in the LIS already we do nothing + if (val > arr[i]) { + // else we remove the bigger element and add a smaller element + // (which is arr[i]) and continue; + active.erase(get); + active.insert(arr[i]); + } + } + } + return active.size(); // size of the LIS. +} +int main(int argc, char const* argv[]) { + int n; + cout << "Enter size of array: "; + cin >> n; + int a[n]; + cout << "Enter array elements: "; + for (int i = 0; i < n; ++i) { + cin >> a[i]; + } + cout << LIS(a, n) << endl; + return 0; +} diff --git a/dynamic_programming/matrix_chain_multiplication.cpp b/dynamic_programming/matrix_chain_multiplication.cpp new file mode 100644 index 00000000000..7d6647c5257 --- /dev/null +++ b/dynamic_programming/matrix_chain_multiplication.cpp @@ -0,0 +1,61 @@ +#include +#include +using namespace std; + +#define MAX 10 + +// dp table to store the solution for already computed sub problems +int dp[MAX][MAX]; + +// Function to find the most efficient way to multiply the given sequence of +// matrices +int MatrixChainMultiplication(int dim[], int i, int j) { + // base case: one matrix + if (j <= i + 1) + return 0; + + // stores minimum number of scalar multiplications (i.e., cost) + // needed to compute the matrix M[i+1]...M[j] = M[i..j] + int min = INT_MAX; + + // if dp[i][j] is not calculated (calculate it!!) + + if (dp[i][j] == 0) { + // take the minimum over each possible position at which the + // sequence of matrices can be split + + for (int k = i + 1; k <= j - 1; k++) { + // recur for M[i+1]..M[k] to get a i x k matrix + int cost = MatrixChainMultiplication(dim, i, k); + + // recur for M[k+1]..M[j] to get a k x j matrix + cost += MatrixChainMultiplication(dim, k, j); + + // cost to multiply two (i x k) and (k x j) matrix + cost += dim[i] * dim[k] * dim[j]; + + if (cost < min) + min = cost; // store the minimum cost + } + dp[i][j] = min; + } + + // return min cost to multiply M[j+1]..M[j] + return dp[i][j]; +} + +// main function +int main() { + // Matrix i has Dimensions dim[i-1] & dim[i] for i=1..n + // input is 10 x 30 matrix, 30 x 5 matrix, 5 x 60 matrix + int dim[] = {10, 30, 5, 60}; + int n = sizeof(dim) / sizeof(dim[0]); + + // Function Calling: MatrixChainMultiplications(dimensions_array, starting, + // ending); + + cout << "Minimum cost is " << MatrixChainMultiplication(dim, 0, n - 1) + << "\n"; + + return 0; +} \ No newline at end of file diff --git a/dynamic_programming/searching_of_element_in_dynamic_array.cpp b/dynamic_programming/searching_of_element_in_dynamic_array.cpp index 9ee48ddedf7..7792a514908 100644 --- a/dynamic_programming/searching_of_element_in_dynamic_array.cpp +++ b/dynamic_programming/searching_of_element_in_dynamic_array.cpp @@ -1,36 +1,36 @@ /* -*this program is use to find any elemet in any row with variable array size -*aplication of pointer is use in it -*important point start from here to: -*the index value of array can be go to 1 to 100000 -*check till array[1000] -*end here -*how to work example: -**Question: -***number of array 2 -***quarry 3 -***array 1 is {1 2 3 4 5} -***array 2 is {6 7} -****i) what is 2nd element in 1st array -****ii) what is 1st element in 2nd array -****iii) what is 5th element in 1st array -*****output: -*****Enter Number of array you want to Store : 2 -*****Enter Number of Question or Quary you want to do Related to Array : 3 -*****Enter number of element in 1 rows : 5 -*****Enter the element of Array 1 2 3 4 5 -*****Enter number of element in 2 rows : 2 -*****Enter the element of Array 6 7 -*****enter the number of row which element You want to find : 1 -*****enter the position of element which You want to find : 2 -*****The element is 2 -*****enter the number of row which element You want to find : 2 -*****enter the position of element which You want to find : 1 -*****The element is 6 -*****enter the number of row which element You want to find : 1 -*****enter the position of element which You want to find : 5 -*****The element is 5 -*/ + *this program is use to find any elemet in any row with variable array size + *aplication of pointer is use in it + *important point start from here to: + *the index value of array can be go to 1 to 100000 + *check till array[1000] + *end here + *how to work example: + **Question: + ***number of array 2 + ***quarry 3 + ***array 1 is {1 2 3 4 5} + ***array 2 is {6 7} + ****i) what is 2nd element in 1st array + ****ii) what is 1st element in 2nd array + ****iii) what is 5th element in 1st array + *****output: + *****Enter Number of array you want to Store : 2 + *****Enter Number of Question or Quary you want to do Related to Array : 3 + *****Enter number of element in 1 rows : 5 + *****Enter the element of Array 1 2 3 4 5 + *****Enter number of element in 2 rows : 2 + *****Enter the element of Array 6 7 + *****enter the number of row which element You want to find : 1 + *****enter the position of element which You want to find : 2 + *****The element is 2 + *****enter the number of row which element You want to find : 2 + *****enter the position of element which You want to find : 1 + *****The element is 6 + *****enter the number of row which element You want to find : 1 + *****enter the position of element which You want to find : 5 + *****The element is 5 + */ #include // this is main fuction @@ -46,7 +46,7 @@ int main() { // create a Array in run time because use can // change the size of each array which he/she is going to store // create a 2D array - int** ar = new int* [x](); + int** ar = new int*[x](); // this for loop is use for entering different variable size array // *** for (r = 0; r < x; r++) { @@ -75,6 +75,6 @@ int main() { std::cin >> q1; q1 = q1 - 1; // use this to find desire position of element in desire array - std::cout <<"The element is "<< ar[r1][q1] < -#include +#include +#include // global declarations // no of nodes max limit. @@ -37,7 +37,7 @@ void depth_first_search(int u) { depth_first_search(v); // select maximum sub-tree height from all children. - child_height = std::max(child_height, dp[v]+1); + child_height = std::max(child_height, dp[v] + 1); } } // assigned the max child height to current visited node. @@ -61,9 +61,9 @@ int main() { adj[v].push_back(u); } // initialize all nodes as unvisited. - visited.assign(number_of_nodes+1, false); + visited.assign(number_of_nodes + 1, false); // initialize depth of all nodes to 0. - dp.assign(number_of_nodes+1, 0); + dp.assign(number_of_nodes + 1, 0); // function call which will initialize the height of all nodes. depth_first_search(1); std::cout << "Height of the Tree : " << dp[1] << std::endl; diff --git a/geometry/CMakeLists.txt b/geometry/CMakeLists.txt new file mode 100644 index 00000000000..72655169aab --- /dev/null +++ b/geometry/CMakeLists.txt @@ -0,0 +1,18 @@ +# If necessary, use the RELATIVE flag, otherwise each source file may be listed +# with full pathname. RELATIVE may makes it easier to extract an executable name +# automatically. +file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) +# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) +foreach( testsourcefile ${APP_SOURCES} ) + # I used a simple string replace, to cut off .cpp. + string( REPLACE ".cpp" "" testname ${testsourcefile} ) + add_executable( ${testname} ${testsourcefile} ) + + set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) + if(OpenMP_CXX_FOUND) + target_link_libraries(${testname} OpenMP::OpenMP_CXX) + endif() + install(TARGETS ${testname} DESTINATION "bin/geometry") + +endforeach( testsourcefile ${APP_SOURCES} ) diff --git a/geometry/line_segment_intersection.cpp b/geometry/line_segment_intersection.cpp index 0b5b858d747..d523ae0a413 100644 --- a/geometry/line_segment_intersection.cpp +++ b/geometry/line_segment_intersection.cpp @@ -3,6 +3,7 @@ * @brief check whether two line segments intersect each other * or not. */ +#include #include /** @@ -20,57 +21,59 @@ struct Point { */ struct SegmentIntersection { inline bool intersect(Point first_point, Point second_point, - Point third_point, Point forth_point) { + Point third_point, Point forth_point) { int direction1 = direction(third_point, forth_point, first_point); int direction2 = direction(third_point, forth_point, second_point); int direction3 = direction(first_point, second_point, third_point); int direction4 = direction(first_point, second_point, forth_point); - if ((direction1 < 0 || direction2 > 0) && (direction3 < 0 || - direction4 > 0)) + if ((direction1 < 0 || direction2 > 0) && + (direction3 < 0 || direction4 > 0)) return true; - else if (direction1 == 0 && on_segment(third_point, forth_point, - first_point)) + else if (direction1 == 0 && + on_segment(third_point, forth_point, first_point)) return true; - else if (direction2 == 0 && on_segment(third_point, forth_point, - second_point)) + else if (direction2 == 0 && + on_segment(third_point, forth_point, second_point)) return true; - else if (direction3 == 0 && on_segment(first_point, second_point, - third_point)) + else if (direction3 == 0 && + on_segment(first_point, second_point, third_point)) return true; - else if (direction3 == 0 && on_segment(first_point, second_point, - forth_point)) + else if (direction3 == 0 && + on_segment(first_point, second_point, forth_point)) return true; else return false; } - /** - * We will find direction of line here respect to @first_point. - * Here @second_point and @third_point is first and second points - * of the line respectively. we want a method to determine which way a - * given angle these three points turns. If returned number is negative, - * then the angle is counter-clockwise. That means the line is going to - * right to left. We will fount angle as clockwise if the method returns - * positive number. - */ + /** + * We will find direction of line here respect to @first_point. + * Here @second_point and @third_point is first and second points + * of the line respectively. we want a method to determine which way a + * given angle these three points turns. If returned number is negative, + * then the angle is counter-clockwise. That means the line is going to + * right to left. We will fount angle as clockwise if the method returns + * positive number. + */ inline int direction(Point first_point, Point second_point, - Point third_point) { - return ((third_point.x-first_point.x)*(second_point.y-first_point.y))- - ((second_point.x-first_point.x) * (third_point.y-first_point.y)); + Point third_point) { + return ((third_point.x - first_point.x) * + (second_point.y - first_point.y)) - + ((second_point.x - first_point.x) * + (third_point.y - first_point.y)); } - /** - * This method determines whether a point known to be colinear - * with a segment lies on that segment. - */ + /** + * This method determines whether a point known to be colinear + * with a segment lies on that segment. + */ inline bool on_segment(Point first_point, Point second_point, - Point third_point) { + Point third_point) { if (std::min(first_point.x, second_point.x) <= third_point.x && third_point.x <= std::max(first_point.x, second_point.x) && std::min(first_point.y, second_point.y) <= third_point.y && @@ -96,6 +99,6 @@ int main() { std::cin >> forth_point.x >> forth_point.y; printf("%d", segment.intersect(first_point, second_point, third_point, - forth_point)); + forth_point)); std::cout << std::endl; } diff --git a/graph/BFS.cpp b/graph/BFS.cpp deleted file mode 100644 index e4e12886b73..00000000000 --- a/graph/BFS.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -using namespace std; -class graph -{ - int v; - list *adj; - -public: - graph(int v); - void addedge(int src, int dest); - void printgraph(); - void bfs(int s); -}; -graph::graph(int v) -{ - this->v = v; - this->adj = new list[v]; -} -void graph::addedge(int src, int dest) -{ - src--; - dest--; - adj[src].push_back(dest); - //adj[dest].push_back(src); -} -void graph::printgraph() -{ - for (int i = 0; i < this->v; i++) - { - cout << "Adjacency list of vertex " << i + 1 << " is \n"; - list::iterator it; - for (it = adj[i].begin(); it != adj[i].end(); ++it) - { - cout << *it + 1 << " "; - } - cout << endl; - } -} -void graph::bfs(int s) -{ - bool *visited = new bool[this->v + 1]; - memset(visited, false, sizeof(bool) * (this->v + 1)); - visited[s] = true; - list q; - q.push_back(s); - list::iterator it; - while (!q.empty()) - { - int u = q.front(); - cout << u << " "; - q.pop_front(); - for (it = adj[u].begin(); it != adj[u].end(); ++it) - { - if (visited[*it] == false) - { - visited[*it] = true; - q.push_back(*it); - } - } - } -} -int main() -{ - graph g(4); - g.addedge(1, 2); - g.addedge(2, 3); - g.addedge(3, 4); - g.addedge(1, 4); - g.addedge(1, 3); - //g.printgraph(); - g.bfs(2); - return 0; -} diff --git a/graph/DFS.cpp b/graph/DFS.cpp deleted file mode 100644 index 656711ac822..00000000000 --- a/graph/DFS.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -using namespace std; -int v = 4; -void DFSUtil_(int graph[4][4], bool visited[], int s) -{ - visited[s] = true; - cout << s << " "; - for (int i = 0; i < v; i++) - { - if (graph[s][i] == 1 && visited[i] == false) - { - DFSUtil_(graph, visited, i); - } - } -} - -void DFS_(int graph[4][4], int s) -{ - bool visited[v]; - memset(visited, 0, sizeof(visited)); - DFSUtil_(graph, visited, s); -} - -int main() -{ - int graph[4][4] = {{0, 1, 1, 0}, {0, 0, 1, 0}, {1, 0, 0, 1}, {0, 0, 0, 1}}; - cout << "DFS: "; - DFS_(graph, 2); - cout << endl; - return 0; -} \ No newline at end of file diff --git a/graph/Kruskal.cpp b/graph/Kruskal.cpp deleted file mode 100644 index 21b04ce49fc..00000000000 --- a/graph/Kruskal.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#include -//#include -//using namespace boost::multiprecision; -const int mx = 1e6 + 5; -const long int inf = 2e9; -typedef long long ll; -#define rep(i, n) for (i = 0; i < n; i++) -#define repp(i, a, b) for (i = a; i <= b; i++) -#define pii pair -#define vpii vector -#define vi vector -#define vll vector -#define r(x) scanf("%d", &x) -#define rs(s) scanf("%s", s) -#define gc getchar_unlocked -#define pc putchar_unlocked -#define mp make_pair -#define pb push_back -#define lb lower_bound -#define ub upper_bound -#define endl "\n" -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL); -using namespace std; -void in(int &x) -{ - register int c = gc(); - x = 0; - int neg = 0; - for (; ((c < 48 || c > 57) && c != '-'); c = gc()) - ; - if (c == '-') - { - neg = 1; - c = gc(); - } - for (; c > 47 && c < 58; c = gc()) - { - x = (x << 1) + (x << 3) + c - 48; - } - if (neg) - x = -x; -} -void out(int n) -{ - int N = n, rev, count = 0; - rev = N; - if (N == 0) - { - pc('0'); - return; - } - while ((rev % 10) == 0) - { - count++; - rev /= 10; - } - rev = 0; - while (N != 0) - { - rev = (rev << 3) + (rev << 1) + N % 10; - N /= 10; - } - while (rev != 0) - { - pc(rev % 10 + '0'); - rev /= 10; - } - while (count--) - pc('0'); -} -ll parent[mx], arr[mx], node, edge; -vector>> v; -void initial() -{ - int i; - rep(i, node + edge) - parent[i] = i; -} -int root(int i) -{ - while (parent[i] != i) - { - parent[i] = parent[parent[i]]; - i = parent[i]; - } - return i; -} -void join(int x, int y) -{ - int root_x = root(x); //Disjoint set union by rank - int root_y = root(y); - parent[root_x] = root_y; -} -ll kruskal() -{ - ll mincost = 0, i, x, y; - rep(i, edge) - { - x = v[i].second.first; - y = v[i].second.second; - if (root(x) != root(y)) - { - mincost += v[i].first; - join(x, y); - } - } - return mincost; -} -int main() -{ - fast; - while (1) - { - int i, j, from, to, cost, totalcost = 0; - cin >> node >> edge; //Enter the nodes and edges - if (node == 0 && edge == 0) - break; //Enter 0 0 to break out - initial(); //Initialise the parent array - rep(i, edge) - { - cin >> from >> to >> cost; - v.pb(mp(cost, mp(from, to))); - totalcost += cost; - } - sort(v.begin(), v.end()); - // rep(i,v.size()) - // cout< -#include -#include -using namespace std; - -int n, m; // For number of Vertices (V) and number of edges (E) -vector> G; -vector visited; -vector ans; - -void dfs(int v) -{ - visited[v] = true; - for (int u : G[v]) - { - if (!visited[u]) - dfs(u); - } - ans.push_back(v); -} - -void topological_sort() -{ - visited.assign(n, false); - ans.clear(); - for (int i = 0; i < n; ++i) - { - if (!visited[i]) - dfs(i); - } - reverse(ans.begin(), ans.end()); -} -int main() -{ - cout << "Enter the number of vertices and the number of directed edges\n"; - cin >> n >> m; - int x, y; - G.resize(n, vector()); - for (int i = 0; i < n; ++i) - { - cin >> x >> y; - x--, y--; // to convert 1-indexed to 0-indexed - G[x].push_back(y); - } - topological_sort(); - cout << "Topological Order : \n"; - for (int v : ans) - { - cout << v + 1 << ' '; // converting zero based indexing back to one based. - } - cout << '\n'; - return 0; -} diff --git a/graph/bfs.cpp b/graph/bfs.cpp new file mode 100644 index 00000000000..3acee8f806f --- /dev/null +++ b/graph/bfs.cpp @@ -0,0 +1,62 @@ +#include +using namespace std; +class graph { + int v; + list *adj; + + public: + graph(int v); + void addedge(int src, int dest); + void printgraph(); + void bfs(int s); +}; +graph::graph(int v) { + this->v = v; + this->adj = new list[v]; +} +void graph::addedge(int src, int dest) { + src--; + dest--; + adj[src].push_back(dest); + // adj[dest].push_back(src); +} +void graph::printgraph() { + for (int i = 0; i < this->v; i++) { + cout << "Adjacency list of vertex " << i + 1 << " is \n"; + list::iterator it; + for (it = adj[i].begin(); it != adj[i].end(); ++it) { + cout << *it + 1 << " "; + } + cout << endl; + } +} +void graph::bfs(int s) { + bool *visited = new bool[this->v + 1]; + memset(visited, false, sizeof(bool) * (this->v + 1)); + visited[s] = true; + list q; + q.push_back(s); + list::iterator it; + while (!q.empty()) { + int u = q.front(); + cout << u << " "; + q.pop_front(); + for (it = adj[u].begin(); it != adj[u].end(); ++it) { + if (visited[*it] == false) { + visited[*it] = true; + q.push_back(*it); + } + } + } +} +int main() { + graph g(4); + g.addedge(1, 2); + g.addedge(2, 3); + g.addedge(3, 4); + g.addedge(1, 4); + g.addedge(1, 3); + // g.printgraph(); + g.bfs(2); + return 0; +} diff --git a/graph/bridge_finding_with_tarjan_algorithm.cpp b/graph/bridge_finding_with_tarjan_algorithm.cpp index ca124f512f0..eec176af58f 100644 --- a/graph/bridge_finding_with_tarjan_algorithm.cpp +++ b/graph/bridge_finding_with_tarjan_algorithm.cpp @@ -4,27 +4,27 @@ * Last Modified Date: May 24, 2020 * */ -#include // for std::vector #include // for min & max -#include // for cout -using std::vector; +#include // for cout +#include // for std::vector using std::cout; using std::min; +using std::vector; class Solution { - vector < vector < int > > graph; - vectorin_time , out_time; + vector> graph; + vector in_time, out_time; int timer; - vector < vector < int > > bridge; - vectorvisited; - void dfs(int current_node , int parent) { + vector> bridge; + vector visited; + void dfs(int current_node, int parent) { visited.at(current_node) = true; in_time[current_node] = out_time[current_node] = timer++; - for ( auto&itr : graph[current_node] ) { + for (auto& itr : graph[current_node]) { if (itr == parent) { continue; } if (!visited[itr]) { - dfs(itr , current_node); + dfs(itr, current_node); if (out_time[itr] > in_time[current_node]) { bridge.push_back({itr, current_node}); } @@ -34,14 +34,14 @@ class Solution { } public: - vector > search_bridges(int n, - const vector>& connections) { + vector> search_bridges(int n, + const vector>& connections) { timer = 0; graph.resize(n); in_time.assign(n, 0); visited.assign(n, false); out_time.assign(n, 0); - for (auto&itr : connections) { + for (auto& itr : connections) { graph.at(itr[0]).push_back(itr[1]); graph.at(itr[1]).push_back(itr[0]); } @@ -52,7 +52,7 @@ class Solution { int main(void) { Solution s1; int number_of_node = 5; - vector< vector >node; + vector> node; node.push_back({0, 1}); node.push_back({1, 3}); node.push_back({1, 2}); @@ -66,13 +66,13 @@ int main(void) { * 3 4 * * In this graph there are 4 bridges [0,2] , [2,4] , [3,5] , [1,2] - * + * * I assumed that the graph is bi-directional and connected. * */ - vector< vector > bridges = s1.search_bridges(number_of_node , node); + vector> bridges = s1.search_bridges(number_of_node, node); cout << bridges.size() << " bridges found!\n"; - for (auto&itr : bridges) { + for (auto& itr : bridges) { cout << itr[0] << " --> " << itr[1] << '\n'; } return 0; diff --git a/graph/connected_components.cpp b/graph/connected_components.cpp index 9c22cc35e48..0bfb8bbdb98 100644 --- a/graph/connected_components.cpp +++ b/graph/connected_components.cpp @@ -8,48 +8,47 @@ class graph { vector> adj; int connected_components; void depth_first_search(); - void explore(int, vector&); + void explore(int, vector &); + public: - explicit graph(int n): adj(n, vector()) { - connected_components = 0; - } + explicit graph(int n) : adj(n, vector()) { connected_components = 0; } void addEdge(int, int); int getConnectedComponents() { - depth_first_search(); - return connected_components; + depth_first_search(); + return connected_components; } }; void graph::addEdge(int u, int v) { - adj[u-1].push_back(v-1); - adj[v-1].push_back(u-1); + adj[u - 1].push_back(v - 1); + adj[v - 1].push_back(u - 1); } void graph::depth_first_search() { - int n = adj.size(); - vector visited(n, false); + int n = adj.size(); + vector visited(n, false); - for (int i = 0 ; i < n ; i++) { - if (!visited[i]) { - explore(i, visited); - connected_components++; + for (int i = 0; i < n; i++) { + if (!visited[i]) { + explore(i, visited); + connected_components++; + } } - } } void graph::explore(int u, vector &visited) { - visited[u] = true; - for (auto v : adj[u]) { - if (!visited[v]) { - explore(v, visited); + visited[u] = true; + for (auto v : adj[u]) { + if (!visited[v]) { + explore(v, visited); + } } - } } int main() { - graph g(4); - g.addEdge(1, 2); - g.addEdge(3, 2); - std::cout << g.getConnectedComponents(); - return 0; + graph g(4); + g.addEdge(1, 2); + g.addEdge(3, 2); + std::cout << g.getConnectedComponents(); + return 0; } diff --git a/graph/connected_components_with_dsu.cpp b/graph/connected_components_with_dsu.cpp index 2c5c6dab55b..aa03bef8f11 100644 --- a/graph/connected_components_with_dsu.cpp +++ b/graph/connected_components_with_dsu.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include int N; // denotes number of nodes; std::vector parent; @@ -31,8 +31,7 @@ void union_sets(int a, int b) { // To join 2 components to belong to one int no_of_connected_components() { // To find total no of connected components std::set temp; // temp set to count number of connected components - for (int i = 1; i <= N; i++) - temp.insert(find_set(i)); + for (int i = 1; i <= N; i++) temp.insert(find_set(i)); return temp.size(); } diff --git a/graph/cycle_check_directed_graph.cpp b/graph/cycle_check_directed_graph.cpp new file mode 100644 index 00000000000..0f7b84cd303 --- /dev/null +++ b/graph/cycle_check_directed_graph.cpp @@ -0,0 +1,302 @@ +/** + * Copyright 2020 + * @file cycle_check_directed graph.cpp + * + * @brief BFS and DFS algorithms to check for cycle in a directed graph. + * + * @author Anmol3299 + * contact: mittalanmol22@gmail.com + * + */ + +#include // for std::cout +#include // for std::queue +#include // for throwing errors +#include // for std::remove_reference_t +#include // for std::unordered_map +#include // for std::move +#include // for std::vector + +/** + * Implementation of non-weighted directed edge of a graph. + * + * The source vertex of the edge is labelled "src" and destination vertex is + * labelled "dest". + */ +struct Edge { + unsigned int src; + unsigned int dest; + + Edge() = delete; + ~Edge() = default; + Edge(Edge&&) = default; + Edge& operator=(Edge&&) = default; + Edge(Edge const&) = default; + Edge& operator=(Edge const&) = default; + + /** Set the source and destination of the vertex. + * + * @param source is the source vertex of the edge. + * @param destination is the destination vertex of the edge. + */ + Edge(unsigned int source, unsigned int destination) + : src(source), dest(destination) {} +}; + +using AdjList = std::unordered_map>; + +/** + * Implementation of graph class. + * + * The graph will be represented using Adjacency List representation. + * This class contains 2 data members "m_vertices" & "m_adjList" used to + * represent the number of vertices and adjacency list of the graph + * respectively. The vertices are labelled 0 - (m_vertices - 1). + */ +class Graph { + public: + Graph() : m_vertices(0), m_adjList({}) {} + ~Graph() = default; + Graph(Graph&&) = default; + Graph& operator=(Graph&&) = default; + Graph(Graph const&) = default; + Graph& operator=(Graph const&) = default; + + /** Create a graph from vertices and adjacency list. + * + * @param vertices specify the number of vertices the graph would contain. + * @param adjList is the adjacency list representation of graph. + */ + Graph(unsigned int vertices, AdjList const& adjList) + : m_vertices(vertices), m_adjList(adjList) {} + + /** Create a graph from vertices and adjacency list. + * + * @param vertices specify the number of vertices the graph would contain. + * @param adjList is the adjacency list representation of graph. + */ + Graph(unsigned int vertices, AdjList&& adjList) + : m_vertices(std::move(vertices)), m_adjList(std::move(adjList)) {} + + /** Create a graph from vertices and a set of edges. + * + * Adjacency list of the graph would be created from the set of edges. If + * the source or destination of any edge has a value greater or equal to + * number of vertices, then it would throw a range_error. + * + * @param vertices specify the number of vertices the graph would contain. + * @param edges is a vector of edges. + */ + Graph(unsigned int vertices, std::vector const& edges) + : m_vertices(vertices) { + for (auto const& edge : edges) { + if (edge.src >= vertices || edge.dest >= vertices) { + throw std::range_error( + "Either src or dest of edge out of range"); + } + m_adjList[edge.src].emplace_back(edge.dest); + } + } + + /** Return a const reference of the adjacency list. + * + * @return const reference to the adjacency list + */ + std::remove_reference_t const& getAdjList() const { + return m_adjList; + } + + /** + * @return number of vertices in the graph. + */ + std::remove_reference_t const& getVertices() const { + return m_vertices; + } + + /** Add vertices in the graph. + * + * @param num is the number of vertices to be added. It adds 1 vertex by + * default. + * + */ + void addVertices(unsigned int num = 1) { m_vertices += num; } + + /** Add an edge in the graph. + * + * @param edge that needs to be added. + */ + void addEdge(Edge const& edge) { + if (edge.src >= m_vertices || edge.dest >= m_vertices) { + throw std::range_error("Either src or dest of edge out of range"); + } + m_adjList[edge.src].emplace_back(edge.dest); + } + + /** Add an Edge in the graph + * + * @param source is source vertex of the edge. + * @param destination is the destination vertex of the edge. + */ + void addEdge(unsigned int source, unsigned int destination) { + if (source >= m_vertices || destination >= m_vertices) { + throw std::range_error( + "Either source or destination of edge out of range"); + } + m_adjList[source].emplace_back(destination); + } + + private: + unsigned int m_vertices; + AdjList m_adjList; +}; + +class CycleCheck { + private: + enum nodeStates : uint8_t { not_visited = 0, in_stack, visited }; + + /** Helper function of "isCyclicDFS". + * + * @param adjList is the adjacency list representation of some graph. + * @param state is the state of the nodes of the graph. + * @param node is the node being evaluated. + * + * @return true if graph has a cycle, else false. + */ + static bool isCyclicDFSHelper(AdjList const& adjList, + std::vector* state, + unsigned int node) { + // Add node "in_stack" state. + (*state)[node] = in_stack; + + // If the node has children, then recursively visit all children of the + // node. + if (auto const& it = adjList.find(node); it != adjList.end()) { + for (auto child : it->second) { + // If state of child node is "not_visited", evaluate that child + // for presence of cycle. + if (auto state_of_child = (*state)[child]; + state_of_child == not_visited) { + if (isCyclicDFSHelper(adjList, state, child)) { + return true; + } + } else if (state_of_child == in_stack) { + // If child node was "in_stack", then that means that there + // is a cycle in the graph. Return true for presence of the + // cycle. + return true; + } + } + } + + // Current node has been evaluated for the presence of cycle and had no + // cycle. Mark current node as "visited". + (*state)[node] = visited; + // Return that current node didn't result in any cycles. + return false; + } + + public: + /** Driver function to check if a graph has a cycle. + * + * This function uses DFS to check for cycle in the graph. + * + * @param graph which needs to be evaluated for the presence of cycle. + * @return true if a cycle is detected, else false. + */ + static bool isCyclicDFS(Graph const& graph) { + /** State of the node. + * + * It is a vector of "nodeStates" which represents the state node is in. + * It can take only 3 values: "not_visited", "in_stack", and "visited". + * + * Initially, all nodes are in "not_visited" state. + */ + std::vector state(graph.getVertices(), not_visited); + + // Start visiting each node. + for (auto node = 0; node < graph.getVertices(); node++) { + // If a node is not visited, only then check for presence of cycle. + // There is no need to check for presence of cycle for a visited + // node as it has already been checked for presence of cycle. + if (state[node] == not_visited) { + // Check for cycle. + if (isCyclicDFSHelper(graph.getAdjList(), &state, node)) { + return true; + } + } + } + + // All nodes have been safely traversed, that means there is no cycle in + // the graph. Return false. + return false; + } + + /** Check if a graph has cycle or not. + * + * This function uses BFS to check if a graph is cyclic or not. + * + * @param graph which needs to be evaluated for the presence of cycle. + * @return true if a cycle is detected, else false. + */ + static bool isCyclicBFS(Graph const& graph) { + AdjList graphAjdList = graph.getAdjList(); + + std::vector indegree(graph.getVertices(), 0); + // Calculate the indegree i.e. the number of incident edges to the node. + for (auto const& [parent, children] : graphAjdList) { + for (auto const& child : children) { + indegree[child]++; + } + } + + std::queue can_be_solved; + for (auto node = 0; node < graph.getVertices(); node++) { + // If a node doesn't have any input edges, then that node will + // definately not result in a cycle and can be visited safely. + if (!indegree[node]) { + can_be_solved.emplace(node); + } + } + + // Vertices that need to be traversed. + auto remain = graph.getVertices(); + // While there are safe nodes that we can visit. + while (!can_be_solved.empty()) { + auto front = can_be_solved.front(); + // Visit the node. + can_be_solved.pop(); + // Decrease number of nodes that need to be traversed. + remain--; + + // Visit all the children of the visited node. + if (auto it = graphAjdList.find(front); it != graphAjdList.end()) { + for (auto child : it->second) { + // Check if we can visited the node safely. + if (--indegree[child] == 0) { + // if node can be visited safely, then add that node to + // the visit queue. + can_be_solved.emplace(child); + } + } + } + } + + // If there are still nodes that we can't visit, then it means that + // there is a cycle and return true, else return false. + return !(remain == 0); + } +}; + +/** + * Main function. + */ +int main() { + // Instantiate the graph. + Graph g(7, std::vector{{0, 1}, {1, 2}, {2, 0}, {2, 5}, {3, 5}}); + // Check for cycle using BFS method. + std::cout << CycleCheck::isCyclicBFS(g) << '\n'; + + // Check for cycle using DFS method. + std::cout << CycleCheck::isCyclicDFS(g) << '\n'; + return 0; +} diff --git a/graph/dfs.cpp b/graph/dfs.cpp new file mode 100644 index 00000000000..2d38c872507 --- /dev/null +++ b/graph/dfs.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +int v = 4; +void DFSUtil_(int graph[4][4], bool visited[], int s) { + visited[s] = true; + cout << s << " "; + for (int i = 0; i < v; i++) { + if (graph[s][i] == 1 && visited[i] == false) { + DFSUtil_(graph, visited, i); + } + } +} + +void DFS_(int graph[4][4], int s) { + bool visited[v]; + memset(visited, 0, sizeof(visited)); + DFSUtil_(graph, visited, s); +} + +int main() { + int graph[4][4] = {{0, 1, 1, 0}, {0, 0, 1, 0}, {1, 0, 0, 1}, {0, 0, 0, 1}}; + cout << "DFS: "; + DFS_(graph, 2); + cout << endl; + return 0; +} \ No newline at end of file diff --git a/graph/DFS_with_stack.cc b/graph/dfs_with_stack.cpp similarity index 74% rename from graph/DFS_with_stack.cc rename to graph/dfs_with_stack.cpp index cc67c75098e..193f3f291e5 100644 --- a/graph/DFS_with_stack.cc +++ b/graph/dfs_with_stack.cpp @@ -11,8 +11,7 @@ using namespace std; int checked[999] = {WHITE}; -void dfs(const list lista[], int start) -{ +void dfs(const list lista[], int start) { stack stack; int checked[999] = {WHITE}; @@ -20,33 +19,28 @@ void dfs(const list lista[], int start) stack.push(start); checked[start] = GREY; - while (!stack.empty()) - { + while (!stack.empty()) { int act = stack.top(); stack.pop(); - if (checked[act] == GREY) - { + if (checked[act] == GREY) { cout << act << ' '; - for (auto it = lista[act].begin(); it != lista[act].end(); ++it) - { + for (auto it = lista[act].begin(); it != lista[act].end(); ++it) { stack.push(*it); if (checked[*it] != BLACK) checked[*it] = GREY; } - checked[act] = BLACK; //nodo controllato + checked[act] = BLACK; // nodo controllato } } } -int main() -{ +int main() { int u, w; int n; cin >> n; list lista[INF]; - for (int i = 0; i < n; ++i) - { + for (int i = 0; i < n; ++i) { cin >> u >> w; lista[u].push_back(w); } diff --git a/graph/Dijkstra.cpp b/graph/dijkstra.cpp similarity index 67% rename from graph/Dijkstra.cpp rename to graph/dijkstra.cpp index b3ee44c416c..650f0cd51cb 100644 --- a/graph/Dijkstra.cpp +++ b/graph/dijkstra.cpp @@ -1,49 +1,46 @@ -#include -#include #include #include +#include +#include using namespace std; #define INF 10000010 vector> graph[5 * 100001]; int dis[5 * 100001]; -int dij(vector> *v, int s, int *dis) -{ - priority_queue, vector>, greater>> pq; +int dij(vector> *v, int s, int *dis) { + priority_queue, vector>, + greater>> + pq; // source distance to zero. pq.push(make_pair(0, s)); dis[s] = 0; int u; - while (!pq.empty()) - { + while (!pq.empty()) { u = (pq.top()).second; pq.pop(); - for (vector>::iterator it = v[u].begin(); it != v[u].end(); it++) - { - if (dis[u] + it->first < dis[it->second]) - { + for (vector>::iterator it = v[u].begin(); + it != v[u].end(); it++) { + if (dis[u] + it->first < dis[it->second]) { dis[it->second] = dis[u] + it->first; pq.push(make_pair(dis[it->second], it->second)); } } } } -int main() -{ +int main() { int m, n, l, x, y, s; // n--> number of nodes , m --> number of edges cin >> n >> m; - for (int i = 0; i < m; i++) - { + for (int i = 0; i < m; i++) { // input edges. scanf("%d%d%d", &x, &y, &l); graph[x].push_back(make_pair(l, y)); - graph[y].push_back(make_pair(l, x)); // comment this line for directed graph + graph[y].push_back( + make_pair(l, x)); // comment this line for directed graph } // start node. scanf("%d", &s); // intialise all distances to infinity. - for (int i = 1; i <= n; i++) - dis[i] = INF; + for (int i = 1; i <= n; i++) dis[i] = INF; dij(graph, s, dis); for (int i = 1; i <= n; i++) diff --git a/graph/kosaraju.cpp b/graph/kosaraju.cpp index 2e66f131fe5..00c9d7ca022 100644 --- a/graph/kosaraju.cpp +++ b/graph/kosaraju.cpp @@ -1,134 +1,121 @@ -/* Implementation of Kosaraju's Algorithm to find out the strongly connected components (SCCs) in a graph. - Author:Anirban166 -*/ +/* Implementation of Kosaraju's Algorithm to find out the strongly connected + components (SCCs) in a graph. Author:Anirban166 +*/ -#include -#include +#include +#include using namespace std; /** -* Iterative function/method to print graph: -* @param a[] : array of vectors (2D) -* @param V : vertices -* @return void -**/ -void print(vector a[],int V) -{ - for(int i=0;i"; - for(int j=0;j a[], int V) { + for (int i = 0; i < V; i++) { + if (!a[i].empty()) + cout << "i=" << i << "-->"; + for (int j = 0; j < a[i].size(); j++) cout << a[i][j] << " "; + if (!a[i].empty()) + cout << endl; } } /** -* //Recursive function/method to push vertices into stack passed as parameter: -* @param v : vertices -* @param &st : stack passed by reference -* @param vis[] : array to keep track of visited nodes (boolean type) -* @param adj[] : array of vectors to represent graph -* @return void -**/ -void push_vertex(int v,stack &st,bool vis[],vector adj[]) -{ - vis[v]=true; - for(auto i=adj[v].begin();i!=adj[v].end();i++) - { - if(vis[*i]==false) - push_vertex(*i,st,vis,adj); + * //Recursive function/method to push vertices into stack passed as parameter: + * @param v : vertices + * @param &st : stack passed by reference + * @param vis[] : array to keep track of visited nodes (boolean type) + * @param adj[] : array of vectors to represent graph + * @return void + **/ +void push_vertex(int v, stack &st, bool vis[], vector adj[]) { + vis[v] = true; + for (auto i = adj[v].begin(); i != adj[v].end(); i++) { + if (vis[*i] == false) + push_vertex(*i, st, vis, adj); } st.push(v); } - /** -* //Recursive function/method to implement depth first traversal(dfs): -* @param v : vertices -* @param vis[] : array to keep track of visited nodes (boolean type) -* @param grev[] : graph with reversed edges -* @return void -**/ -void dfs(int v,bool vis[],vector grev[]) -{ - vis[v]=true; + * //Recursive function/method to implement depth first traversal(dfs): + * @param v : vertices + * @param vis[] : array to keep track of visited nodes (boolean type) + * @param grev[] : graph with reversed edges + * @return void + **/ +void dfs(int v, bool vis[], vector grev[]) { + vis[v] = true; // cout<0)) - i.e. it returns the count of (number of) strongly connected components (SCCs) in the graph. (variable 'count_scc' within function) +* @return int ( 0, 1, 2..and so on, only unsigned values as either there can be +no SCCs i.e. none(0) or there will be x no. of SCCs (x>0)) i.e. it returns the +count of (number of) strongly connected components (SCCs) in the graph. +(variable 'count_scc' within function) **/ -int kosaraju(int V, vector adj[]) -{ - bool vis[V]={}; +int kosaraju(int V, vector adj[]) { + bool vis[V] = {}; stack st; - for(int v=0;v grev[V]; - for(int i=0;i 57) && c != '-'); c = gc()) + ; + if (c == '-') { + neg = 1; + c = gc(); + } + for (; c > 47 && c < 58; c = gc()) { + x = (x << 1) + (x << 3) + c - 48; + } + if (neg) + x = -x; +} +void out(int n) { + int N = n, rev, count = 0; + rev = N; + if (N == 0) { + pc('0'); + return; + } + while ((rev % 10) == 0) { + count++; + rev /= 10; + } + rev = 0; + while (N != 0) { + rev = (rev << 3) + (rev << 1) + N % 10; + N /= 10; + } + while (rev != 0) { + pc(rev % 10 + '0'); + rev /= 10; + } + while (count--) pc('0'); +} +ll parent[mx], arr[mx], node, edge; +vector>> v; +void initial() { + int i; + rep(i, node + edge) parent[i] = i; +} +int root(int i) { + while (parent[i] != i) { + parent[i] = parent[parent[i]]; + i = parent[i]; + } + return i; +} +void join(int x, int y) { + int root_x = root(x); // Disjoint set union by rank + int root_y = root(y); + parent[root_x] = root_y; +} +ll kruskal() { + ll mincost = 0, i, x, y; + rep(i, edge) { + x = v[i].second.first; + y = v[i].second.second; + if (root(x) != root(y)) { + mincost += v[i].first; + join(x, y); + } + } + return mincost; +} +int main() { + fast; + while (1) { + int i, j, from, to, cost, totalcost = 0; + cin >> node >> edge; // Enter the nodes and edges + if (node == 0 && edge == 0) + break; // Enter 0 0 to break out + initial(); // Initialise the parent array + rep(i, edge) { + cin >> from >> to >> cost; + v.pb(mp(cost, mp(from, to))); + totalcost += cost; + } + sort(v.begin(), v.end()); + // rep(i,v.size()) + // cout< adj[N]; // Graph - int up[LG][N]; // build this table - int level[N]; // get the levels of all of them + vector adj[N]; // Graph + int up[LG][N]; // build this table + int level[N]; // get the levels of all of them - lca(int n_): n(n_) - { + lca(int n_) : n(n_) { memset(up, -1, sizeof(up)); memset(level, 0, sizeof(level)); - for (int i = 0; i < n - 1; ++i) - { + for (int i = 0; i < n - 1; ++i) { int a, b; cin >> a >> b; a--; @@ -31,77 +28,59 @@ struct lca dfs(0, -1); build(); } - void verify() - { - for (int i = 0; i < n; ++i) - { + void verify() { + for (int i = 0; i < n; ++i) { cout << i << " : level: " << level[i] << endl; } cout << endl; - for (int i = 0; i < LG; ++i) - { + for (int i = 0; i < LG; ++i) { cout << "Power:" << i << ": "; - for (int j = 0; j < n; ++j) - { + for (int j = 0; j < n; ++j) { cout << up[i][j] << " "; } cout << endl; } } - void build() - { - for (int i = 1; i < LG; ++i) - { - for (int j = 0; j < n; ++j) - { - if (up[i - 1][j] != -1) - { + void build() { + for (int i = 1; i < LG; ++i) { + for (int j = 0; j < n; ++j) { + if (up[i - 1][j] != -1) { up[i][j] = up[i - 1][up[i - 1][j]]; } } } } - void dfs(int node, int par) - { + void dfs(int node, int par) { up[0][node] = par; - for (auto i: adj[node]) - { - if (i != par) - { + for (auto i : adj[node]) { + if (i != par) { level[i] = level[node] + 1; dfs(i, node); } } } - int query(int u, int v) - { + int query(int u, int v) { u--; v--; - if (level[v] > level[u]) - { + if (level[v] > level[u]) { swap(u, v); } // u is at the bottom. int dist = level[u] - level[v]; // Go up this much distance - for (int i = LG - 1; i >= 0; --i) - { - if (dist & (1 << i)) - { + for (int i = LG - 1; i >= 0; --i) { + if (dist & (1 << i)) { u = up[i][u]; } } - if (u == v) - { + if (u == v) { return u; } assert(level[u] == level[v]); - for (int i = LG - 1; i >= 0; --i) - { - if (up[i][u] != up[i][v]) - { + for (int i = LG - 1; i >= 0; --i) { + if (up[i][u] != up[i][v]) { u = up[i][u]; v = up[i][v]; } @@ -111,10 +90,9 @@ struct lca } }; -int main() -{ - int n; // number of nodes in the tree. - lca l(n); // will take the input in the format given +int main() { + int n; // number of nodes in the tree. + lca l(n); // will take the input in the format given // n-1 edges of the form // a b // Use verify function to see. 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 ee394d9f09a..cbd6bc15c60 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,15 @@ * Copyright: 2020, Open-Source * Last Modified: May 25, 2020 */ -#include -#include -#include #include #include -#include #include -#include +#include +#include +#include +#include #include +#include // std::max capacity of node in graph const int MAXN = 505; class Graph { @@ -21,13 +21,13 @@ class Graph { int total_nodes; int total_edges, source, sink; int parent[MAXN]; - std::vector >edge_participated; - std::bitset visited; + std::vector > edge_participated; + std::bitset visited; int max_flow = 0; bool bfs(int source, int sink) { // to find the augmented - path memset(parent, -1, sizeof(parent)); visited.reset(); - std::queueq; + std::queue q; q.push(source); bool is_path_found = false; while (q.empty() == false && is_path_found == false) { @@ -49,9 +49,7 @@ class Graph { } public: - Graph() { - memset(residual_capacity, 0, sizeof(residual_capacity)); - } + Graph() { memset(residual_capacity, 0, sizeof(residual_capacity)); } void set_graph(void) { std::cin >> total_nodes >> total_edges >> source >> sink; for (int start, destination, capacity_, i = 0; i < total_edges; ++i) { @@ -71,7 +69,7 @@ class Graph { } current_node = sink; max_flow += flow; - while ( current_node != source ) { + while (current_node != source) { int parent_ = parent[current_node]; residual_capacity[parent_][current_node] -= flow; residual_capacity[current_node][parent_] += flow; @@ -83,23 +81,21 @@ class Graph { for (int i = 0; i < total_nodes; ++i) { for (int j = 0; j < total_nodes; ++j) { if (capacity[i][j] && - residual_capacity[i][j] < capacity[i][j]) { - edge_participated.push_back( - std::make_tuple(i, j, - capacity[i][j]-residual_capacity[i][j])); + residual_capacity[i][j] < capacity[i][j]) { + edge_participated.push_back(std::make_tuple( + i, j, capacity[i][j] - residual_capacity[i][j])); } } } - std::cout << "\nNodes : " << total_nodes - << "\nMax flow: " << max_flow - << "\nEdge present in flow: " << edge_participated.size() - << '\n'; - std::cout<< "\nSource\tDestination\tCapacity\total_nodes"; - for (auto&edge_data : edge_participated) { + std::cout << "\nNodes : " << total_nodes << "\nMax flow: " << max_flow + << "\nEdge present in flow: " << edge_participated.size() + << '\n'; + std::cout << "\nSource\tDestination\tCapacity\total_nodes"; + for (auto& edge_data : edge_participated) { int source, destination, capacity_; std::tie(source, destination, capacity_) = edge_data; - std::cout << source << "\t" << destination << "\t\t" - << capacity_ <<'\t'; + std::cout << source << "\t" << destination << "\t\t" << capacity_ + << '\t'; } } }; @@ -119,4 +115,3 @@ int main(void) { graph.print_flow_info(); return 0; } - diff --git a/graph/prim.cpp b/graph/prim.cpp index 2923b5b25fe..5cc70bd395b 100644 --- a/graph/prim.cpp +++ b/graph/prim.cpp @@ -1,22 +1,22 @@ // C++ program to implement Prim's Algorithm #include -#include #include +#include const int MAX = 1e4 + 5; -typedef std:: pair PII; +typedef std::pair PII; bool marked[MAX]; -std:: vector adj[MAX]; +std::vector adj[MAX]; int prim(int x) { // priority queue to maintain edges with respect to weights - std:: priority_queue, std:: greater > Q; + std::priority_queue, std::greater > Q; int y; int minimumCost = 0; PII p; - Q.push(std:: make_pair(0, x)); + Q.push(std::make_pair(0, x)); while (!Q.empty()) { // Select the edge with minimum weight p = Q.top(); @@ -40,19 +40,19 @@ int main() { int nodes, edges, x, y; int weight, minimumCost; - std:: cin >> nodes >> edges; // number of nodes & edges in graph + std::cin >> nodes >> edges; // number of nodes & edges in graph if (nodes == 0 || edges == 0) return 0; // Edges with their nodes & weight for (int i = 0; i < edges; ++i) { std::cin >> x >> y >> weight; - adj[x].push_back(std:: make_pair(weight, y)); - adj[y].push_back(std:: make_pair(weight, x)); + adj[x].push_back(std::make_pair(weight, y)); + adj[y].push_back(std::make_pair(weight, x)); } // Selecting 1 as the starting node minimumCost = prim(1); - std:: cout << minimumCost << std:: endl; + std::cout << minimumCost << std::endl; return 0; } diff --git a/graph/topological_sort.cpp b/graph/topological_sort.cpp new file mode 100644 index 00000000000..9e6c8917b59 --- /dev/null +++ b/graph/topological_sort.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +using namespace std; + +int n, m; // For number of Vertices (V) and number of edges (E) +vector> G; +vector visited; +vector ans; + +void dfs(int v) { + visited[v] = true; + for (int u : G[v]) { + if (!visited[u]) + dfs(u); + } + ans.push_back(v); +} + +void topological_sort() { + visited.assign(n, false); + ans.clear(); + for (int i = 0; i < n; ++i) { + if (!visited[i]) + dfs(i); + } + reverse(ans.begin(), ans.end()); +} +int main() { + cout << "Enter the number of vertices and the number of directed edges\n"; + cin >> n >> m; + int x, y; + G.resize(n, vector()); + for (int i = 0; i < n; ++i) { + cin >> x >> y; + x--, y--; // to convert 1-indexed to 0-indexed + G[x].push_back(y); + } + topological_sort(); + cout << "Topological Order : \n"; + for (int v : ans) { + cout << v + 1 + << ' '; // converting zero based indexing back to one based. + } + cout << '\n'; + return 0; +} diff --git a/graph/topological_sort_by_kahns_algo.cpp b/graph/topological_sort_by_kahns_algo.cpp index eda2a74bc5a..57ee01b237d 100644 --- a/graph/topological_sort_by_kahns_algo.cpp +++ b/graph/topological_sort_by_kahns_algo.cpp @@ -1,8 +1,8 @@ #include #include #include -#include #include +#include int *topoSortKahn(int N, std::vector adj[]); @@ -13,7 +13,7 @@ int main() { return 0; int u, v; - std::vectorgraph[nodes]; + std::vector graph[nodes]; // create graph // example // 6 6 @@ -31,23 +31,23 @@ int main() { } } -int* topoSortKahn(int V, std::vector adj[]) { - std::vectorvis(V+1, false); - std::vectordeg(V+1, 0); +int *topoSortKahn(int V, std::vector adj[]) { + std::vector vis(V + 1, false); + std::vector deg(V + 1, 0); for (int i = 0; i < V; i++) { for (int j = 0; j < adj[i].size(); j++) { deg[adj[i][j]]++; } } - std::queueq; + std::queue q; for (int i = 0; i < V; i++) { if (deg[i] == 0) { q.push(i); vis[i] = true; } } - int *arr = new int[V+1]; - memset(arr, 0, V+1); + int *arr = new int[V + 1]; + memset(arr, 0, V + 1); int count = 0; while (!q.empty()) { int cur = q.front(); diff --git a/greedy_algorithms/Knapsack.cpp b/greedy_algorithms/Knapsack.cpp deleted file mode 100644 index 2135bd1ebe9..00000000000 --- a/greedy_algorithms/Knapsack.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include -using namespace std; - -struct Item -{ - int weight; - int profit; -}; - -float profitPerUnit(Item x) -{ - return (float)x.profit / (float)x.weight; -} - -int partition(Item arr[], int low, int high) -{ - Item pivot = arr[high]; // pivot - int i = (low - 1); // Index of smaller element - - for (int j = low; j < high; j++) - { - // If current element is smaller than or - // equal to pivot - if (profitPerUnit(arr[j]) <= profitPerUnit(pivot)) - { - i++; // increment index of smaller element - Item temp = arr[i]; - arr[i] = arr[j]; - arr[j] = temp; - } - } - Item temp = arr[i + 1]; - arr[i + 1] = arr[high]; - arr[high] = temp; - return (i + 1); -} - -void quickSort(Item arr[], int low, int high) -{ - if (low < high) - { - - int p = partition(arr, low, high); - - quickSort(arr, low, p - 1); - quickSort(arr, p + 1, high); - } -} - -int main() -{ - cout << "\nEnter the capacity of the knapsack : "; - float capacity; - cin >> capacity; - cout << "\n Enter the number of Items : "; - int n; - cin >> n; - Item itemArray[n]; - for (int i = 0; i < n; i++) - { - cout << "\nEnter the weight and profit of item " << i + 1 << " : "; - cin >> itemArray[i].weight; - cin >> itemArray[i].profit; - } - - quickSort(itemArray, 0, n - 1); - - // show(itemArray, n); - - float maxProfit = 0; - int i = n; - while (capacity > 0 && --i >= 0) - { - if (capacity >= itemArray[i].weight) - { - maxProfit += itemArray[i].profit; - capacity -= itemArray[i].weight; - cout << "\n\t" << itemArray[i].weight << "\t" << itemArray[i].profit; - } - else - { - maxProfit += profitPerUnit(itemArray[i]) * capacity; - cout << "\n\t" << capacity << "\t" << profitPerUnit(itemArray[i]) * capacity; - capacity = 0; - break; - } - } - - cout << "\nMax Profit : " << maxProfit; - - return 0; -} diff --git a/greedy_algorithms/Kruskals Minimum Spanning Tree.cpp b/greedy_algorithms/Kruskals Minimum Spanning Tree.cpp deleted file mode 100644 index 951d4a88ac6..00000000000 --- a/greedy_algorithms/Kruskals Minimum Spanning Tree.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -using namespace std; - -#define V 6 -#define INFINITY 99999 - -int graph[V][V] = { - {0, 4, 1, 4, INFINITY, INFINITY}, - {4, 0, 3, 8, 3, INFINITY}, - {1, 3, 0, INFINITY, 1, INFINITY}, - {4, 8, INFINITY, 0, 5, 7}, - {INFINITY, 3, 1, 5, 0, INFINITY}, - {INFINITY, INFINITY, INFINITY, 7, INFINITY, 0}}; - -void findMinimumEdge() -{ - for (int i = 0; i < V; i++) - { - int min = INFINITY; - int minIndex = 0; - for (int j = 0; j < V; j++) - { - if (graph[i][j] != 0 && graph[i][j] < min) - { - min = graph[i][j]; - minIndex = j; - } - } - cout << i << " - " << minIndex << "\t" << graph[i][minIndex] << "\n"; - } -} - -int main() -{ - findMinimumEdge(); - return 0; -} diff --git a/greedy_algorithms/Prims Minimum Spanning Tree.cpp b/greedy_algorithms/Prims Minimum Spanning Tree.cpp deleted file mode 100644 index 769ca64e4de..00000000000 --- a/greedy_algorithms/Prims Minimum Spanning Tree.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include -using namespace std; - -#define V 4 -#define INFINITY 99999 - -int graph[V][V] = { - {0, 5, 1, 2}, - {5, 0, 3, 3}, - {1, 3, 0, 4}, - {2, 3, 4, 0}}; - -struct mst -{ - bool visited; - int key; - int near; -}; - -mst MST_Array[V]; - -void initilize() -{ - for (int i = 0; i < V; i++) - { - MST_Array[i].visited = false; - MST_Array[i].key = INFINITY; // considering INFINITY as inifinity - MST_Array[i].near = i; - } - - MST_Array[0].key = 0; -} - -void updateNear() -{ - for (int v = 0; v < V; v++) - { - int min = INFINITY; - int minIndex = 0; - for (int i = 0; i < V; i++) - { - if (MST_Array[i].key < min && MST_Array[i].visited == false && MST_Array[i].key != INFINITY) - { - min = MST_Array[i].key; - minIndex = i; - } - } - - MST_Array[minIndex].visited = true; - - for (int i = 0; i < V; i++) - { - if (graph[minIndex][i] != 0 && graph[minIndex][i] < INFINITY) - { - if (graph[minIndex][i] < MST_Array[i].key) - { - MST_Array[i].key = graph[minIndex][i]; - MST_Array[i].near = minIndex; - } - } - } - } -} - -void show() -{ - for (int i = 0; i < V; i++) - { - cout << i << " - " << MST_Array[i].near << "\t" << graph[i][MST_Array[i].near] << "\n"; - } -} - -int main() -{ - initilize(); - updateNear(); - show(); - return 0; -} diff --git a/greedy_algorithms/Dijkstra.cpp b/greedy_algorithms/dijkstra.cpp similarity index 53% rename from greedy_algorithms/Dijkstra.cpp rename to greedy_algorithms/dijkstra.cpp index 0c7fffc8cbf..e4450379c5d 100644 --- a/greedy_algorithms/Dijkstra.cpp +++ b/greedy_algorithms/dijkstra.cpp @@ -1,31 +1,25 @@ -#include #include +#include using namespace std; -//Wrapper class for storing a graph -class Graph -{ -public: +// Wrapper class for storing a graph +class Graph { + public: int vertexNum; int **edges; - //Constructs a graph with V vertices and E edges - Graph(const int V) - { - + // Constructs a graph with V vertices and E edges + Graph(const int V) { // initializes the array edges. this->edges = new int *[V]; - for (int i = 0; i < V; i++) - { + for (int i = 0; i < V; i++) { edges[i] = new int[V]; } // fills the array with zeros. - for (int i = 0; i < V; i++) - { - for (int j = 0; j < V; j++) - { + for (int i = 0; i < V; i++) { + for (int j = 0; j < V; j++) { edges[i][j] = 0; } } @@ -33,20 +27,16 @@ class Graph this->vertexNum = V; } - //Adds the given edge to the graph - void addEdge(int src, int dst, int weight) - { + // Adds the given edge to the graph + void addEdge(int src, int dst, int weight) { this->edges[src][dst] = weight; } }; -//Utility function to find minimum distance vertex in mdist -int minDistance(int mdist[], bool vset[], int V) -{ +// Utility function to find minimum distance vertex in mdist +int minDistance(int mdist[], bool vset[], int V) { int minVal = INT_MAX, minInd = 0; - for (int i = 0; i < V; i++) - { - if (!vset[i] && (mdist[i] < minVal)) - { + for (int i = 0; i < V; i++) { + if (!vset[i] && (mdist[i] < minVal)) { minVal = mdist[i]; minInd = i; } @@ -55,12 +45,10 @@ int minDistance(int mdist[], bool vset[], int V) return minInd; } -//Utility function to print distances -void print(int dist[], int V) -{ +// Utility function to print distances +void print(int dist[], int V) { cout << "\nVertex Distance" << endl; - for (int i = 0; i < V; i++) - { + for (int i = 0; i < V; i++) { if (dist[i] < INT_MAX) cout << i << "\t" << dist[i] << endl; else @@ -68,36 +56,32 @@ void print(int dist[], int V) } } -//The main function that finds the shortest path from given source -//to all other vertices using Dijkstra's Algorithm.It doesn't work on negative -//weights -void Dijkstra(Graph graph, int src) -{ +// The main function that finds the shortest path from given source +// to all other vertices using Dijkstra's Algorithm.It doesn't work on negative +// weights +void Dijkstra(Graph graph, int src) { int V = graph.vertexNum; - int mdist[V]; //Stores updated distances to vertex - bool vset[V]; // vset[i] is true if the vertex i included + int mdist[V]; // Stores updated distances to vertex + bool vset[V]; // vset[i] is true if the vertex i included // in the shortest path tree - //Initialise mdist and vset. Set distance of source as zero - for (int i = 0; i < V; i++) - { + // Initialise mdist and vset. Set distance of source as zero + for (int i = 0; i < V; i++) { mdist[i] = INT_MAX; vset[i] = false; } mdist[src] = 0; - //iterate to find shortest path - for (int count = 0; count < V - 1; count++) - { + // iterate to find shortest path + for (int count = 0; count < V - 1; count++) { int u = minDistance(mdist, vset, V); vset[u] = true; - for (int v = 0; v < V; v++) - { - if (!vset[v] && graph.edges[u][v] && mdist[u] + graph.edges[u][v] < mdist[v]) - { + for (int v = 0; v < V; v++) { + if (!vset[v] && graph.edges[u][v] && + mdist[u] + graph.edges[u][v] < mdist[v]) { mdist[v] = mdist[u] + graph.edges[u][v]; } } @@ -106,9 +90,8 @@ void Dijkstra(Graph graph, int src) print(mdist, V); } -//Driver Function -int main() -{ +// Driver Function +int main() { int V, E, gsrc; int src, dst, weight; cout << "Enter number of vertices: "; @@ -116,8 +99,7 @@ int main() cout << "Enter number of edges: "; cin >> E; Graph G(V); - for (int i = 0; i < E; i++) - { + for (int i = 0; i < E; i++) { cout << "\nEdge " << i + 1 << "\nEnter source: "; cin >> src; cout << "Enter destination: "; @@ -126,12 +108,9 @@ int main() cin >> weight; // makes sure source and destionation are in the proper bounds. - if (src >= 0 && src < V && dst >= 0 && dst < V) - { + if (src >= 0 && src < V && dst >= 0 && dst < V) { G.addEdge(src, dst, weight); - } - else - { + } else { cout << "source and/or destination out of bounds" << endl; i--; continue; diff --git a/greedy_algorithms/huffman.cpp b/greedy_algorithms/huffman.cpp index 253d8d0b520..21c8295f3dd 100644 --- a/greedy_algorithms/huffman.cpp +++ b/greedy_algorithms/huffman.cpp @@ -1,109 +1,100 @@ -// C++ program for Huffman Coding +// C++ program for Huffman Coding #include -#include -using namespace std; - -// A Huffman tree node -struct MinHeapNode { - - // One of the input characters - char data; - - // Frequency of the character - unsigned freq; - - // Left and right child - MinHeapNode *left, *right; - - MinHeapNode(char data, unsigned freq) - - { - - left = right = NULL; - this->data = data; - this->freq = freq; - } -}; - -// For comparison of -// two heap nodes (needed in min heap) -struct compare { - - bool operator()(MinHeapNode* l, MinHeapNode* r) - - { - return (l->freq > r->freq); - } -}; - -// Prints huffman codes from -// the root of Huffman Tree. -void printCodes(struct MinHeapNode* root, string str) -{ - - if (!root) - return; - - if (root->data != '$') - cout << root->data << ": " << str << "\n"; - - printCodes(root->left, str + "0"); - printCodes(root->right, str + "1"); -} - -// The main function that builds a Huffman Tree and -// print codes by traversing the built Huffman Tree -void HuffmanCodes(char data[], int freq[], int size) -{ - struct MinHeapNode *left, *right, *top; - - // Create a min heap & inserts all characters of data[] - priority_queue, compare> minHeap; - - for (int i = 0; i < size; ++i) - minHeap.push(new MinHeapNode(data[i], freq[i])); - - // Iterate while size of heap doesn't become 1 - while (minHeap.size() != 1) { - - // Extract the two minimum - // freq items from min heap - left = minHeap.top(); - minHeap.pop(); - - right = minHeap.top(); - minHeap.pop(); - - // Create a new internal node with - // frequency equal to the sum of the - // two nodes frequencies. Make the - // two extracted node as left and right children - // of this new node. Add this node - // to the min heap '$' is a special value - // for internal nodes, not used - top = new MinHeapNode('$', left->freq + right->freq); - - top->left = left; - top->right = right; - - minHeap.push(top); - } - - // Print Huffman codes using - // the Huffman tree built above - printCodes(minHeap.top(), ""); -} - -// Driver program to test above functions -int main() -{ - - char arr[] = { 'a', 'b', 'c', 'd', 'e', 'f' }; - int freq[] = { 5, 9, 12, 13, 16, 45 }; - - int size = sizeof(arr) / sizeof(arr[0]); - - HuffmanCodes(arr, freq, size); - - return 0; -} +#include +using namespace std; + +// A Huffman tree node +struct MinHeapNode { + // One of the input characters + char data; + + // Frequency of the character + unsigned freq; + + // Left and right child + MinHeapNode *left, *right; + + MinHeapNode(char data, unsigned freq) + + { + left = right = NULL; + this->data = data; + this->freq = freq; + } +}; + +// For comparison of +// two heap nodes (needed in min heap) +struct compare { + bool operator()(MinHeapNode* l, MinHeapNode* r) + + { + return (l->freq > r->freq); + } +}; + +// Prints huffman codes from +// the root of Huffman Tree. +void printCodes(struct MinHeapNode* root, string str) { + if (!root) + return; + + if (root->data != '$') + cout << root->data << ": " << str << "\n"; + + printCodes(root->left, str + "0"); + printCodes(root->right, str + "1"); +} + +// The main function that builds a Huffman Tree and +// print codes by traversing the built Huffman Tree +void HuffmanCodes(char data[], int freq[], int size) { + struct MinHeapNode *left, *right, *top; + + // Create a min heap & inserts all characters of data[] + priority_queue, compare> minHeap; + + for (int i = 0; i < size; ++i) + minHeap.push(new MinHeapNode(data[i], freq[i])); + + // Iterate while size of heap doesn't become 1 + while (minHeap.size() != 1) { + // Extract the two minimum + // freq items from min heap + left = minHeap.top(); + minHeap.pop(); + + right = minHeap.top(); + minHeap.pop(); + + // Create a new internal node with + // frequency equal to the sum of the + // two nodes frequencies. Make the + // two extracted node as left and right children + // of this new node. Add this node + // to the min heap '$' is a special value + // for internal nodes, not used + top = new MinHeapNode('$', left->freq + right->freq); + + top->left = left; + top->right = right; + + minHeap.push(top); + } + + // Print Huffman codes using + // the Huffman tree built above + printCodes(minHeap.top(), ""); +} + +// Driver program to test above functions +int main() { + char arr[] = {'a', 'b', 'c', 'd', 'e', 'f'}; + int freq[] = {5, 9, 12, 13, 16, 45}; + + int size = sizeof(arr) / sizeof(arr[0]); + + HuffmanCodes(arr, freq, size); + + return 0; +} diff --git a/greedy_algorithms/knapsack.cpp b/greedy_algorithms/knapsack.cpp new file mode 100644 index 00000000000..74be4fee0e0 --- /dev/null +++ b/greedy_algorithms/knapsack.cpp @@ -0,0 +1,78 @@ +#include +using namespace std; + +struct Item { + int weight; + int profit; +}; + +float profitPerUnit(Item x) { return (float)x.profit / (float)x.weight; } + +int partition(Item arr[], int low, int high) { + Item pivot = arr[high]; // pivot + int i = (low - 1); // Index of smaller element + + for (int j = low; j < high; j++) { + // If current element is smaller than or + // equal to pivot + if (profitPerUnit(arr[j]) <= profitPerUnit(pivot)) { + i++; // increment index of smaller element + Item temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + } + Item temp = arr[i + 1]; + arr[i + 1] = arr[high]; + arr[high] = temp; + return (i + 1); +} + +void quickSort(Item arr[], int low, int high) { + if (low < high) { + int p = partition(arr, low, high); + + quickSort(arr, low, p - 1); + quickSort(arr, p + 1, high); + } +} + +int main() { + cout << "\nEnter the capacity of the knapsack : "; + float capacity; + cin >> capacity; + cout << "\n Enter the number of Items : "; + int n; + cin >> n; + Item itemArray[n]; + for (int i = 0; i < n; i++) { + cout << "\nEnter the weight and profit of item " << i + 1 << " : "; + cin >> itemArray[i].weight; + cin >> itemArray[i].profit; + } + + quickSort(itemArray, 0, n - 1); + + // show(itemArray, n); + + float maxProfit = 0; + int i = n; + while (capacity > 0 && --i >= 0) { + if (capacity >= itemArray[i].weight) { + maxProfit += itemArray[i].profit; + capacity -= itemArray[i].weight; + cout << "\n\t" << itemArray[i].weight << "\t" + << itemArray[i].profit; + } else { + maxProfit += profitPerUnit(itemArray[i]) * capacity; + cout << "\n\t" << capacity << "\t" + << profitPerUnit(itemArray[i]) * capacity; + capacity = 0; + break; + } + } + + cout << "\nMax Profit : " << maxProfit; + + return 0; +} diff --git a/greedy_algorithms/kruskals_minimum_spanning_tree.cpp b/greedy_algorithms/kruskals_minimum_spanning_tree.cpp new file mode 100644 index 00000000000..9f35e86ac1f --- /dev/null +++ b/greedy_algorithms/kruskals_minimum_spanning_tree.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +#define V 6 +#define INFINITY 99999 + +int graph[V][V] = {{0, 4, 1, 4, INFINITY, INFINITY}, + {4, 0, 3, 8, 3, INFINITY}, + {1, 3, 0, INFINITY, 1, INFINITY}, + {4, 8, INFINITY, 0, 5, 7}, + {INFINITY, 3, 1, 5, 0, INFINITY}, + {INFINITY, INFINITY, INFINITY, 7, INFINITY, 0}}; + +void findMinimumEdge() { + for (int i = 0; i < V; i++) { + int min = INFINITY; + int minIndex = 0; + for (int j = 0; j < V; j++) { + if (graph[i][j] != 0 && graph[i][j] < min) { + min = graph[i][j]; + minIndex = j; + } + } + cout << i << " - " << minIndex << "\t" << graph[i][minIndex] << "\n"; + } +} + +int main() { + findMinimumEdge(); + return 0; +} diff --git a/greedy_algorithms/prims_minimum_spanning_tree.cpp b/greedy_algorithms/prims_minimum_spanning_tree.cpp new file mode 100644 index 00000000000..c804c176d8b --- /dev/null +++ b/greedy_algorithms/prims_minimum_spanning_tree.cpp @@ -0,0 +1,64 @@ +#include +using namespace std; + +#define V 4 +#define INFINITY 99999 + +int graph[V][V] = {{0, 5, 1, 2}, {5, 0, 3, 3}, {1, 3, 0, 4}, {2, 3, 4, 0}}; + +struct mst { + bool visited; + int key; + int near; +}; + +mst MST_Array[V]; + +void initilize() { + for (int i = 0; i < V; i++) { + MST_Array[i].visited = false; + MST_Array[i].key = INFINITY; // considering INFINITY as inifinity + MST_Array[i].near = i; + } + + MST_Array[0].key = 0; +} + +void updateNear() { + for (int v = 0; v < V; v++) { + int min = INFINITY; + int minIndex = 0; + for (int i = 0; i < V; i++) { + if (MST_Array[i].key < min && MST_Array[i].visited == false && + MST_Array[i].key != INFINITY) { + min = MST_Array[i].key; + minIndex = i; + } + } + + MST_Array[minIndex].visited = true; + + for (int i = 0; i < V; i++) { + if (graph[minIndex][i] != 0 && graph[minIndex][i] < INFINITY) { + if (graph[minIndex][i] < MST_Array[i].key) { + MST_Array[i].key = graph[minIndex][i]; + MST_Array[i].near = minIndex; + } + } + } + } +} + +void show() { + for (int i = 0; i < V; i++) { + cout << i << " - " << MST_Array[i].near << "\t" + << graph[i][MST_Array[i].near] << "\n"; + } +} + +int main() { + initilize(); + updateNear(); + show(); + return 0; +} diff --git a/hashing/Chaining.cpp b/hashing/Chaining.cpp deleted file mode 100644 index 55aa8961c79..00000000000 --- a/hashing/Chaining.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include -#include -using namespace std; - -struct Node -{ - int data; - struct Node *next; -} * head[100], *curr; - -void init() -{ - for (int i = 0; i < 100; i++) - head[i] = NULL; -} - -void add(int x, int h) -{ - struct Node *temp = new Node; - temp->data = x; - temp->next = NULL; - if (!head[h]) - { - head[h] = temp; - curr = head[h]; - } - else - { - curr = head[h]; - while (curr->next) - curr = curr->next; - curr->next = temp; - } -} - -void display(int mod) -{ - struct Node *temp; - int i; - for (i = 0; i < mod; i++) - { - if (!head[i]) - { - cout << "Key " << i << " is empty" << endl; - } - else - { - cout << "Key " << i << " has values = "; - temp = head[i]; - while (temp->next) - { - cout << temp->data << " "; - temp = temp->next; - } - cout << temp->data; - cout << endl; - } - } -} - -int hash(int x, int mod) -{ - return x % mod; -} - -void find(int x, int h) -{ - struct Node *temp = head[h]; - if (!head[h]) - { - cout << "Element not found"; - return; - } - while (temp->data != x && temp->next) - temp = temp->next; - if (temp->next) - cout << "Element found"; - else - { - if (temp->data == x) - cout << "Element found"; - else - cout << "Element not found"; - } -} - -int main(void) -{ - init(); - int c, x, mod, h; - cout << "Enter the size of Hash Table. = "; - cin >> mod; - bool loop = true; - while (loop) - { - cout << endl; - cout << "PLEASE CHOOSE -" << endl; - cout << "1. Add element." << endl; - cout << "2. Find element." << endl; - cout << "3. Generate Hash." << endl; - cout << "4. Display Hash table." << endl; - cout << "5. Exit." << endl; - cin >> c; - switch (c) - { - case 1: - cout << "Enter element to add = "; - cin >> x; - h = hash(x, mod); - h = fabs(h); - add(x, h); - break; - case 2: - cout << "Enter element to search = "; - cin >> x; - h = hash(x, mod); - find(x, h); - break; - case 3: - cout << "Enter element to generate hash = "; - cin >> x; - cout << "Hash of " << x << " is = " << hash(x, mod); - break; - case 4: - display(mod); - break; - default: - loop = false; - break; - } - cout << endl; - } - /*add(1,&head1); - add(2,&head1); - add(3,&head2); - add(5,&head1); - display(&head1); - display(&head2);*/ - return 0; -} \ No newline at end of file diff --git a/hashing/chaining.cpp b/hashing/chaining.cpp new file mode 100644 index 00000000000..6afd2d13b2c --- /dev/null +++ b/hashing/chaining.cpp @@ -0,0 +1,116 @@ +#include +#include +using namespace std; + +struct Node { + int data; + struct Node *next; +} * head[100], *curr; + +void init() { + for (int i = 0; i < 100; i++) head[i] = NULL; +} + +void add(int x, int h) { + struct Node *temp = new Node; + temp->data = x; + temp->next = NULL; + if (!head[h]) { + head[h] = temp; + curr = head[h]; + } else { + curr = head[h]; + while (curr->next) curr = curr->next; + curr->next = temp; + } +} + +void display(int mod) { + struct Node *temp; + int i; + for (i = 0; i < mod; i++) { + if (!head[i]) { + cout << "Key " << i << " is empty" << endl; + } else { + cout << "Key " << i << " has values = "; + temp = head[i]; + while (temp->next) { + cout << temp->data << " "; + temp = temp->next; + } + cout << temp->data; + cout << endl; + } + } +} + +int hash(int x, int mod) { return x % mod; } + +void find(int x, int h) { + struct Node *temp = head[h]; + if (!head[h]) { + cout << "Element not found"; + return; + } + while (temp->data != x && temp->next) temp = temp->next; + if (temp->next) + cout << "Element found"; + else { + if (temp->data == x) + cout << "Element found"; + else + cout << "Element not found"; + } +} + +int main(void) { + init(); + int c, x, mod, h; + cout << "Enter the size of Hash Table. = "; + cin >> mod; + bool loop = true; + while (loop) { + cout << endl; + cout << "PLEASE CHOOSE -" << endl; + cout << "1. Add element." << endl; + cout << "2. Find element." << endl; + cout << "3. Generate Hash." << endl; + cout << "4. Display Hash table." << endl; + cout << "5. Exit." << endl; + cin >> c; + switch (c) { + case 1: + cout << "Enter element to add = "; + cin >> x; + h = hash(x, mod); + h = fabs(h); + add(x, h); + break; + case 2: + cout << "Enter element to search = "; + cin >> x; + h = hash(x, mod); + find(x, h); + break; + case 3: + cout << "Enter element to generate hash = "; + cin >> x; + cout << "Hash of " << x << " is = " << hash(x, mod); + break; + case 4: + display(mod); + break; + default: + loop = false; + break; + } + cout << endl; + } + /*add(1,&head1); + add(2,&head1); + add(3,&head2); + add(5,&head1); + display(&head1); + display(&head2);*/ + return 0; +} \ No newline at end of file diff --git a/hashing/double_hash_hash_table.cpp b/hashing/double_hash_hash_table.cpp index 6030b7ff361..7ee2757ded9 100644 --- a/hashing/double_hash_hash_table.cpp +++ b/hashing/double_hash_hash_table.cpp @@ -1,13 +1,13 @@ // Copyright 2019 -#include -#include -#include -#include +#include +#include +#include +#include -using std::endl; -using std::cout; using std::cin; +using std::cout; +using std::endl; using std::string; // fwd declarations @@ -48,8 +48,8 @@ int doubleHash(int key, bool searching) { int i = 0; Entry entry; do { - int index = static_cast(fabs((hash + - (i * otherHashFxn(key))))) % totalSize; + int index = static_cast(fabs((hash + (i * otherHashFxn(key))))) % + totalSize; entry = table[index]; if (searching) { if (entry.key == notPresent) { @@ -63,12 +63,17 @@ int doubleHash(int key, bool searching) { i++; } else { if (putProber(entry, key)) { - if (!rehashing) cout << "Spot found!" << endl; + if (!rehashing) + cout << "Spot found!" << endl; return index; } - if (!rehashing) cout << "Spot taken, looking at next (next index:" - << " " << static_cast(fabs((hash + - (i * otherHashFxn(key))))) % totalSize << ")" << endl; + if (!rehashing) + cout << "Spot taken, looking at next (next index:" + << " " + << static_cast( + fabs((hash + (i * otherHashFxn(key))))) % + totalSize + << ")" << endl; i++; } if (i == totalSize * 100) { @@ -89,7 +94,8 @@ bool putProber(Entry entry, int key) { // Looks for a matching key bool searchingProber(Entry entry, int key) { - if (entry.key == key) return true; + if (entry.key == key) + return true; return false; } @@ -131,12 +137,12 @@ void rehash() { // Checks for load factor here void add(int key) { - Entry * entry = new Entry(); + Entry* entry = new Entry(); entry->key = key; int index = doubleHash(key, false); table[index] = *entry; // Load factor greater than 0.5 causes resizing - if (++size/ static_cast(totalSize) >= 0.5) { + if (++size / static_cast(totalSize) >= 0.5) { rehash(); } } @@ -157,8 +163,8 @@ void addInfo(int key) { cout << "Initial table: "; display(); cout << endl; - cout << "hash of " << key << " is " << hashFxn(key) - << " % " << totalSize << " == " << fabs(hashFxn(key) % totalSize); + cout << "hash of " << key << " is " << hashFxn(key) << " % " << totalSize + << " == " << fabs(hashFxn(key) % totalSize); cout << endl; add(key); cout << "New table: "; @@ -170,8 +176,8 @@ void removalInfo(int key) { cout << "Initial table: "; display(); cout << endl; - cout << "hash of " << key << " is " << hashFxn(key) - << " % " << totalSize << " == " << hashFxn(key) % totalSize; + cout << "hash of " << key << " is " << hashFxn(key) << " % " << totalSize + << " == " << hashFxn(key) % totalSize; cout << endl; remove(key); cout << "New table: "; diff --git a/hashing/linear_probing_hash_table.cpp b/hashing/linear_probing_hash_table.cpp index b00eb864109..393504c1d09 100644 --- a/hashing/linear_probing_hash_table.cpp +++ b/hashing/linear_probing_hash_table.cpp @@ -1,13 +1,13 @@ // Copyright 2019 -#include -#include -#include -#include +#include +#include +#include +#include -using std::endl; -using std::cout; using std::cin; +using std::cout; +using std::endl; using std::string; // fwd declarations @@ -56,10 +56,12 @@ int linearProbe(int key, bool searching) { i++; } else { if (putProber(entry, key)) { - if (!rehashing) cout << "Spot found!" << endl; + if (!rehashing) + cout << "Spot found!" << endl; return index; } - if (!rehashing) cout << "Spot taken, looking at next" << endl; + if (!rehashing) + cout << "Spot taken, looking at next" << endl; i++; } if (i == totalSize) { @@ -80,7 +82,8 @@ bool putProber(Entry entry, int key) { // Looks for a matching key bool searchingProber(Entry entry, int key) { - if (entry.key == key) return true; + if (entry.key == key) + return true; return false; } @@ -122,12 +125,12 @@ void rehash() { // Adds entry using linear probing. Checks for load factor here void add(int key) { - Entry * entry = new Entry(); + Entry* entry = new Entry(); entry->key = key; int index = linearProbe(key, false); table[index] = *entry; // Load factor greater than 0.5 causes resizing - if (++size/ static_cast(totalSize) >= 0.5) { + if (++size / static_cast(totalSize) >= 0.5) { rehash(); } } @@ -148,8 +151,8 @@ void addInfo(int key) { cout << "Initial table: "; display(); cout << endl; - cout << "hash of " << key << " is " << hashFxn(key) << " % " - << totalSize << " == " << fabs(hashFxn(key) % totalSize); + cout << "hash of " << key << " is " << hashFxn(key) << " % " << totalSize + << " == " << fabs(hashFxn(key) % totalSize); cout << endl; add(key); cout << "New table: "; @@ -161,8 +164,8 @@ void removalInfo(int key) { cout << "Initial table: "; display(); cout << endl; - cout << "hash of " << key << " is " << hashFxn(key) - << " % " << totalSize << " == " << hashFxn(key) % totalSize; + cout << "hash of " << key << " is " << hashFxn(key) << " % " << totalSize + << " == " << hashFxn(key) % totalSize; cout << endl; remove(key); cout << "New table: "; diff --git a/hashing/quadratic_probing_hash_table.cpp b/hashing/quadratic_probing_hash_table.cpp index 44e2e3b9f1b..971c2182dd5 100644 --- a/hashing/quadratic_probing_hash_table.cpp +++ b/hashing/quadratic_probing_hash_table.cpp @@ -1,14 +1,14 @@ // Copyright 2019 -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -using std::endl; -using std::cout; using std::cin; +using std::cout; +using std::endl; using std::string; // fwd declarations @@ -43,8 +43,8 @@ int quadraticProbe(int key, bool searching) { int i = 0; Entry entry; do { - int index = std::round(fabs((hash + - static_cast(std::round(std::pow(i, 2)))) % totalSize)); + int index = std::round(fabs( + (hash + static_cast(std::round(std::pow(i, 2)))) % totalSize)); entry = table[index]; if (searching) { if (entry.key == notPresent) { @@ -58,13 +58,16 @@ int quadraticProbe(int key, bool searching) { i++; } else { if (putProber(entry, key)) { - if (!rehashing) cout << "Spot found!" << endl; + if (!rehashing) + cout << "Spot found!" << endl; return index; } if (!rehashing) { - cout << "Spot taken, looking at next (next index = " << - std::round(fabs((hash + static_cast(std::round( - std::pow(i + 1, 2)))) % totalSize)) << endl; + cout << "Spot taken, looking at next (next index = " + << std::round(fabs((hash + static_cast(std::round( + std::pow(i + 1, 2)))) % + totalSize)) + << endl; } i++; } @@ -86,14 +89,16 @@ bool putProber(Entry entry, int key) { // Looks for a matching key bool searchingProber(Entry entry, int key) { - if (entry.key == key) return true; + if (entry.key == key) + return true; return false; } // Helper Entry find(int key) { int index = quadraticProbe(key, true); - if (index == notPresent) return Entry(); + if (index == notPresent) + return Entry(); return table[index]; } @@ -135,12 +140,12 @@ void rehash() { // Checks for load factor here void add(int key) { - Entry * entry = new Entry(); + Entry* entry = new Entry(); entry->key = key; int index = quadraticProbe(key, false); table[index] = *entry; // Load factor greater than 0.5 causes resizing - if (++size/ static_cast(totalSize) >= 0.5) { + if (++size / static_cast(totalSize) >= 0.5) { rehash(); } } @@ -161,8 +166,8 @@ void addInfo(int key) { cout << "Initial table: "; display(); cout << endl; - cout << "hash of " << key << " is " << hashFxn(key) << " % " - << totalSize << " == " << fabs(hashFxn(key) % totalSize); + cout << "hash of " << key << " is " << hashFxn(key) << " % " << totalSize + << " == " << fabs(hashFxn(key) % totalSize); cout << endl; add(key); cout << "New table: "; @@ -174,8 +179,8 @@ void removalInfo(int key) { cout << "Initial table: "; display(); cout << endl; - cout << "hash of " << key << " is " << hashFxn(key) - << " % " << totalSize << " == " << hashFxn(key) % totalSize; + cout << "hash of " << key << " is " << hashFxn(key) << " % " << totalSize + << " == " << hashFxn(key) % totalSize; cout << endl; remove(key); cout << "New table: "; diff --git a/machine_learning/CMakeLists.txt b/machine_learning/CMakeLists.txt new file mode 100644 index 00000000000..e6d8a9af405 --- /dev/null +++ b/machine_learning/CMakeLists.txt @@ -0,0 +1,18 @@ +# If necessary, use the RELATIVE flag, otherwise each source file may be listed +# with full pathname. RELATIVE may makes it easier to extract an executable name +# automatically. +file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) +# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) +foreach( testsourcefile ${APP_SOURCES} ) + # I used a simple string replace, to cut off .cpp. + string( REPLACE ".cpp" "" testname ${testsourcefile} ) + add_executable( ${testname} ${testsourcefile} ) + + set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) + if(OpenMP_CXX_FOUND) + target_link_libraries(${testname} OpenMP::OpenMP_CXX) + endif() + install(TARGETS ${testname} DESTINATION "bin/machine_learning") + +endforeach( testsourcefile ${APP_SOURCES} ) diff --git a/machine_learning/adaline_learning.cpp b/machine_learning/adaline_learning.cpp new file mode 100644 index 00000000000..1e25d3ba168 --- /dev/null +++ b/machine_learning/adaline_learning.cpp @@ -0,0 +1,351 @@ +/** + * \addtogroup machine_learning Machine Learning Algorithms + * @{ + * \file + * \brief [Adaptive Linear Neuron + * (ADALINE)](https://en.wikipedia.org/wiki/ADALINE) implementation + * + * \author [Krishna Vedala](https://github.com/kvedala) + * + * + * [source](https://commons.wikimedia.org/wiki/File:Adaline_flow_chart.gif) + * ADALINE is one of the first and simplest single layer artificial neural + * network. The algorithm essentially implements a linear function + * \f[ f\left(x_0,x_1,x_2,\ldots\right) = + * \sum_j x_jw_j+\theta + * \f] + * where \f$x_j\f$ are the input features of a sample, \f$w_j\f$ are the + * coefficients of the linear function and \f$\theta\f$ is a constant. If we + * know the \f$w_j\f$, then for any given set of features, \f$y\f$ can be + * computed. Computing the \f$w_j\f$ is a supervised learning algorithm wherein + * a set of features and their corresponding outputs are given and weights are + * computed using stochastic gradient descent method. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_ITER 500 // INT_MAX ///< Maximum number of iterations to learn + +/** \namespace machine_learning + * \brief Machine learning algorithms + */ +namespace machine_learning { +class adaline { + public: + /** + * Default constructor + * \param[in] num_features number of features present + * \param[in] eta learning rate (optional, default=0.1) + * \param[in] convergence accuracy (optional, + * default=\f$1\times10^{-5}\f$) + */ + adaline(int num_features, const double eta = 0.01f, + const double accuracy = 1e-5) + : eta(eta), accuracy(accuracy) { + if (eta <= 0) { + std::cerr << "learning rate should be positive and nonzero" + << std::endl; + std::exit(EXIT_FAILURE); + } + + weights = std::vector( + num_features + + 1); // additional weight is for the constant bias term + + // initialize with random weights in the range [-50, 49] + for (int i = 0; i < weights.size(); i++) weights[i] = 1.f; + // weights[i] = (static_cast(std::rand() % 100) - 50); + } + + /** + * Operator to print the weights of the model + */ + friend std::ostream &operator<<(std::ostream &out, const adaline &ada) { + out << "<"; + for (int i = 0; i < ada.weights.size(); i++) { + out << ada.weights[i]; + if (i < ada.weights.size() - 1) + out << ", "; + } + out << ">"; + return out; + } + + /** + * predict the output of the model for given set of features + * \param[in] x input vector + * \param[out] out optional argument to return neuron output before + * applying activation function (optional, `nullptr` to ignore) \returns + * model prediction output + */ + int predict(const std::vector &x, double *out = nullptr) { + if (!check_size_match(x)) + return 0; + + double y = weights.back(); // assign bias value + + // for (int i = 0; i < x.size(); i++) y += x[i] * weights[i]; + y = std::inner_product(x.begin(), x.end(), weights.begin(), y); + + if (out != nullptr) // if out variable is provided + *out = y; + + return activation(y); // quantizer: apply ADALINE threshold function + } + + /** + * Update the weights of the model using supervised learning for one + * feature vector \param[in] x feature vector \param[in] y known output + * value \returns correction factor + */ + double fit(const std::vector &x, const int &y) { + if (!check_size_match(x)) + return 0; + + /* output of the model with current weights */ + int p = predict(x); + int prediction_error = y - p; // error in estimation + double correction_factor = eta * prediction_error; + + /* update each weight, the last weight is the bias term */ + for (int i = 0; i < x.size(); i++) { + weights[i] += correction_factor * x[i]; + } + weights[x.size()] += correction_factor; // update bias + + return correction_factor; + } + + /** + * Update the weights of the model using supervised learning for an + * array of vectors. \param[in] X array of feature vector \param[in] y + * known output value for each feature vector + */ + template + void fit(std::vector const (&X)[N], const int *y) { + double avg_pred_error = 1.f; + + int iter; + for (iter = 0; (iter < MAX_ITER) && (avg_pred_error > accuracy); + iter++) { + avg_pred_error = 0.f; + + // perform fit for each sample + for (int i = 0; i < N; i++) { + double err = fit(X[i], y[i]); + avg_pred_error += std::abs(err); + } + avg_pred_error /= N; + + // Print updates every 200th iteration + // if (iter % 100 == 0) + std::cout << "\tIter " << iter << ": Training weights: " << *this + << "\tAvg error: " << avg_pred_error << std::endl; + } + + if (iter < MAX_ITER) + + std::cout << "Converged after " << iter << " iterations." + << std::endl; + else + std::cout << "Did not converge after " << iter << " iterations." + << std::endl; + } + + int activation(double x) { return x > 0 ? 1 : -1; } + + private: + /** + * convenient function to check if input feature vector size matches the + * model weights size + * \param[in] x fecture vector to check + * \returns `true` size matches + * \returns `false` size does not match + */ + bool check_size_match(const std::vector &x) { + if (x.size() != (weights.size() - 1)) { + std::cerr << __func__ << ": " + << "Number of features in x does not match the feature " + "dimension in model!" + << std::endl; + return false; + } + return true; + } + + const double eta; ///< learning rate of the algorithm + const double accuracy; ///< model fit convergence accuracy + std::vector weights; ///< weights of the neural network +}; + +} // namespace machine_learning + +using machine_learning::adaline; + +/** @} */ + +/** + * test function to predict points in a 2D coordinate system above the line + * \f$x=y\f$ as +1 and others as -1. + * Note that each point is defined by 2 values or 2 features. + * \param[in] eta learning rate (optional, default=0.01) + */ +void test1(double eta = 0.01) { + adaline ada(2, eta); // 2 features + + const int N = 10; // number of sample points + + std::vector X[N] = {{0, 1}, {1, -2}, {2, 3}, {3, -1}, + {4, 1}, {6, -5}, {-7, -3}, {-8, 5}, + {-9, 2}, {-10, -15}}; + int y[] = {1, -1, 1, -1, -1, -1, 1, 1, 1, -1}; // corresponding y-values + + std::cout << "------- Test 1 -------" << std::endl; + std::cout << "Model before fit: " << ada << std::endl; + + ada.fit(X, y); + std::cout << "Model after fit: " << ada << std::endl; + + int predict = ada.predict({5, -3}); + std::cout << "Predict for x=(5,-3): " << predict; + assert(predict == -1); + std::cout << " ...passed" << std::endl; + + predict = ada.predict({5, 8}); + std::cout << "Predict for x=(5,8): " << predict; + assert(predict == 1); + std::cout << " ...passed" << std::endl; +} + +/** + * test function to predict points in a 2D coordinate system above the line + * \f$x+3y=-1\f$ as +1 and others as -1. + * Note that each point is defined by 2 values or 2 features. + * The function will create random sample points for training and test purposes. + * \param[in] eta learning rate (optional, default=0.01) + */ +void test2(double eta = 0.01) { + adaline ada(2, eta); // 2 features + + const int N = 50; // number of sample points + + std::vector X[N]; + int Y[N]; // corresponding y-values + + // generate sample points in the interval + // [-range2/100 , (range2-1)/100] + int range = 500; // sample points full-range + int range2 = range >> 1; // sample points half-range + for (int i = 0; i < N; i++) { + double x0 = ((std::rand() % range) - range2) / 100.f; + double x1 = ((std::rand() % range) - range2) / 100.f; + X[i] = {x0, x1}; + Y[i] = (x0 + 3. * x1) > -1 ? 1 : -1; + } + + std::cout << "------- Test 2 -------" << std::endl; + std::cout << "Model before fit: " << ada << std::endl; + + ada.fit(X, Y); + std::cout << "Model after fit: " << ada << std::endl; + + int N_test_cases = 5; + for (int i = 0; i < N_test_cases; i++) { + double x0 = ((std::rand() % range) - range2) / 100.f; + double x1 = ((std::rand() % range) - range2) / 100.f; + + int predict = ada.predict({x0, x1}); + + std::cout << "Predict for x=(" << x0 << "," << x1 << "): " << predict; + + int expected_val = (x0 + 3. * x1) > -1 ? 1 : -1; + assert(predict == expected_val); + std::cout << " ...passed" << std::endl; + } +} + +/** + * test function to predict points in a 3D coordinate system lying within the + * sphere of radius 1 and centre at origin as +1 and others as -1. Note that + * each point is defined by 3 values but we use 6 features. The function will + * create random sample points for training and test purposes. + * The sphere centred at origin and radius 1 is defined as: + * \f$x^2+y^2+z^2=r^2=1\f$ and if the \f$r^2<1\f$, point lies within the sphere + * else, outside. + * + * \param[in] eta learning rate (optional, default=0.01) + */ +void test3(double eta = 0.01) { + adaline ada(6, eta); // 2 features + + const int N = 100; // number of sample points + + std::vector X[N]; + int Y[N]; // corresponding y-values + + // generate sample points in the interval + // [-range2/100 , (range2-1)/100] + int range = 200; // sample points full-range + int range2 = range >> 1; // sample points half-range + for (int i = 0; i < N; i++) { + double x0 = ((std::rand() % range) - range2) / 100.f; + double x1 = ((std::rand() % range) - range2) / 100.f; + double x2 = ((std::rand() % range) - range2) / 100.f; + X[i] = {x0, x1, x2, x0 * x0, x1 * x1, x2 * x2}; + Y[i] = ((x0 * x0) + (x1 * x1) + (x2 * x2)) <= 1.f ? 1 : -1; + } + + std::cout << "------- Test 3 -------" << std::endl; + std::cout << "Model before fit: " << ada << std::endl; + + ada.fit(X, Y); + std::cout << "Model after fit: " << ada << std::endl; + + int N_test_cases = 5; + for (int i = 0; i < N_test_cases; i++) { + double x0 = ((std::rand() % range) - range2) / 100.f; + double x1 = ((std::rand() % range) - range2) / 100.f; + double x2 = ((std::rand() % range) - range2) / 100.f; + + int predict = ada.predict({x0, x1, x2, x0 * x0, x1 * x1, x2 * x2}); + + std::cout << "Predict for x=(" << x0 << "," << x1 << "," << x2 + << "): " << predict; + + int expected_val = ((x0 * x0) + (x1 * x1) + (x2 * x2)) <= 1.f ? 1 : -1; + assert(predict == expected_val); + std::cout << " ...passed" << std::endl; + } +} + +/** Main function */ +int main(int argc, char **argv) { + std::srand(std::time(nullptr)); // initialize random number generator + + double eta = 0.1; // default value of eta + if (argc == 2) // read eta value from commandline argument if present + eta = strtof(argv[1], nullptr); + + test1(eta); + + std::cout << "Press ENTER to continue..." << std::endl; + std::cin.get(); + + test2(eta); + + std::cout << "Press ENTER to continue..." << std::endl; + std::cin.get(); + + test3(eta); + + return 0; +} diff --git a/machine_learning/kohonen_som_topology.cpp b/machine_learning/kohonen_som_topology.cpp new file mode 100644 index 00000000000..25c58e26072 --- /dev/null +++ b/machine_learning/kohonen_som_topology.cpp @@ -0,0 +1,595 @@ +/** + * \addtogroup machine_learning Machine Learning Algorithms + * @{ + * \file + * \author [Krishna Vedala](https://github.com/kvedala) + * \brief [Kohonen self organizing + * map](https://en.wikipedia.org/wiki/Self-organizing_map) (topological map) + * + * This example implements a powerful unsupervised learning algorithm called as + * a self organizing map. The algorithm creates a connected network of weights + * that closely follows the given data points. This thus creates a topological + * map of the given data i.e., it maintains the relationship between varipus + * data points in a much higher dimesional space by creating an equivalent in a + * 2-dimensional space. + * Trained topological maps for the test cases in the program + * \note This C++ version of the program is considerable slower than its [C + * counterpart](https://github.com/kvedala/C/blob/master/machine_learning/kohonen_som_trace.c) + * \note The compiled code is much slower when compiled with MS Visual C++ 2019 + * than with GCC on windows + * \see kohonen_som_trace.cpp + */ +#define _USE_MATH_DEFINES // required for MS Visual C++ +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef _OPENMP // check if OpenMP based parallellization is available +#include +#endif + +/** + * Helper function to generate a random number in a given interval. + * \n Steps: + * 1. `r1 = rand() % 100` gets a random number between 0 and 99 + * 2. `r2 = r1 / 100` converts random number to be between 0 and 0.99 + * 3. scale and offset the random number to given range of \f$[a,b]\f$ + * + * \param[in] a lower limit + * \param[in] b upper limit + * \returns random number in the range \f$[a,b]\f$ + */ +double _random(double a, double b) { + return ((b - a) * (std::rand() % 100) / 100.f) + a; +} + +/** + * Save a given n-dimensional data martix to file. + * + * \param[in] fname filename to save in (gets overwriten without confirmation) + * \param[in] X matrix to save + * \returns 0 if all ok + * \returns -1 if file creation failed + */ +int save_2d_data(const char *fname, + const std::vector> &X) { + size_t num_points = X.size(); // number of rows + size_t num_features = X[0].size(); // number of columns + + std::ofstream fp; + fp.open(fname); + if (!fp.is_open()) { + // error with opening file to write + std::cerr << "Error opening file " << fname << "\n"; + return -1; + } + + // for each point in the array + for (int i = 0; i < num_points; i++) { + // for each feature in the array + for (int j = 0; j < num_features; j++) { + fp << X[i][j]; // print the feature value + if (j < num_features - 1) // if not the last feature + fp << ","; // suffix comma + } + if (i < num_points - 1) // if not the last row + fp << "\n"; // start a new line + } + + fp.close(); + return 0; +} + +/** + * Get minimum value and index of the value in a matrix + * \param[in] X matrix to search + * \param[in] N number of points in the vector + * \param[out] val minimum value found + * \param[out] idx_x x-index where minimum value was found + * \param[out] idx_y y-index where minimum value was found + */ +void get_min_2d(const std::vector> &X, double *val, + int *x_idx, int *y_idx) { + val[0] = INFINITY; // initial min value + int N = X.size(); + + for (int i = 0; i < N; i++) { // traverse each x-index + auto result = std::min_element(std::begin(X[i]), std::end(X[i])); + double d_min = *result; + int j = std::distance(std::begin(X[i]), result); + + if (d_min < val[0]) { // if a lower value is found + // save the value and its index + x_idx[0] = i; + y_idx[0] = j; + val[0] = d_min; + } + } +} + +/** \namespace machine_learning + * \brief Machine learning algorithms + */ +namespace machine_learning { +#define MIN_DISTANCE 1e-4 ///< Minimum average distance of image nodes + +/** + * Create the distance matrix or + * [U-matrix](https://en.wikipedia.org/wiki/U-matrix) from the trained + * 3D weiths matrix and save to disk. + * + * \param [in] fname filename to save in (gets overwriten without + * confirmation) + * \param [in] W model matrix to save + * \returns 0 if all ok + * \returns -1 if file creation failed + */ +int save_u_matrix(const char *fname, + const std::vector>> &W) { + std::ofstream fp(fname); + if (!fp) { // error with fopen + char msg[120]; + std::snprintf(msg, sizeof(msg), "File error (%s): ", fname); + std::perror(msg); + return -1; + } + + // neighborhood range + unsigned int R = 1; + + for (int i = 0; i < W.size(); i++) { // for each x + for (int j = 0; j < W[0].size(); j++) { // for each y + double distance = 0.f; + + int from_x = std::max(0, i - R); + int to_x = std::min(W.size(), i + R + 1); + int from_y = std::max(0, j - R); + int to_y = std::min(W[0].size(), j + R + 1); + int l, m; +#ifdef _OPENMP +#pragma omp parallel for reduction(+ : distance) +#endif + for (l = from_x; l < to_x; l++) { // scan neighborhoor in x + for (m = from_y; m < to_y; m++) { // scan neighborhood in y + auto d = W[i][j] - W[l][m]; + double d2 = std::pow(d, 2).sum(); + distance += std::sqrt(d2); + // distance += d2; + } + } + + distance /= R * R; // mean distance from neighbors + fp << distance; // print the mean separation + if (j < W[0].size() - 1) { // if not the last column + fp << ','; // suffix comma + } + } + if (i < W.size() - 1) // if not the last row + fp << '\n'; // start a new line + } + + fp.close(); + return 0; +} + +/** + * Update weights of the SOM using Kohonen algorithm + * + * \param[in] X data point - N features + * \param[in,out] W weights matrix - PxQxN + * \param[in,out] D temporary vector to store distances PxQ + * \param[in] alpha learning rate \f$0<\alpha\le1\f$ + * \param[in] R neighborhood range + * \returns minimum distance of sample and trained weights + */ +double update_weights(const std::valarray &X, + std::vector>> *W, + std::vector> *D, double alpha, + int R) { + int x, y; + int num_out_x = static_cast(W->size()); // output nodes - in X + int num_out_y = static_cast(W[0][0].size()); // output nodes - in Y + int num_features = static_cast(W[0][0][0].size()); // features = in Z + double d_min = 0.f; + +#ifdef _OPENMP +#pragma omp for +#endif + // step 1: for each output point + for (x = 0; x < num_out_x; x++) { + for (y = 0; y < num_out_y; y++) { + (*D)[x][y] = 0.f; + // compute Euclidian distance of each output + // point from the current sample + auto d = ((*W)[x][y] - X); + (*D)[x][y] = (d * d).sum(); + (*D)[x][y] = std::sqrt((*D)[x][y]); + } + } + + // step 2: get closest node i.e., node with snallest Euclidian distance + // to the current pattern + int d_min_x, d_min_y; + get_min_2d(*D, &d_min, &d_min_x, &d_min_y); + + // step 3a: get the neighborhood range + int from_x = std::max(0, d_min_x - R); + int to_x = std::min(num_out_x, d_min_x + R + 1); + int from_y = std::max(0, d_min_y - R); + int to_y = std::min(num_out_y, d_min_y + R + 1); + + // step 3b: update the weights of nodes in the + // neighborhood +#ifdef _OPENMP +#pragma omp for +#endif + for (x = from_x; x < to_x; x++) { + for (y = from_y; y < to_y; y++) { + /* you can enable the following normalization if needed. + personally, I found it detrimental to convergence */ + // const double s2pi = sqrt(2.f * M_PI); + // double normalize = 1.f / (alpha * s2pi); + + /* apply scaling inversely proportional to distance from the + current node */ + double d2 = + (d_min_x - x) * (d_min_x - x) + (d_min_y - y) * (d_min_y - y); + double scale_factor = std::exp(-d2 / (2.f * alpha * alpha)); + + (*W)[x][y] += (X - (*W)[x][y]) * alpha * scale_factor; + } + } + return d_min; +} + +/** + * Apply incremental algorithm with updating neighborhood and learning + * rates on all samples in the given datset. + * + * \param[in] X data set + * \param[in,out] W weights matrix + * \param[in] alpha_min terminal value of alpha + */ +void kohonen_som(const std::vector> &X, + std::vector>> *W, + double alpha_min) { + int num_samples = X.size(); // number of rows + int num_features = X[0].size(); // number of columns + int num_out = W->size(); // output matrix size + int R = num_out >> 2, iter = 0; + double alpha = 1.f; + + std::vector> D(num_out); + for (int i = 0; i < num_out; i++) D[i] = std::valarray(num_out); + + double dmin = 1.f; // average minimum distance of all samples + double past_dmin = 1.f; // average minimum distance of all samples + double dmin_ratio = 1.f; // change per step + + // Loop alpha from 1 to slpha_min + for (; alpha > 0 && dmin_ratio > 1e-5; alpha -= 1e-4, iter++) { + // Loop for each sample pattern in the data set + for (int sample = 0; sample < num_samples; sample++) { + // update weights for the current input pattern sample + dmin += update_weights(X[sample], W, &D, alpha, R); + } + + // every 100th iteration, reduce the neighborhood range + if (iter % 300 == 0 && R > 1) + R--; + + dmin /= num_samples; + + // termination condition variable -> % change in minimum distance + dmin_ratio = (past_dmin - dmin) / past_dmin; + if (dmin_ratio < 0) + dmin_ratio = 1.f; + past_dmin = dmin; + + std::cout << "iter: " << iter << "\t alpha: " << alpha << "\t R: " << R + << "\t d_min: " << dmin_ratio << "\r"; + } + + std::cout << "\n"; +} + +} // namespace machine_learning + +using machine_learning::kohonen_som; +using machine_learning::save_u_matrix; + +/** @} */ + +/** Creates a random set of points distributed in four clusters in + * 3D space with centroids at the points + * * \f$(0,5, 0.5, 0.5)\f$ + * * \f$(0,5,-0.5, -0.5)\f$ + * * \f$(-0,5, 0.5, 0.5)\f$ + * * \f$(-0,5,-0.5, -0.5)\f$ + * + * \param[out] data matrix to store data in + */ +void test_2d_classes(std::vector> *data) { + const int N = data->size(); + const double R = 0.3; // radius of cluster + int i; + const int num_classes = 4; + const double centres[][2] = { + // centres of each class cluster + {.5, .5}, // centre of class 1 + {.5, -.5}, // centre of class 2 + {-.5, .5}, // centre of class 3 + {-.5, -.5} // centre of class 4 + }; + +#ifdef _OPENMP +#pragma omp for +#endif + for (i = 0; i < N; i++) { + // select a random class for the point + int cls = std::rand() % num_classes; + + // create random coordinates (x,y,z) around the centre of the class + data[0][i][0] = _random(centres[cls][0] - R, centres[cls][0] + R); + data[0][i][1] = _random(centres[cls][1] - R, centres[cls][1] + R); + + /* The follosing can also be used + for (int j = 0; j < 2; j++) + data[i][j] = _random(centres[class][j] - R, centres[class][j] + R); + */ + } +} + +/** Test that creates a random set of points distributed in four clusters in + * circumference of a circle and trains an SOM that finds that circular pattern. + * The following [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) + * files are created to validate the execution: + * * `test1.csv`: random test samples points with a circular pattern + * * `w11.csv`: initial random map + * * `w12.csv`: trained SOM map + */ +void test1() { + int j, N = 300; + int features = 2; + int num_out = 30; + std::vector> X(N); + std::vector>> W(num_out); + for (int i = 0; i < std::max(num_out, N); i++) { + // loop till max(N, num_out) + if (i < N) // only add new arrays if i < N + X[i] = std::valarray(features); + if (i < num_out) { // only add new arrays if i < num_out + W[i] = std::vector>(num_out); + for (int k = 0; k < num_out; k++) { + W[i][k] = std::valarray(features); +#ifdef _OPENMP +#pragma omp for +#endif + for (j = 0; j < features; j++) + // preallocate with random initial weights + W[i][k][j] = _random(-10, 10); + } + } + } + + test_2d_classes(&X); // create test data around circumference of a circle + save_2d_data("test1.csv", X); // save test data points + save_u_matrix("w11.csv", W); // save initial random weights + kohonen_som(X, &W, 1e-4); // train the SOM + save_u_matrix("w12.csv", W); // save the resultant weights +} + +/** Creates a random set of points distributed in four clusters in + * 3D space with centroids at the points + * * \f$(0,5, 0.5, 0.5)\f$ + * * \f$(0,5,-0.5, -0.5)\f$ + * * \f$(-0,5, 0.5, 0.5)\f$ + * * \f$(-0,5,-0.5, -0.5)\f$ + * + * \param[out] data matrix to store data in + */ +void test_3d_classes1(std::vector> *data) { + const int N = data->size(); + const double R = 0.3; // radius of cluster + int i; + const int num_classes = 4; + const double centres[][3] = { + // centres of each class cluster + {.5, .5, .5}, // centre of class 1 + {.5, -.5, -.5}, // centre of class 2 + {-.5, .5, .5}, // centre of class 3 + {-.5, -.5 - .5} // centre of class 4 + }; + +#ifdef _OPENMP +#pragma omp for +#endif + for (i = 0; i < N; i++) { + // select a random class for the point + int cls = std::rand() % num_classes; + + // create random coordinates (x,y,z) around the centre of the class + data[0][i][0] = _random(centres[cls][0] - R, centres[cls][0] + R); + data[0][i][1] = _random(centres[cls][1] - R, centres[cls][1] + R); + data[0][i][2] = _random(centres[cls][2] - R, centres[cls][2] + R); + + /* The follosing can also be used + for (int j = 0; j < 3; j++) + data[i][j] = _random(centres[class][j] - R, centres[class][j] + R); + */ + } +} + +/** Test that creates a random set of points distributed in 4 clusters in + * 3D space and trains an SOM that finds the topological pattern. The following + * [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) files are created + * to validate the execution: + * * `test2.csv`: random test samples points with a lamniscate pattern + * * `w21.csv`: initial random map + * * `w22.csv`: trained SOM map + */ +void test2() { + int j, N = 300; + int features = 3; + int num_out = 30; + std::vector> X(N); + std::vector>> W(num_out); + for (int i = 0; i < std::max(num_out, N); i++) { + // loop till max(N, num_out) + if (i < N) // only add new arrays if i < N + X[i] = std::valarray(features); + if (i < num_out) { // only add new arrays if i < num_out + W[i] = std::vector>(num_out); + for (int k = 0; k < num_out; k++) { + W[i][k] = std::valarray(features); +#ifdef _OPENMP +#pragma omp for +#endif + for (j = 0; j < features; j++) + // preallocate with random initial weights + W[i][k][j] = _random(-10, 10); + } + } + } + + test_3d_classes1(&X); // create test data around circumference of a circle + save_2d_data("test2.csv", X); // save test data points + save_u_matrix("w21.csv", W); // save initial random weights + kohonen_som(X, &W, 1e-4); // train the SOM + save_u_matrix("w22.csv", W); // save the resultant weights +} + +/** Creates a random set of points distributed in four clusters in + * 3D space with centroids at the points + * * \f$(0,5, 0.5, 0.5)\f$ + * * \f$(0,5,-0.5, -0.5)\f$ + * * \f$(-0,5, 0.5, 0.5)\f$ + * * \f$(-0,5,-0.5, -0.5)\f$ + * + * \param[out] data matrix to store data in + */ +void test_3d_classes2(std::vector> *data) { + const int N = data->size(); + const double R = 0.2; // radius of cluster + int i; + const int num_classes = 8; + const double centres[][3] = { + // centres of each class cluster + {.5, .5, .5}, // centre of class 1 + {.5, .5, -.5}, // centre of class 2 + {.5, -.5, .5}, // centre of class 3 + {.5, -.5, -.5}, // centre of class 4 + {-.5, .5, .5}, // centre of class 5 + {-.5, .5, -.5}, // centre of class 6 + {-.5, -.5, .5}, // centre of class 7 + {-.5, -.5, -.5} // centre of class 8 + }; + +#ifdef _OPENMP +#pragma omp for +#endif + for (i = 0; i < N; i++) { + // select a random class for the point + int cls = std::rand() % num_classes; + + // create random coordinates (x,y,z) around the centre of the class + data[0][i][0] = _random(centres[cls][0] - R, centres[cls][0] + R); + data[0][i][1] = _random(centres[cls][1] - R, centres[cls][1] + R); + data[0][i][2] = _random(centres[cls][2] - R, centres[cls][2] + R); + + /* The follosing can also be used + for (int j = 0; j < 3; j++) + data[i][j] = _random(centres[class][j] - R, centres[class][j] + R); + */ + } +} + +/** Test that creates a random set of points distributed in eight clusters in + * 3D space and trains an SOM that finds the topological pattern. The following + * [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) files are created + * to validate the execution: + * * `test3.csv`: random test samples points with a circular pattern + * * `w31.csv`: initial random map + * * `w32.csv`: trained SOM map + */ +void test3() { + int j, N = 500; + int features = 3; + int num_out = 30; + std::vector> X(N); + std::vector>> W(num_out); + for (int i = 0; i < std::max(num_out, N); i++) { + // loop till max(N, num_out) + if (i < N) // only add new arrays if i < N + X[i] = std::valarray(features); + if (i < num_out) { // only add new arrays if i < num_out + W[i] = std::vector>(num_out); + for (int k = 0; k < num_out; k++) { + W[i][k] = std::valarray(features); +#ifdef _OPENMP +#pragma omp for +#endif + for (j = 0; j < features; j++) + // preallocate with random initial weights + W[i][k][j] = _random(-10, 10); + } + } + } + + test_3d_classes2(&X); // create test data around circumference of a circle + save_2d_data("test3.csv", X); // save test data points + save_u_matrix("w31.csv", W); // save initial random weights + kohonen_som(X, &W, 1e-4); // train the SOM + save_u_matrix("w32.csv", W); // save the resultant weights +} + +/** + * Convert clock cycle difference to time in seconds + * + * \param[in] start_t start clock + * \param[in] end_t end clock + * \returns time difference in seconds + */ +double get_clock_diff(clock_t start_t, clock_t end_t) { + return static_cast(end_t - start_t) / CLOCKS_PER_SEC; +} + +/** Main function */ +int main(int argc, char **argv) { +#ifdef _OPENMP + std::cout << "Using OpenMP based parallelization\n"; +#else + std::cout << "NOT using OpenMP based parallelization\n"; +#endif + + std::srand(std::time(nullptr)); + + std::clock_t start_clk = std::clock(); + test1(); + auto end_clk = std::clock(); + std::cout << "Test 1 completed in " << get_clock_diff(start_clk, end_clk) + << " sec\n"; + + start_clk = std::clock(); + test2(); + end_clk = std::clock(); + std::cout << "Test 2 completed in " << get_clock_diff(start_clk, end_clk) + << " sec\n"; + + start_clk = std::clock(); + test3(); + end_clk = std::clock(); + std::cout << "Test 3 completed in " << get_clock_diff(start_clk, end_clk) + << " sec\n"; + + std::cout + << "(Note: Calculated times include: creating test sets, training " + "model and writing files to disk.)\n\n"; + return 0; +} diff --git a/machine_learning/kohonen_som_trace.cpp b/machine_learning/kohonen_som_trace.cpp new file mode 100644 index 00000000000..273a2a57c6c --- /dev/null +++ b/machine_learning/kohonen_som_trace.cpp @@ -0,0 +1,474 @@ +/** + * \addtogroup machine_learning Machine Learning Algorithms + * @{ + * \file + * \brief [Kohonen self organizing + * map](https://en.wikipedia.org/wiki/Self-organizing_map) (data tracing) + * + * This example implements a powerful self organizing map algorithm. + * The algorithm creates a connected network of weights that closely + * follows the given data points. This this creates a chain of nodes that + * resembles the given input shape. + * + * \author [Krishna Vedala](https://github.com/kvedala) + * + * \note This C++ version of the program is considerable slower than its [C + * counterpart](https://github.com/kvedala/C/blob/master/machine_learning/kohonen_som_trace.c) + * \note The compiled code is much slower when compiled with MS Visual C++ 2019 + * than with GCC on windows + * \see kohonen_som_topology.cpp + */ +#define _USE_MATH_DEFINES // required for MS Visual C++ +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef _OPENMP // check if OpenMP based parallellization is available +#include +#endif + +/** + * Helper function to generate a random number in a given interval. + * \n Steps: + * 1. `r1 = rand() % 100` gets a random number between 0 and 99 + * 2. `r2 = r1 / 100` converts random number to be between 0 and 0.99 + * 3. scale and offset the random number to given range of \f$[a,b]\f$ + * + * \param[in] a lower limit + * \param[in] b upper limit + * \returns random number in the range \f$[a,b]\f$ + */ +double _random(double a, double b) { + return ((b - a) * (std::rand() % 100) / 100.f) + a; +} + +/** + * Save a given n-dimensional data martix to file. + * + * \param[in] fname filename to save in (gets overwriten without confirmation) + * \param[in] X matrix to save + * \returns 0 if all ok + * \returns -1 if file creation failed + */ +int save_nd_data(const char *fname, + const std::vector> &X) { + size_t num_points = X.size(); // number of rows + size_t num_features = X[0].size(); // number of columns + + std::ofstream fp; + fp.open(fname); + if (!fp.is_open()) { + // error with opening file to write + std::cerr << "Error opening file " << fname << "\n"; + return -1; + } + + // for each point in the array + for (int i = 0; i < num_points; i++) { + // for each feature in the array + for (int j = 0; j < num_features; j++) { + fp << X[i][j]; // print the feature value + if (j < num_features - 1) // if not the last feature + fp << ","; // suffix comma + } + if (i < num_points - 1) // if not the last row + fp << "\n"; // start a new line + } + + fp.close(); + return 0; +} + +/** \namespace machine_learning + * \brief Machine learning algorithms + */ +namespace machine_learning { + +/** + * Update weights of the SOM using Kohonen algorithm + * + * \param[in] X data point + * \param[in,out] W weights matrix + * \param[in,out] D temporary vector to store distances + * \param[in] alpha learning rate \f$0<\alpha\le1\f$ + * \param[in] R neighborhood range + */ +void update_weights(const std::valarray &x, + std::vector> *W, + std::valarray *D, double alpha, int R) { + int j, k; + int num_out = W->size(); // number of SOM output nodes + int num_features = x.size(); // number of data features + +#ifdef _OPENMP +#pragma omp for +#endif + // step 1: for each output point + for (j = 0; j < num_out; j++) { + // compute Euclidian distance of each output + // point from the current sample + (*D)[j] = (((*W)[j] - x) * ((*W)[j] - x)).sum(); + } + + // step 2: get closest node i.e., node with snallest Euclidian distance to + // the current pattern + auto result = std::min_element(std::begin(*D), std::end(*D)); + double d_min = *result; + int d_min_idx = std::distance(std::begin(*D), result); + + // step 3a: get the neighborhood range + int from_node = std::max(0, d_min_idx - R); + int to_node = std::min(num_out, d_min_idx + R + 1); + + // step 3b: update the weights of nodes in the + // neighborhood +#ifdef _OPENMP +#pragma omp for +#endif + for (j = from_node; j < to_node; j++) + // update weights of nodes in the neighborhood + (*W)[j] += alpha * (x - (*W)[j]); +} + +/** + * Apply incremental algorithm with updating neighborhood and learning rates + * on all samples in the given datset. + * + * \param[in] X data set + * \param[in,out] W weights matrix + * \param[in] alpha_min terminal value of alpha + */ +void kohonen_som_tracer(const std::vector> &X, + std::vector> *W, + double alpha_min) { + int num_samples = X.size(); // number of rows + int num_features = X[0].size(); // number of columns + int num_out = W->size(); // number of rows + int R = num_out >> 2, iter = 0; + double alpha = 1.f; + + std::valarray D(num_out); + + // Loop alpha from 1 to slpha_min + for (; alpha > alpha_min; alpha -= 0.01, iter++) { + // Loop for each sample pattern in the data set + for (int sample = 0; sample < num_samples; sample++) { + // update weights for the current input pattern sample + update_weights(X[sample], W, &D, alpha, R); + } + + // every 10th iteration, reduce the neighborhood range + if (iter % 10 == 0 && R > 1) + R--; + } +} + +} // namespace machine_learning + +/** @} */ + +using machine_learning::kohonen_som_tracer; + +/** Creates a random set of points distributed *near* the circumference + * of a circle and trains an SOM that finds that circular pattern. The + * generating function is + * \f{eqnarray*}{ + * r &\in& [1-\delta r, 1+\delta r)\\ + * \theta &\in& [0, 2\pi)\\ + * x &=& r\cos\theta\\ + * y &=& r\sin\theta + * \f} + * + * \param[out] data matrix to store data in + */ +void test_circle(std::vector> *data) { + const int N = data->size(); + const double R = 0.75, dr = 0.3; + double a_t = 0., b_t = 2.f * M_PI; // theta random between 0 and 2*pi + double a_r = R - dr, b_r = R + dr; // radius random between R-dr and R+dr + int i; + +#ifdef _OPENMP +#pragma omp for +#endif + for (i = 0; i < N; i++) { + double r = _random(a_r, b_r); // random radius + double theta = _random(a_t, b_t); // random theta + data[0][i][0] = r * cos(theta); // convert from polar to cartesian + data[0][i][1] = r * sin(theta); + } +} + +/** Test that creates a random set of points distributed *near* the + * circumference of a circle and trains an SOM that finds that circular pattern. + * The following [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) + * files are created to validate the execution: + * * `test1.csv`: random test samples points with a circular pattern + * * `w11.csv`: initial random map + * * `w12.csv`: trained SOM map + * + * The outputs can be readily plotted in [gnuplot](https:://gnuplot.info) using + * the following snippet + * ```gnuplot + * set datafile separator ',' + * plot "test1.csv" title "original", \ + * "w11.csv" title "w1", \ + * "w12.csv" title "w2" + * ``` + * ![Sample execution + * output](https://raw.githubusercontent.com/TheAlgorithms/C-Plus-Plus/docs/images/machine_learning/kohonen/test1.svg) + */ +void test1() { + int j, N = 500; + int features = 2; + int num_out = 50; + std::vector> X(N); + std::vector> W(num_out); + for (int i = 0; i < std::max(num_out, N); i++) { + // loop till max(N, num_out) + if (i < N) // only add new arrays if i < N + X[i] = std::valarray(features); + if (i < num_out) { // only add new arrays if i < num_out + W[i] = std::valarray(features); + +#ifdef _OPENMP +#pragma omp for +#endif + for (j = 0; j < features; j++) + // preallocate with random initial weights + W[i][j] = _random(-1, 1); + } + } + + test_circle(&X); // create test data around circumference of a circle + save_nd_data("test1.csv", X); // save test data points + save_nd_data("w11.csv", W); // save initial random weights + kohonen_som_tracer(X, &W, 0.1); // train the SOM + save_nd_data("w12.csv", W); // save the resultant weights +} + +/** Creates a random set of points distributed *near* the locus + * of the [Lamniscate of + * Gerono](https://en.wikipedia.org/wiki/Lemniscate_of_Gerono). + * \f{eqnarray*}{ + * \delta r &=& 0.2\\ + * \delta x &\in& [-\delta r, \delta r)\\ + * \delta y &\in& [-\delta r, \delta r)\\ + * \theta &\in& [0, \pi)\\ + * x &=& \delta x + \cos\theta\\ + * y &=& \delta y + \frac{\sin(2\theta)}{2} + * \f} + * \param[out] data matrix to store data in + */ +void test_lamniscate(std::vector> *data) { + const int N = data->size(); + const double dr = 0.2; + int i; + +#ifdef _OPENMP +#pragma omp for +#endif + for (i = 0; i < N; i++) { + double dx = _random(-dr, dr); // random change in x + double dy = _random(-dr, dr); // random change in y + double theta = _random(0, M_PI); // random theta + data[0][i][0] = dx + cos(theta); // convert from polar to cartesian + data[0][i][1] = dy + sin(2. * theta) / 2.f; + } +} + +/** Test that creates a random set of points distributed *near* the locus + * of the [Lamniscate of + * Gerono](https://en.wikipedia.org/wiki/Lemniscate_of_Gerono) and trains an SOM + * that finds that circular pattern. The following + * [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) files are created + * to validate the execution: + * * `test2.csv`: random test samples points with a lamniscate pattern + * * `w21.csv`: initial random map + * * `w22.csv`: trained SOM map + * + * The outputs can be readily plotted in [gnuplot](https:://gnuplot.info) using + * the following snippet + * ```gnuplot + * set datafile separator ',' + * plot "test2.csv" title "original", \ + * "w21.csv" title "w1", \ + * "w22.csv" title "w2" + * ``` + * ![Sample execution + * output](https://raw.githubusercontent.com/TheAlgorithms/C-Plus-Plus/docs/images/machine_learning/kohonen/test2.svg) + */ +void test2() { + int j, N = 500; + int features = 2; + int num_out = 20; + std::vector> X(N); + std::vector> W(num_out); + for (int i = 0; i < std::max(num_out, N); i++) { + // loop till max(N, num_out) + if (i < N) // only add new arrays if i < N + X[i] = std::valarray(features); + if (i < num_out) { // only add new arrays if i < num_out + W[i] = std::valarray(features); + +#ifdef _OPENMP +#pragma omp for +#endif + for (j = 0; j < features; j++) + // preallocate with random initial weights + W[i][j] = _random(-1, 1); + } + } + + test_lamniscate(&X); // create test data around the lamniscate + save_nd_data("test2.csv", X); // save test data points + save_nd_data("w21.csv", W); // save initial random weights + kohonen_som_tracer(X, &W, 0.01); // train the SOM + save_nd_data("w22.csv", W); // save the resultant weights +} + +/** Creates a random set of points distributed in six clusters in + * 3D space with centroids at the points + * * \f${0.5, 0.5, 0.5}\f$ + * * \f${0.5, 0.5, -0.5}\f$ + * * \f${0.5, -0.5, 0.5}\f$ + * * \f${0.5, -0.5, -0.5}\f$ + * * \f${-0.5, 0.5, 0.5}\f$ + * * \f${-0.5, 0.5, -0.5}\f$ + * * \f${-0.5, -0.5, 0.5}\f$ + * * \f${-0.5, -0.5, -0.5}\f$ + * + * \param[out] data matrix to store data in + */ +void test_3d_classes(std::vector> *data) { + const int N = data->size(); + const double R = 0.1; // radius of cluster + int i; + const int num_classes = 8; + const double centres[][3] = { + // centres of each class cluster + {.5, .5, .5}, // centre of class 0 + {.5, .5, -.5}, // centre of class 1 + {.5, -.5, .5}, // centre of class 2 + {.5, -.5, -.5}, // centre of class 3 + {-.5, .5, .5}, // centre of class 4 + {-.5, .5, -.5}, // centre of class 5 + {-.5, -.5, .5}, // centre of class 6 + {-.5, -.5, -.5} // centre of class 7 + }; + +#ifdef _OPENMP +#pragma omp for +#endif + for (i = 0; i < N; i++) { + int cls = + std::rand() % num_classes; // select a random class for the point + + // create random coordinates (x,y,z) around the centre of the class + data[0][i][0] = _random(centres[cls][0] - R, centres[cls][0] + R); + data[0][i][1] = _random(centres[cls][1] - R, centres[cls][1] + R); + data[0][i][2] = _random(centres[cls][2] - R, centres[cls][2] + R); + + /* The follosing can also be used + for (int j = 0; j < 3; j++) + data[0][i][j] = _random(centres[cls][j] - R, centres[cls][j] + R); + */ + } +} + +/** Test that creates a random set of points distributed in six clusters in + * 3D space. The following + * [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) files are created + * to validate the execution: + * * `test3.csv`: random test samples points with a circular pattern + * * `w31.csv`: initial random map + * * `w32.csv`: trained SOM map + * + * The outputs can be readily plotted in [gnuplot](https:://gnuplot.info) using + * the following snippet + * ```gnuplot + * set datafile separator ',' + * plot "test3.csv" title "original", \ + * "w31.csv" title "w1", \ + * "w32.csv" title "w2" + * ``` + * ![Sample execution + * output](https://raw.githubusercontent.com/TheAlgorithms/C-Plus-Plus/docs/images/machine_learning/kohonen/test3.svg) + */ +void test3() { + int j, N = 200; + int features = 3; + int num_out = 20; + std::vector> X(N); + std::vector> W(num_out); + for (int i = 0; i < std::max(num_out, N); i++) { + // loop till max(N, num_out) + if (i < N) // only add new arrays if i < N + X[i] = std::valarray(features); + if (i < num_out) { // only add new arrays if i < num_out + W[i] = std::valarray(features); + +#ifdef _OPENMP +#pragma omp for +#endif + for (j = 0; j < features; j++) + // preallocate with random initial weights + W[i][j] = _random(-1, 1); + } + } + + test_3d_classes(&X); // create test data around the lamniscate + save_nd_data("test3.csv", X); // save test data points + save_nd_data("w31.csv", W); // save initial random weights + kohonen_som_tracer(X, &W, 0.01); // train the SOM + save_nd_data("w32.csv", W); // save the resultant weights +} + +/** + * Convert clock cycle difference to time in seconds + * + * \param[in] start_t start clock + * \param[in] end_t end clock + * \returns time difference in seconds + */ +double get_clock_diff(clock_t start_t, clock_t end_t) { + return static_cast(end_t - start_t) / CLOCKS_PER_SEC; +} + +/** Main function */ +int main(int argc, char **argv) { +#ifdef _OPENMP + std::cout << "Using OpenMP based parallelization\n"; +#else + std::cout << "NOT using OpenMP based parallelization\n"; +#endif + + std::srand(std::time(nullptr)); + + std::clock_t start_clk = std::clock(); + test1(); + auto end_clk = std::clock(); + std::cout << "Test 1 completed in " << get_clock_diff(start_clk, end_clk) + << " sec\n"; + + start_clk = std::clock(); + test2(); + end_clk = std::clock(); + std::cout << "Test 2 completed in " << get_clock_diff(start_clk, end_clk) + << " sec\n"; + + start_clk = std::clock(); + test3(); + end_clk = std::clock(); + std::cout << "Test 3 completed in " << get_clock_diff(start_clk, end_clk) + << " sec\n"; + + std::cout + << "(Note: Calculated times include: creating test sets, training " + "model and writing files to disk.)\n\n"; + return 0; +} diff --git a/math/CMakeLists.txt b/math/CMakeLists.txt new file mode 100644 index 00000000000..2b70b2d3101 --- /dev/null +++ b/math/CMakeLists.txt @@ -0,0 +1,18 @@ +# If necessary, use the RELATIVE flag, otherwise each source file may be listed +# with full pathname. RELATIVE may makes it easier to extract an executable name +# automatically. +file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) +# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) +foreach( testsourcefile ${APP_SOURCES} ) + # I used a simple string replace, to cut off .cpp. + string( REPLACE ".cpp" "" testname ${testsourcefile} ) + add_executable( ${testname} ${testsourcefile} ) + + set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) + if(OpenMP_CXX_FOUND) + target_link_libraries(${testname} OpenMP::OpenMP_CXX) + endif() + install(TARGETS ${testname} DESTINATION "bin/math") + +endforeach( testsourcefile ${APP_SOURCES} ) diff --git a/math/README.md b/math/README.md index 4ac39c87877..d7b862f9f77 100644 --- a/math/README.md +++ b/math/README.md @@ -1,3 +1,4 @@ +# Prime factorization # {#section} Prime Factorization is a very important and useful technique to factorize any number into its prime factors. It has various applications in the field of number theory. The method of prime factorization involves two function calls. diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index b4551da25f6..05e6f33f7ae 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -1,46 +1,57 @@ -/// C++ Program to find Binary Exponent Iteratively and Recursively. - -#include -/* - * Calculate a^b in O(log(b)) by converting b to a binary number. - * Binary exponentiation is also known as exponentiation by squaring. - * NOTE : This is a far better approach compared to naive method which provide O(b) operations. +/** + * @file + * @brief C++ Program to find Binary Exponent Iteratively and Recursively. + * + * Calculate \f$a^b\f$ in \f$O(\log(b))\f$ by converting \f$b\f$ to a + * binary number. Binary exponentiation is also known as exponentiation by + * squaring. + * @note This is a far better approach compared to naive method which + * provide \f$O(b)\f$ operations. + * * Example: - * 10 in base 2 is 1010. - * 2^10 = 2^(1010) = 2^8 * 2^2 - * 2^1 = 2 - * 2^2 = (2^1)^2 = 2^2 = 4 - * 2^4 = (2^2)^2 = 4^2 = 16 - * 2^8 = (2^4)^2 = 16^2 = 256 - * Hence to calculate 2^10 we only need to multiply 2^8 and 2^2 skipping 2^1 and 2^4. -*/ + *
10 in base 2 is 1010. + * \f{eqnarray*}{ + * 2^{10_d} &=& 2^{1010_b} = 2^8 * 2^2\\ + * 2^1 &=& 2\\ + * 2^2 &=& (2^1)^2 = 2^2 = 4\\ + * 2^4 &=& (2^2)^2 = 4^2 = 16\\ + * 2^8 &=& (2^4)^2 = 16^2 = 256\\ + * \f} + * Hence to calculate 2^10 we only need to multiply \f$2^8\f$ and \f$2^2\f$ + * skipping \f$2^1\f$ and \f$2^4\f$. + */ + +#include -/// Recursive function to calculate exponent in O(log(n)) using binary exponent. +/// Recursive function to calculate exponent in \f$O(\log(n))\f$ using binary +/// exponent. int binExpo(int a, int b) { if (b == 0) { return 1; } - int res = binExpo(a, b/2); - if (b%2) { - return res*res*a; + int res = binExpo(a, b / 2); + if (b % 2) { + return res * res * a; } else { - return res*res; + return res * res; } } -/// Iterative function to calculate exponent in O(log(n)) using binary exponent. +/// Iterative function to calculate exponent in \f$O(\log(n))\f$ using binary +/// exponent. int binExpo_alt(int a, int b) { int res = 1; while (b > 0) { - if (b%2) { - res = res*a; + if (b % 2) { + res = res * a; } - a = a*a; + a = a * a; b /= 2; } return res; } +/// Main function int main() { int a, b; /// Give two numbers a, b diff --git a/math/check_prime.cpp b/math/check_prime.cpp index e517d774e8f..ea4e6d52d27 100644 --- a/math/check_prime.cpp +++ b/math/check_prime.cpp @@ -1,22 +1,24 @@ /** * Copyright 2020 @author omkarlanghe * - * @file + * @file * A simple program to check if the given number if prime or not. - * + * * @brief * Reduced all possibilities of a number which cannot be prime. - * Eg: No even number, except 2 can be a prime number, hence we will increment our loop with i+2 jumping on all odd numbers only. - * If number is <= 1 or if it is even except 2, break the loop and return false telling number is not prime. + * Eg: No even number, except 2 can be a prime number, hence we will increment + * our loop with i+2 jumping on all odd numbers only. If number is <= 1 or if it + * is even except 2, break the loop and return false telling number is not + * prime. */ -#include #include - /** +#include +/** * Function to check if the given number is prime or not. * @param num number to be checked. * @return if number is prime, it returns @ true, else it returns @ false. */ -template +template bool is_prime(T num) { bool result = true; if (num <= 1) { @@ -27,7 +29,7 @@ bool is_prime(T num) { return 0; } if (num >= 3) { - for (T i = 3 ; (i*i) < (num) ; i = (i + 2)) { + for (T i = 3; (i * i) < (num); i = (i + 2)) { if ((num % i) == 0) { result = false; break; @@ -41,18 +43,19 @@ bool is_prime(T num) { * Main function */ int main() { + // perform self-test + assert(is_prime(50) == false); + assert(is_prime(115249) == true); + int num; - std::cout << "Enter the number to check if it is prime or not" << - std::endl; + std::cout << "Enter the number to check if it is prime or not" << std::endl; std::cin >> num; bool result = is_prime(num); if (result) { - std::cout << num << " is a prime number" << - std::endl; + std::cout << num << " is a prime number" << std::endl; } else { - std::cout << num << " is not a prime number" << - std::endl; + std::cout << num << " is not a prime number" << std::endl; } - assert(is_prime(50) == false); - assert(is_prime(115249) == true); + + return 0; } diff --git a/math/double_factorial.cpp b/math/double_factorial.cpp index 7b0d1d9709f..8e5ffcefa04 100644 --- a/math/double_factorial.cpp +++ b/math/double_factorial.cpp @@ -1,28 +1,41 @@ -#include -#include +/** + * @file + * @brief Compute double factorial: \f$n!!\f$ + * + * Double factorial of a non-negative integer n, is defined as the product of + * all the integers from 1 to n that have the same parity (odd or even) as n. + *
It is also called as semifactorial of a number and is denoted by + * \f$n!!\f$ + */ -/* Double factorial of a non-negative integer n, is defined as the product of -all the integers from 1 to n that have the same parity (odd or even) as n. -It is also called as semifactorial of a number and is denoted by !! */ +#include +#include +/** Compute double factorial using iterative method + */ uint64_t double_factorial_iterative(uint64_t n) { - uint64_t res = 1; - for ( uint64_t i = n; i >= 0; i -= 2 ) { - if (i == 0 || i == 1) return res; - res *= i; - } + uint64_t res = 1; + for (uint64_t i = n;; i -= 2) { + if (i == 0 || i == 1) + return res; + res *= i; + } + return res; } -/* Recursion can be costly for large numbers */ - +/** Compute double factorial using resursive method. + *
Recursion can be costly for large numbers. + */ uint64_t double_factorial_recursive(uint64_t n) { - if (n <= 1) return 1; - return n * double_factorial_recursive(n - 2); + if (n <= 1) + return 1; + return n * double_factorial_recursive(n - 2); } +/// main function int main() { - uint64_t n{}; - std::cin >> n; - assert(n >= 0); - std::cout << double_factorial_iterative(n); + uint64_t n; + std::cin >> n; + assert(n >= 0); + std::cout << double_factorial_iterative(n); } diff --git a/math/eulers_totient_function.cpp b/math/eulers_totient_function.cpp index 31ced5a5181..8283ab04503 100644 --- a/math/eulers_totient_function.cpp +++ b/math/eulers_totient_function.cpp @@ -1,28 +1,37 @@ -/// C++ Program to find Euler Totient Function -#include - -/* +/** + * @file + * @brief C++ Program to find + * [Euler's Totient](https://en.wikipedia.org/wiki/Euler%27s_totient_function) + * function + * * Euler Totient Function is also known as phi function. - * phi(n) = phi(p1^a1).phi(p2^a2)... - * where p1, p2,... are prime factors of n. - * 3 Euler's properties: - * 1. phi(prime_no) = prime_no-1 - * 2. phi(prime_no^k) = (prime_no^k - prime_no^(k-1)) - * 3. phi(a,b) = phi(a). phi(b) where a and b are relative primes. + * \f[\phi(n) = + * \phi\left({p_1}^{a_1}\right)\cdot\phi\left({p_2}^{a_2}\right)\ldots\f] where + * \f$p_1\f$, \f$p_2\f$, \f$\ldots\f$ are prime factors of n. + *
3 Euler's properties: + * 1. \f$\phi(n) = n-1\f$ + * 2. \f$\phi(n^k) = n^k - n^{k-1}\f$ + * 3. \f$\phi(a,b) = \phi(a)\cdot\phi(b)\f$ where a and b are relative primes. + * * Applying this 3 properties on the first equation. - * phi(n) = n. (1-1/p1). (1-1/p2). ... - * where p1,p2... are prime factors. - * Hence Implementation in O(sqrt(n)). - * phi(100) = 40 - * phi(1) = 1 - * phi(17501) = 15120 - * phi(1420) = 560 + * \f[\phi(n) = + * n\cdot\left(1-\frac{1}{p_1}\right)\cdot\left(1-\frac{1}{p_2}\right)\cdots\f] + * where \f$p_1\f$,\f$p_2\f$... are prime factors. + * Hence Implementation in \f$O\left(\sqrt{n}\right)\f$. + *
Some known values are: + * * \f$\phi(100) = 40\f$ + * * \f$\phi(1) = 1\f$ + * * \f$\phi(17501) = 15120\f$ + * * \f$\phi(1420) = 560\f$ */ +#include +#include -// Function to caculate Euler's totient phi -int phiFunction(int n) { - int result = n; - for (int i = 2; i * i <= n; i++) { +/** Function to caculate Euler's totient phi + */ +uint64_t phiFunction(uint64_t n) { + uint64_t result = n; + for (uint64_t i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) { n /= i; @@ -30,12 +39,20 @@ int phiFunction(int n) { result -= result / i; } } - if (n > 1) result -= result / n; + if (n > 1) + result -= result / n; return result; } -int main() { - int n; +/// Main function +int main(int argc, char *argv[]) { + uint64_t n; + if (argc < 2) { + std::cout << "Enter the number: "; + } else { + n = strtoull(argv[1], nullptr, 10); + } std::cin >> n; std::cout << phiFunction(n); + return 0; } diff --git a/math/extended_euclid_algorithm.cpp b/math/extended_euclid_algorithm.cpp index 3db14802f0d..9fdc9692ef1 100644 --- a/math/extended_euclid_algorithm.cpp +++ b/math/extended_euclid_algorithm.cpp @@ -1,28 +1,96 @@ +/** + * @file + * @brief GCD using [extended Euclid's algorithm] + * (https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm) + * + * Finding coefficients of a and b ie x and y in Bézout's identity + * \f[\text{gcd}(a, b) = a \times x + b \times y \f] + * This is also used in finding Modular + * 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 -// Finding coefficients of a and b ie x and y in gcd(a, b) = a * x + b * y -// d is gcd(a, b) -// This is also used in finding Modular 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. -int d, x, y; -void extendedEuclid(int A, int B) { +/** + * function to update the coefficients per iteration + * \f[r_0,\,r = r,\, r_0 - \text{quotient}\times r\f] + * + * @param[in,out] r signed or unsigned + * @param[in,out] r0 signed or unsigned + * @param[in] quotient unsigned + */ +template +inline void update_step(T *r, T *r0, const T2 quotient) { + T temp = *r; + *r = *r0 - (quotient * temp); + *r0 = temp; +} + +/** + * Implementation using iterative algorithm from + * [Wikipedia](https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Pseudocode) + * + * @param[in] A unsigned + * @param[in] B unsigned + * @param[out] GCD unsigned + * @param[out] x signed + * @param[out] y signed + */ +template +void extendedEuclid_1(T1 A, T1 B, T1 *GCD, T2 *x, T2 *y) { + if (B > A) + std::swap(A, B); // Ensure that A >= B + + T2 s = 0, s0 = 1; + T2 t = 1, t0 = 0; + T1 r = B, r0 = A; + + while (r != 0) { + T1 quotient = r0 / r; + update_step(&r, &r0, quotient); + update_step(&s, &s0, quotient); + update_step(&t, &t0, quotient); + } + *GCD = r0; + *x = s0; + *y = t0; +} + +/** + * Implementation using recursive algorithm + * + * @param[in] A unsigned + * @param[in] B unsigned + * @param[out] GCD unsigned + * @param[in,out] x signed + * @param[in,out] y signed + */ +template +void extendedEuclid(T A, T B, T *GCD, T2 *x, T2 *y) { + if (B > A) + std::swap(A, B); // Ensure that A >= B + if (B == 0) { - d = A; - x = 1; - y = 0; + *GCD = A; + *x = 1; + *y = 0; } else { - extendedEuclid(B, A%B); - int temp = x; - x = y; - y = temp - (A/B)*y; + extendedEuclid(B, A % B, GCD, x, y); + T2 temp = *x; + *x = *y; + *y = temp - (A / B) * (*y); } } +/// Main function int main() { - int a, b; + uint32_t a, b, gcd; + int32_t x, y; std::cin >> a >> b; - extendedEuclid(a, b); - std::cout << x << " " << y << std::endl; + extendedEuclid(a, b, &gcd, &x, &y); + std::cout << gcd << " " << x << " " << y << std::endl; + extendedEuclid_1(a, b, &gcd, &x, &y); + std::cout << gcd << " " << x << " " << y << std::endl; return 0; } diff --git a/math/factorial.cpp b/math/factorial.cpp index 8b13eb52de4..353f0b16bc7 100644 --- a/math/factorial.cpp +++ b/math/factorial.cpp @@ -1,14 +1,17 @@ -// C++ program to find factorial of given number -#include +/** + * @file + * @brief C++ program to find factorial of given number + */ +#include -// function to find factorial of given number +/** function to find factorial of given number */ unsigned int factorial(unsigned int n) { if (n == 0) return 1; return n * factorial(n - 1); } -// Driver code +/** Main function */ int main() { int num = 5; std::cout << "Factorial of " << num << " is " << factorial(num) diff --git a/math/fast_power.cpp b/math/fast_power.cpp index 4f6e0208197..c5621cd4ecc 100644 --- a/math/fast_power.cpp +++ b/math/fast_power.cpp @@ -1,29 +1,40 @@ -#include -#include -#include +/** + * @file + * @brief Faster computation for \f$a^b\f$ + * + * Program that computes \f$a^b\f$ in \f$O(logN)\f$ time. + * It is based on formula that: + * 1. if \f$b\f$ is even: + * \f$a^b = a^\frac{b}{2} \cdot a^\frac{b}{2} = {a^\frac{b}{2}}^2\f$ + * 2. if \f$b\f$ is odd: \f$a^b = a^\frac{b-1}{2} + * \cdot a^\frac{b-1}{2} \cdot a = {a^\frac{b-1}{2}}^2 \cdot a\f$ + * + * We can compute \f$a^b\f$ recursively using above algorithm. + */ + #include -#include #include +#include +#include +#include +#include -/* - Program that computes a^b in O(logN) time. - It is based on formula that: - case1) if b is even: a^b = a^(b/2) * a^(b/2) = (a^(b/2))ˆ2 - case2) if b is odd: a^b = a^((b-1)/2) * a^((b-1)/2) * a = (a^((b-1)/2))^2 * a - We can compute a^b recursively using above algorithm. -*/ - -double fast_power_recursive(int64_t a, int64_t b) { +/** + * algorithm implementation for \f$a^b\f$ + */ +template +double fast_power_recursive(T a, T b) { // negative power. a^b = 1 / (a^-b) if (b < 0) return 1.0 / fast_power_recursive(a, -b); - if (b == 0) return 1; - int64_t bottom = fast_power_recursive(a, b >> 1); + if (b == 0) + return 1; + T bottom = fast_power_recursive(a, b >> 1); // Since it is integer division b/2 = (b-1)/2 where b is odd. // Therefore, case2 is easily solved by integer division. - int64_t result; + double result; if ((b & 1) == 0) // case1 result = bottom * bottom; else // case2 @@ -31,49 +42,52 @@ double fast_power_recursive(int64_t a, int64_t b) { return result; } -/* +/** Same algorithm with little different formula. - It still calculates in O(logN) + It still calculates in \f$O(\log N)\f$ */ -double fast_power_linear(int64_t a, int64_t b) { +template +double fast_power_linear(T a, T b) { // negative power. a^b = 1 / (a^-b) if (b < 0) return 1.0 / fast_power_linear(a, -b); double result = 1; while (b) { - if (b & 1) result = result * a; + if (b & 1) + result = result * a; a = a * a; b = b >> 1; } return result; } +/** + * Main function + */ int main() { - std::srand(time(NULL)); + std::srand(std::time(nullptr)); std::ios_base::sync_with_stdio(false); std::cout << "Testing..." << std::endl; for (int i = 0; i < 20; i++) { - unsigned int *rand1, *rand2; - int a = rand_r(rand1) % 20 - 10; - int b = rand_r(rand2) % 20 - 10; + int a = std::rand() % 20 - 10; + int b = std::rand() % 20 - 10; std::cout << std::endl << "Calculating " << a << "^" << b << std::endl; assert(fast_power_recursive(a, b) == std::pow(a, b)); assert(fast_power_linear(a, b) == std::pow(a, b)); - std::cout << "------ " << a << "^" << b << " = "<< - fast_power_recursive(a, b) << std::endl; + std::cout << "------ " << a << "^" << b << " = " + << fast_power_recursive(a, b) << std::endl; } int64_t a, b; std::cin >> a >> b; - std::cout << a << "^" << b << " = "<< - fast_power_recursive(a, b) << std::endl; + std::cout << a << "^" << b << " = " << fast_power_recursive(a, b) + << std::endl; - std::cout << a << "^" << b << " = "<< - fast_power_linear(a, b) << std::endl; + std::cout << a << "^" << b << " = " << fast_power_linear(a, b) << std::endl; return 0; } diff --git a/math/fibonacci.cpp b/math/fibonacci.cpp index 1c07cd93fff..e15cfc0ccff 100644 --- a/math/fibonacci.cpp +++ b/math/fibonacci.cpp @@ -1,22 +1,30 @@ -#include +/** + * @file + * @brief Generate fibonacci sequence + * + * Calculate the the value on Fibonacci's sequence given an + * integer as input. + * \f[\text{fib}(n) = \text{fib}(n-1) + \text{fib}(n-2)\f] + * + * @see fibonacci_large.cpp, fibonacci_fast.cpp, string_fibonacci.cpp + */ #include +#include -/* Calculate the the value on Fibonacci's sequence given an -integer as input -Fibonacci = 0, 1, 1, 2, 3, 5, - 8, 13, 21, 34, 55, - 89, 144, ... */ - -int fibonacci(uint n) { +/** + * Recursively compute sequences + */ +int fibonacci(unsigned int n) { /* If the input is 0 or 1 just return the same This will set the first 2 values of the sequence */ if (n <= 1) return n; /* Add the last 2 values of the sequence to get next */ - return fibonacci(n-1) + fibonacci(n-2); + return fibonacci(n - 1) + fibonacci(n - 2); } +/// Main function int main() { int n; std::cin >> n; diff --git a/math/fibonacci_fast.cpp b/math/fibonacci_fast.cpp new file mode 100644 index 00000000000..8fdb20058aa --- /dev/null +++ b/math/fibonacci_fast.cpp @@ -0,0 +1,53 @@ +/** + * @file + * @brief Faster computation of Fibonacci series + * + * An efficient way to calculate nth fibonacci number faster and simpler than + * \f$O(n\log n)\f$ method of matrix exponentiation This works by using both + * recursion and dynamic programming. as 93rd fibonacci exceeds 19 digits, which + * cannot be stored in a single long long variable, we can only use it till 92nd + * fibonacci we can use it for 10000th fibonacci etc, if we implement + * bigintegers. This algorithm works with the fact that nth fibonacci can easily + * found if we have already found n/2th or (n+1)/2th fibonacci It is a property + * of fibonacci similar to matrix exponentiation. + * + * \author [Krishna Vedala](https://github.com/kvedala) + * @see fibonacci_large.cpp, fibonacci.cpp, string_fibonacci.cpp + */ + +#include +#include +#include + +/** maximum number that can be computed - The result after 93 cannot be stored + * in a `uint64_t` data type. */ +const uint64_t MAX = 93; + +/** Array of computed fibonacci numbers */ +uint64_t f[MAX] = {0}; + +/** Algorithm */ +uint64_t fib(uint64_t n) { + if (n == 0) + return 0; + if (n == 1 || n == 2) + return (f[n] = 1); + + if (f[n]) + return f[n]; + + uint64_t k = (n % 2 != 0) ? (n + 1) / 2 : n / 2; + + f[n] = (n % 2 != 0) ? (fib(k) * fib(k) + fib(k - 1) * fib(k - 1)) + : (2 * fib(k - 1) + fib(k)) * fib(k); + return f[n]; +} + +/** Main function */ +int main() { + // Main Function + for (uint64_t i = 1; i < 93; i++) { + std::cout << i << " th fibonacci number is " << fib(i) << std::endl; + } + return 0; +} diff --git a/math/fibonacci_large.cpp b/math/fibonacci_large.cpp new file mode 100644 index 00000000000..e4f4e5eaf1b --- /dev/null +++ b/math/fibonacci_large.cpp @@ -0,0 +1,85 @@ +/** + * @file + * @brief Computes N^th Fibonacci number given as + * input argument. Uses custom build arbitrary integers library + * to perform additions and other operations. + * + * Took 0.608246 seconds to compute 50,000^th Fibonacci + * number that contains 10450 digits! + * + * \author [Krishna Vedala](https://github.com/kvedala) + * @see fibonacci.cpp, fibonacci_fast.cpp, string_fibonacci.cpp + */ + +#include +#include +#include + +#include "./large_number.h" + +/** Compute fibonacci numbers using the relation + * \f[f(n)=f(n-1)+f(n-2)\f] + * and returns the result as a large_number type. + */ +large_number fib(uint64_t n) { + large_number f0(1); + large_number f1(1); + + do { + large_number f2 = f1; + f1 += f0; + f0 = f2; + n--; + } while (n > 2); // since we start from 2 + + return f1; +} + +int main(int argc, char *argv[]) { + uint64_t N; + if (argc == 2) { + N = strtoull(argv[1], NULL, 10); + } else { + std::cout << "Enter N: "; + std::cin >> N; + } + + clock_t start_time = std::clock(); + large_number result = fib(N); + clock_t end_time = std::clock(); + double time_taken = static_cast(end_time - start_time) / + static_cast(CLOCKS_PER_SEC); + + std::cout << std::endl + << N << "^th Fibonacci number: " << result << std::endl + << "Number of digits: " << result.num_digits() << std::endl + << "Time taken: " << std::scientific << time_taken << " s" + << std::endl; + + N = 5000; + if (fib(N) == + large_number( + "387896845438832563370191630832590531208212771464624510616059721489" + "555013904403709701082291646221066947929345285888297381348310200895" + "498294036143015691147893836421656394410691021450563413370655865623" + "825465670071252592990385493381392883637834751890876297071203333705" + "292310769300851809384980180384781399674888176555465378829164426891" + "298038461377896902150229308247566634622492307188332480328037503913" + "035290330450584270114763524227021093463769910400671417488329842289" + "149127310405432875329804427367682297724498774987455569190770388063" + "704683279481135897373999311010621930814901857081539785437919530561" + "751076105307568878376603366735544525884488624161921055345749367589" + "784902798823435102359984466393485325641195222185956306047536464547" + "076033090242080638258492915645287629157575914234380914230291749108" + "898415520985443248659407979357131684169286803954530954538869811466" + "508206686289742063932343848846524098874239587380197699382031717420" + "893226546887936400263079778005875912967138963421425257911687275560" + "0360311370547754724604639987588046985178408674382863125")) + std::cout << "Test for " << N << "^th Fibonacci number passed!" + << std::endl; + else + std::cerr << "Test for " << N << "^th Fibonacci number failed!" + << std::endl; + + return 0; +} diff --git a/math/greatest_common_divisor_euclidean.cpp b/math/gcd_iterative_euclidean.cpp similarity index 79% rename from math/greatest_common_divisor_euclidean.cpp rename to math/gcd_iterative_euclidean.cpp index c4812e45b4c..2c0651ad7ca 100644 --- a/math/greatest_common_divisor_euclidean.cpp +++ b/math/gcd_iterative_euclidean.cpp @@ -1,10 +1,17 @@ -#include +/** + * @file + * @brief Compute the greatest common denominator of two integers using + * *iterative form* of + * [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) + * + * @see gcd_recursive_euclidean.cpp, gcd_of_n_numbers.cpp + */ #include #include -// will find the greatest common denominator of two ints integers -// Euclidean algorithm can be found here -// https://en.wikipedia.org/wiki/Euclidean_algorithm +/** + * algorithm + */ int gcd(int num1, int num2) { if (num1 <= 0 | num2 <= 0) { throw std::domain_error("Euclidean algorithm domain is for ints > 0"); @@ -34,6 +41,9 @@ int gcd(int num1, int num2) { return previous_remainder; } +/** + * Main function + */ int main() { std::cout << "gcd of 120,7 is " << (gcd(120, 7)) << std::endl; try { diff --git a/math/gcd_of_n_numbers.cpp b/math/gcd_of_n_numbers.cpp new file mode 100644 index 00000000000..92968ff1265 --- /dev/null +++ b/math/gcd_of_n_numbers.cpp @@ -0,0 +1,41 @@ +/** + * @file + * @brief This program aims at calculating the GCD of n numbers by division + * method + * + * @see gcd_iterative_euclidean.cpp, gcd_recursive_euclidean.cpp + */ +#include + +/** Compute GCD using division algorithm + * + * @param[in] a array of integers to compute GCD for + * @param[in] n number of integers in array `a` + */ +int gcd(int *a, int n) { + int j = 1; // to access all elements of the array starting from 1 + int gcd = a[0]; + while (j < n) { + if (a[j] % gcd == 0) // value of gcd is as needed so far + j++; // so we check for next element + else + gcd = a[j] % gcd; // calculating GCD by division method + } + return gcd; +} + +/** Main function */ +int main() { + int n; + std::cout << "Enter value of n:" << std::endl; + std::cin >> n; + int *a = new int[n]; + int i; + std::cout << "Enter the n numbers:" << std::endl; + for (i = 0; i < n; i++) std::cin >> a[i]; + + std::cout << "GCD of entered n numbers:" << gcd(a, n) << std::endl; + + delete[] a; + return 0; +} diff --git a/math/gcd_recursive_euclidean.cpp b/math/gcd_recursive_euclidean.cpp new file mode 100644 index 00000000000..2a3d2183c4e --- /dev/null +++ b/math/gcd_recursive_euclidean.cpp @@ -0,0 +1,52 @@ +/** + * @file + * @brief Compute the greatest common denominator of two integers using + * *recursive form* of + * [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) + * + * @see gcd_iterative_euclidean.cpp, gcd_of_n_numbers.cpp + */ +#include + +/** + * algorithm + */ +int gcd(int num1, int num2) { + if (num1 <= 0 | num2 <= 0) { + throw std::domain_error("Euclidean algorithm domain is for ints > 0"); + } + + if (num1 == num2) { + return num1; + } + + // Everything divides 0 + if (num1 == 0) + return num2; + if (num2 == 0) + return num1; + + // base case + if (num1 == num2) + return num1; + + // a is greater + if (num1 > num2) + return gcd(num1 - num2, num2); + return gcd(num1, num2 - num1); +} + +/** + * Main function + */ +int main() { + std::cout << "gcd of 120,7 is " << (gcd(120, 7)) << std::endl; + try { + std::cout << "gcd of -120,10 is " << gcd(-120, 10) << std::endl; + } catch (const std::domain_error &e) { + std::cout << "Error handling was successful" << std::endl; + } + std::cout << "gcd of 312,221 is " << (gcd(312, 221)) << std::endl; + std::cout << "gcd of 289,204 is " << (gcd(289, 204)) << std::endl; + return 0; +} diff --git a/math/greatest_common_divisor.cpp b/math/greatest_common_divisor.cpp deleted file mode 100644 index 5601c4be91c..00000000000 --- a/math/greatest_common_divisor.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// C++ program to find GCD of two numbers -#include - -// Recursive function to return gcd of a and b -int gcd(int a, int b) { - // Everything divides 0 - if (a == 0) - return b; - if (b == 0) - return a; - - // base case - if (a == b) - return a; - - // a is greater - if (a > b) - return gcd(a-b, b); - return gcd(a, b-a); -} - -// Driver program to test above function -int main() { - int a = 98, b = 56; - std::cout << "GCD of " << a << " and " << b << " is " << gcd(a, b); - return 0; -} diff --git a/math/large_factorial.cpp b/math/large_factorial.cpp new file mode 100644 index 00000000000..20c677cdcc4 --- /dev/null +++ b/math/large_factorial.cpp @@ -0,0 +1,118 @@ +/** + * @file + * @brief Compute factorial of any arbitratily large number/ + * + * \author [Krishna Vedala](https://github.com/kvedala) + * @see factorial.cpp + */ +#include +#include +#include + +#include "./large_number.h" + +/** Test implementation for 10! Result must be 3628800. + * @returns True if test pass else False + */ +bool test1() { + std::cout << "---- Check 1\t"; + unsigned int i, number = 10; + large_number result; + for (i = 2; i <= number; i++) /* Multiply every number from 2 thru N */ + result *= i; + + const char *known_reslt = "3628800"; + + /* check 1 */ + if (strlen(known_reslt) != result.num_digits()) { + std::cerr << "Result lengths dont match! " << strlen(known_reslt) + << " != " << result.num_digits() << std::endl; + return false; + } + + const size_t N = result.num_digits(); + for (i = 0; i < N; i++) { + if (known_reslt[i] != result.digit_char(i)) { + std::cerr << i << "^th digit mismatch! " << known_reslt[i] + << " != " << result.digit_char(i) << std::endl; + return false; + } + } + + std::cout << "Passed!" << std::endl; + return true; +} + +/** Test implementation for 100! The result is the 156 digit number: + * ``` + * 9332621544394415268169923885626670049071596826438162146859296389521759 + * 9993229915608941463976156518286253697920827223758251185210916864000000 + * 000000000000000000 + * ``` + * @returns True if test pass else False + */ +bool test2() { + std::cout << "---- Check 2\t"; + unsigned int i, number = 100; + large_number result; + for (i = 2; i <= number; i++) /* Multiply every number from 2 thru N */ + result *= i; + + const char *known_reslt = + "9332621544394415268169923885626670049071596826438162146859296389521759" + "9993229915608941463976156518286253697920827223758251185210916864000000" + "000000000000000000"; + + /* check 1 */ + if (strlen(known_reslt) != result.num_digits()) { + std::cerr << "Result lengths dont match! " << strlen(known_reslt) + << " != " << result.num_digits() << std::endl; + return false; + } + + const size_t N = result.num_digits(); + for (i = 0; i < N; i++) { + if (known_reslt[i] != result.digit_char(i)) { + std::cerr << i << "^th digit mismatch! " << known_reslt[i] + << " != " << result.digit_char(i) << std::endl; + return false; + } + } + + std::cout << "Passed!" << std::endl; + return true; +} + +/** + * Main program + **/ +int main(int argc, char *argv[]) { + int number, i; + + if (argc == 2) { + number = atoi(argv[1]); + } else { + std::cout << "Enter the value of n(n starts from 0 ): "; + std::cin >> number; + } + + large_number result; + + std::clock_t start_time = std::clock(); + for (i = 2; i <= number; i++) /* Multiply every number from 2 thru N */ + result *= i; + std::clock_t end_time = std::clock(); + double time_taken = + static_cast(end_time - start_time) / CLOCKS_PER_SEC; + + std::cout << number << "! = " << result << std::endl + << "Number of digits: " << result.num_digits() << std::endl + << "Time taken: " << std::scientific << time_taken << " s" + << std::endl; + + test1(); + test2(); + result.test(); + + return 0; +} diff --git a/math/large_number.h b/math/large_number.h new file mode 100644 index 00000000000..bffb764d036 --- /dev/null +++ b/math/large_number.h @@ -0,0 +1,288 @@ +/** + * @file + * @brief Library to perform arithmatic operations on arbitrarily large + * numbers. + * \author [Krishna Vedala](https://github.com/kvedala) + */ + +#ifndef MATH_LARGE_NUMBER_H_ +#define MATH_LARGE_NUMBER_H_ +#include +#include +#include +#include +#include +#include +#include + +/** + * Store large unsigned numbers as a C++ vector + * The class provides convenience functions to add a + * digit to the number, perform multiplication of + * large number with long unsigned integers. + **/ +class large_number { + public: + /**< initializer with value = 1 */ + large_number() { _digits.push_back(1); } + + // /**< initializer from an integer */ + // explicit large_number(uint64_t n) { + // uint64_t carry = n; + // do { + // add_digit(carry % 10); + // carry /= 10; + // } while (carry != 0); + // } + + /**< initializer from an integer */ + explicit large_number(int n) { + int carry = n; + do { + add_digit(carry % 10); + carry /= 10; + } while (carry != 0); + } + + /**< initializer from another large_number */ + large_number(const large_number &a) : _digits(a._digits) {} + + /**< initializer from a vector */ + explicit large_number(std::vector &vec) : _digits(vec) {} + + /**< initializer from a string */ + explicit large_number(char const *number_str) { + for (size_t i = strlen(number_str); i > 0; i--) { + unsigned char a = number_str[i - 1] - '0'; + if (a >= 0 && a <= 9) + _digits.push_back(a); + } + } + + /** + * Function to check implementation + **/ + static bool test() { + std::cout << "------ Checking `large_number` class implementations\t" + << std::endl; + large_number a(40); + // 1. test multiplication + a *= 10; + if (a != large_number(400)) { + std::cerr << "\tFailed 1/6 (" << a << "!=400)" << std::endl; + return false; + } + std::cout << "\tPassed 1/6..."; + // 2. test compound addition with integer + a += 120; + if (a != large_number(520)) { + std::cerr << "\tFailed 2/6 (" << a << "!=520)" << std::endl; + return false; + } + std::cout << "\tPassed 2/6..."; + // 3. test compound multiplication again + a *= 10; + if (a != large_number(5200)) { + std::cerr << "\tFailed 3/6 (" << a << "!=5200)" << std::endl; + return false; + } + std::cout << "\tPassed 3/6..."; + // 4. test increment (prefix) + ++a; + if (a != large_number(5201)) { + std::cerr << "\tFailed 4/6 (" << a << "!=5201)" << std::endl; + return false; + } + std::cout << "\tPassed 4/6..."; + // 5. test increment (postfix) + a++; + if (a != large_number(5202)) { + std::cerr << "\tFailed 5/6 (" << a << "!=5202)" << std::endl; + return false; + } + std::cout << "\tPassed 5/6..."; + // 6. test addition with another large number + a = a + large_number("7000000000000000000000000000000"); + if (a != large_number("7000000000000000000000000005202")) { + std::cerr << "\tFailed 6/6 (" << a + << "!=7000000000000000000000000005202)" << std::endl; + return false; + } + std::cout << "\tPassed 6/6..." << std::endl; + return true; + } + + /** + * add a digit at MSB to the large number + **/ + void add_digit(unsigned int value) { + if (value > 9) { + std::cerr << "digit > 9!!\n"; + exit(EXIT_FAILURE); + } + + _digits.push_back(value); + } + + /** + * Get number of digits in the number + **/ + const size_t num_digits() const { return _digits.size(); } + + /** + * operator over load to access the + * i^th digit conveniently and also + * assign value to it + **/ + inline unsigned char &operator[](size_t n) { return this->_digits[n]; } + + inline const unsigned char &operator[](size_t n) const { + return this->_digits[n]; + } + + /** + * operator overload to compare two numbers + **/ + friend std::ostream &operator<<(std::ostream &out, const large_number &a) { + for (size_t i = a.num_digits(); i > 0; i--) + out << static_cast(a[i - 1]); + return out; + } + + /** + * operator overload to compare two numbers + **/ + friend bool operator==(large_number const &a, large_number const &b) { + size_t N = a.num_digits(); + if (N != b.num_digits()) + return false; + for (size_t i = 0; i < N; i++) + if (a[i] != b[i]) + return false; + return true; + } + + /** + * operator overload to compare two numbers + **/ + friend bool operator!=(large_number const &a, large_number const &b) { + return !(a == b); + } + + /** + * operator overload to increment (prefix) + **/ + large_number &operator++() { + (*this) += 1; + return *this; + } + + /** + * operator overload to increment (postfix) + **/ + large_number &operator++(int) { + static large_number tmp(_digits); + ++(*this); + return tmp; + } + + /** + * operator overload to add + **/ + large_number &operator+=(large_number n) { + // if adding with another large_number + large_number *b = reinterpret_cast(&n); + const size_t max_L = std::max(this->num_digits(), b->num_digits()); + unsigned int carry = 0; + size_t i; + for (i = 0; i < max_L || carry != 0; i++) { + if (i < b->num_digits()) + carry += (*b)[i]; + if (i < this->num_digits()) + carry += (*this)[i]; + if (i < this->num_digits()) + (*this)[i] = carry % 10; + else + this->add_digit(carry % 10); + carry /= 10; + } + return *this; + } + + large_number &operator+=(int n) { return (*this) += large_number(n); } + // large_number &operator+=(uint64_t n) { return (*this) += large_number(n); + // } + + /** + * operator overload to perform addition + **/ + template + friend large_number &operator+(const large_number &a, const T &b) { + static large_number c = a; + c += b; + return c; + } + + /** + * assignment operator + **/ + large_number &operator=(const large_number &b) { + this->_digits = b._digits; + return *this; + } + + /** + * operator overload to increment + **/ + template + large_number &operator*=(const T n) { + static_assert(std::is_integral::value, + "Must be integer addition unsigned integer types."); + this->multiply(n); + return *this; + } + + /** + * returns i^th digit as an ASCII character + **/ + const char digit_char(size_t i) const { + return _digits[num_digits() - i - 1] + '0'; + } + + private: + /** + * multiply large number with another integer and + * store the result in the same large number + **/ + template + void multiply(const T n) { + static_assert(std::is_integral::value, + "Can only have integer types."); + // assert(!(std::is_signed::value)); //, "Implemented only for + // unsigned integer types."); + + size_t i; + uint64_t carry = 0, temp; + for (i = 0; i < this->num_digits(); i++) { + temp = (*this)[i] * n; + temp += carry; + if (temp < 10) { + carry = 0; + } else { + carry = temp / 10; + temp = temp % 10; + } + (*this)[i] = temp; + } + + while (carry != 0) { + this->add_digit(carry % 10); + carry /= 10; + } + } + + std::vector + _digits; /**< where individual digits are stored */ +}; + +#endif // MATH_LARGE_NUMBER_H_ diff --git a/math/modular_inverse_fermat_little_theorem.cpp b/math/modular_inverse_fermat_little_theorem.cpp index 965c21298ae..7550e14bf23 100644 --- a/math/modular_inverse_fermat_little_theorem.cpp +++ b/math/modular_inverse_fermat_little_theorem.cpp @@ -1,44 +1,59 @@ -/* - * C++ Program to find the modular inverse using Fermat's Little Theorem. - * Fermat's Little Theorem state that => ϕ(m) = m-1, where m is a prime number. - * - * (a * x) ≡ 1 mod m. - * x ≡ (a^(-1)) mod m. +/** + * @file + * @brief C++ Program to find the modular inverse using [Fermat's Little + * Theorem](https://en.wikipedia.org/wiki/Fermat%27s_little_theorem) * + * Fermat's Little Theorem state that \f[ϕ(m) = m-1\f] + * where \f$m\f$ is a prime number. + * \f{eqnarray*}{ + * a \cdot x &≡& 1 \;\text{mod}\; m\\ + * x &≡& a^{-1} \;\text{mod}\; m + * \f} * Using Euler's theorem we can modify the equation. + *\f[ + * a^{ϕ(m)} ≡ 1 \;\text{mod}\; m + * \f] + * (Where '^' denotes the exponent operator) * - * (a^ϕ(m)) ≡ 1 mod m (Where '^' denotes the exponent operator) - * Here 'ϕ' is Euler's Totient Function. For modular inverse existence 'a' and 'm' must be relatively primes numbers. - * To apply Fermat's Little Theorem is necessary that 'm' must be a prime number. - * Generally in many competitive programming competitions 'm' is either 1000000007 (1e9+7) or 998244353. + * Here 'ϕ' is Euler's Totient Function. For modular inverse existence 'a' and + * 'm' must be relatively primes numbers. To apply Fermat's Little Theorem is + * necessary that 'm' must be a prime number. Generally in many competitive + * programming competitions 'm' is either 1000000007 (1e9+7) or 998244353. * * We considered m as large prime (1e9+7). - * (a^ϕ(m)) ≡ 1 mod m (Using Euler's Theorem) - * ϕ(m) = m-1 using Fermat's Little Theorem. - * (a^(m-1)) ≡ 1 mod m - * Now multiplying both side by (a^(-1)). - * (a^(m-1)) * (a^(-1)) ≡ (a^(-1)) mod m - * (a^(m-2)) ≡ (a^(-1)) mod m + * \f$a^{ϕ(m)} ≡ 1 \;\text{mod}\; m\f$ (Using Euler's Theorem) + * \f$ϕ(m) = m-1\f$ using Fermat's Little Theorem. + * \f$a^{m-1} ≡ 1 \;\text{mod}\; m\f$ + * Now multiplying both side by \f$a^{-1}\f$. + * \f{eqnarray*}{ + * a^{m-1} \cdot a^{-1} &≡& a^{-1} \;\text{mod}\; m\\ + * a^{m-2} &≡& a^{-1} \;\text{mod}\; m + * \f} * - * We will find the exponent using binary exponentiation. Such that the algorithm works in O(log(m)) time. + * We will find the exponent using binary exponentiation. Such that the + * algorithm works in \f$O(\log m)\f$ time. * - * Example: - - * a = 3 and m = 7 - * (a^(-1) mod m) is equivalent to (a^(m-2) mod m) - * (3^(5) mod 7) = (243 mod 7) = 5 - * Hence, ( 3^(-1) mod 7 ) = 5 - * or ( 3 * 5 ) mod 7 = 1 mod 7 (as a*(a^(-1)) = 1) + * Examples: - + * * a = 3 and m = 7 + * * \f$a^{-1} \;\text{mod}\; m\f$ is equivalent to + * \f$a^{m-2} \;\text{mod}\; m\f$ + * * \f$3^5 \;\text{mod}\; 7 = 243 \;\text{mod}\; 7 = 5\f$ + *
Hence, \f$3^{-1} \;\text{mod}\; 7 = 5\f$ + * or \f$3 \times 5 \;\text{mod}\; 7 = 1 \;\text{mod}\; 7\f$ + * (as \f$a\times a^{-1} = 1\f$) */ -#include -#include +#include +#include -// Recursive function to calculate exponent in O(log(n)) using binary exponent. +/** Recursive function to calculate exponent in \f$O(\log n)\f$ using binary + * exponent. + */ int64_t binExpo(int64_t a, int64_t b, int64_t m) { a %= m; int64_t res = 1; while (b > 0) { - if (b%2) { + if (b % 2) { res = res * a % m; } a = a * a % m; @@ -48,13 +63,14 @@ int64_t binExpo(int64_t a, int64_t b, int64_t m) { return res; } -// Prime check in O(sqrt(m)) time. +/** Prime check in \f$O(\sqrt{m})\f$ time. + */ bool isPrime(int64_t m) { if (m <= 1) { return false; } else { - for (int i=2; i*i <= m; i++) { - if (m%i == 0) { + for (int64_t i = 2; i * i <= m; i++) { + if (m % i == 0) { return false; } } @@ -62,6 +78,9 @@ bool isPrime(int64_t m) { return true; } +/** + * Main function + */ int main() { int64_t a, m; // Take input of a and m. @@ -71,7 +90,7 @@ int main() { std::cin >> a >> m; if (isPrime(m)) { std::cout << "The modular inverse of a with mod m is (a^(m-2)) : "; - std::cout << binExpo(a, m-2, m) << std::endl; + std::cout << binExpo(a, m - 2, m) << std::endl; } else { std::cout << "m must be a prime number."; std::cout << std::endl; diff --git a/math/number_of_positive_divisors.cpp b/math/number_of_positive_divisors.cpp index 48ab63c3642..f157f7b4161 100644 --- a/math/number_of_positive_divisors.cpp +++ b/math/number_of_positive_divisors.cpp @@ -1,34 +1,39 @@ -/// C++ Program to calculate number of divisors. - -#include -#include - /** + * @file + * @brief C++ Program to calculate number of divisors + * * This algorithm use the prime factorization approach. * Any number can be written in multiplication of its prime factors. - * Let N = P1^E1 * P2^E2 ... Pk^Ek - * Therefore. number-of-divisors(N) = (E1+1) * (E2+1) ... (Ek+1). - * Where P1, P2 ... Pk are prime factors and E1, E2 ... Ek are exponents respectively. + *
Let N = P1^E1 * P2^E2 ... Pk^Ek + *
Therefore. number-of-divisors(N) = (E1+1) * (E2+1) ... (Ek+1). + *
Where P1, P2 ... Pk are prime factors and E1, E2 ... Ek are exponents +respectively. * * Example:- - * N = 36 - * 36 = (3^2 * 2^2) - * number_of_positive_divisors(36) = (2+1) * (2+1) = 9. - * list of positive divisors of 36 = 1, 2, 3, 4, 6, 9, 12, 18, 36. + *
N = 36 + *
36 = (3^2 * 2^2) + *
number_of_positive_divisors(36) = (2+1) * (2+1) = 9. + *
list of positive divisors of 36 = 1, 2, 3, 4, 6, 9, 12, 18, 36. * * Similarly if N is -36 at that time number of positive divisors remain same. * * Example:- - * N = -36 - * -36 = -1 * (3^2 * 2^2) - * number_of_positive_divisors(-36) = (2+1) * (2+1) = 9. - * list of positive divisors of -36 = 1, 2, 3, 4, 6, 9, 12, 18, 36. + *
N = -36 + *
-36 = -1 * (3^2 * 2^2) + *
number_of_positive_divisors(-36) = (2+1) * (2+1) = 9. + *
list of positive divisors of -36 = 1, 2, 3, 4, 6, 9, 12, 18, 36. * **/ +#include +#include + +/** + * Algorithm + */ int number_of_positive_divisors(int n) { std::vector prime_exponent_count; - for (int i=2; i*i <= n; i++) { + for (int i = 2; i * i <= n; i++) { int prime_count = 0; while (n % i == 0) { prime_count += 1; @@ -44,13 +49,16 @@ int number_of_positive_divisors(int n) { int divisors_count = 1; - for (int i=0; i < prime_exponent_count.size(); i++) { - divisors_count = divisors_count * (prime_exponent_count[i]+1); + for (int i = 0; i < prime_exponent_count.size(); i++) { + divisors_count = divisors_count * (prime_exponent_count[i] + 1); } return divisors_count; } +/** + * Main function + */ int main() { int n; std::cin >> n; diff --git a/math/power_for_huge_numbers.cpp b/math/power_for_huge_numbers.cpp index bf93742289d..301767d666e 100644 --- a/math/power_for_huge_numbers.cpp +++ b/math/power_for_huge_numbers.cpp @@ -1,91 +1,90 @@ +/** + * @file + * @brief Compute powers of large numbers + */ #include -using namespace std; -// Maximum number of digits in output -// x^n where 1 <= x, n <= 10000 and overflow may happen +/** Maximum number of digits in output + * \f$x^n\f$ where \f$1 <= x,\; n <= 10000\f$ and overflow may happen + */ #define MAX 100000 -// This function multiplies x -// with the number represented by res[]. -// res_size is size of res[] or -// number of digits in the number -// represented by res[]. This function -// uses simple school mathematics -// for multiplication. -// This function may value of res_size -// and returns the new value of res_size -int multiply(int x, int res[], int res_size) -{ +/** This function multiplies x + * with the number represented by res[]. + * res_size is size of res[] or + * number of digits in the number + * represented by res[]. This function + * uses simple school mathematics + * for multiplication. + * This function may value of res_size + * and returns the new value of res_size + * @param x multiplicand + * @param res large number representation using array + * @param res_size number of digits in `res` + */ +int multiply(int x, int res[], int res_size) { + // Initialize carry + int carry = 0; - // Initialize carry - int carry = 0; + // One by one multiply n with + // individual digits of res[] + for (int i = 0; i < res_size; i++) { + int prod = res[i] * x + carry; - // One by one multiply n with - // individual digits of res[] - for (int i = 0; i < res_size; i++) - { - int prod = res[i] * x + carry; + // Store last digit of + // 'prod' in res[] + res[i] = prod % 10; - // Store last digit of - // 'prod' in res[] - res[i] = prod % 10; + // Put rest in carry + carry = prod / 10; + } - // Put rest in carry - carry = prod / 10; - } - - // Put carry in res and - // increase result size - while (carry) - { - res[res_size] = carry % 10; - carry = carry / 10; - res_size++; - } - return res_size; + // Put carry in res and + // increase result size + while (carry) { + res[res_size] = carry % 10; + carry = carry / 10; + res_size++; + } + return res_size; } -// This function finds -// power of a number x -void power(int x, int n) -{ - - //printing value "1" for power = 0 - if (n == 0) - { - cout << "1"; - return; - } +/** This function finds power of a number x and print \f$x^n\f$ + * @param x base + * @param n exponent + */ +void power(int x, int n) { + // printing value "1" for power = 0 + if (n == 0) { + std::cout << "1"; + return; + } - int res[MAX]; - int res_size = 0; - int temp = x; + int res[MAX]; + int res_size = 0; + int temp = x; - // Initialize result - while (temp != 0) - { - res[res_size++] = temp % 10; - temp = temp / 10; - } + // Initialize result + while (temp != 0) { + res[res_size++] = temp % 10; + temp = temp / 10; + } - // Multiply x n times - // (x^n = x*x*x....n times) - for (int i = 2; i <= n; i++) - res_size = multiply(x, res, res_size); + // Multiply x n times + // (x^n = x*x*x....n times) + for (int i = 2; i <= n; i++) res_size = multiply(x, res, res_size); - cout << x << "^" << n << " = "; - for (int i = res_size - 1; i >= 0; i--) - cout << res[i]; + std::cout << x << "^" << n << " = "; + for (int i = res_size - 1; i >= 0; i--) std::cout << res[i]; } -// Driver program -int main() -{ - int exponent, base; - printf("Enter base "); - scanf("%id \n", &base); - printf("Enter exponent "); - scanf("%id", &exponent); - power(base, exponent); - return 0; +/** Main function */ +int main() { + int exponent, base; + std::cout << "Enter base "; + std::cin >> base; + std::cout << "Enter exponent "; + std::cin >> exponent; + power(base, exponent); + return 0; } diff --git a/math/prime_factorization.cpp b/math/prime_factorization.cpp index 822cad332c6..001c2c3c360 100644 --- a/math/prime_factorization.cpp +++ b/math/prime_factorization.cpp @@ -1,80 +1,77 @@ +/** + * @file + * @brief Prime factorization of positive integers + */ +#include +#include #include #include -#include -using namespace std; -// Declaring variables for maintaing prime numbers and to check whether a number is prime or not +/** Declaring variables for maintaing prime numbers and to check whether a + * number is prime or not + */ bool isprime[1000006]; -vector prime_numbers; -vector> factors; -// Calculating prime number upto a given range -void SieveOfEratosthenes(int N) -{ +/** list of prime numbers */ +std::vector prime_numbers; + +/** list of prime factor-pairs */ +std::vector> factors; + +/** Calculating prime number upto a given range + */ +void SieveOfEratosthenes(int N) { // initializes the array isprime memset(isprime, true, sizeof isprime); - for (int i = 2; i <= N; i++) - { - if (isprime[i]) - { - for (int j = 2 * i; j <= N; j += i) - isprime[j] = false; + for (int i = 2; i <= N; i++) { + if (isprime[i]) { + for (int j = 2 * i; j <= N; j += i) isprime[j] = false; } } - for (int i = 2; i <= N; i++) - { + for (int i = 2; i <= N; i++) { if (isprime[i]) prime_numbers.push_back(i); } } -// Prime factorization of a number -void prime_factorization(int num) -{ - +/** Prime factorization of a number */ +void prime_factorization(int num) { int number = num; - for (int i = 0; prime_numbers[i] <= num; i++) - { + for (int i = 0; prime_numbers[i] <= num; i++) { int count = 0; // termination condition - if (number == 1) - { + if (number == 1) { break; } - while (number % prime_numbers[i] == 0) - { + while (number % prime_numbers[i] == 0) { count++; number = number / prime_numbers[i]; } if (count) - factors.push_back(make_pair(prime_numbers[i], count)); + factors.push_back(std::make_pair(prime_numbers[i], count)); } } -/* - I added a simple UI. -*/ -int main() -{ +/** Main program */ +int main() { int num; - cout << "\t\tComputes the prime factorization\n\n"; - cout << "Type in a number: "; - cin >> num; + std::cout << "\t\tComputes the prime factorization\n\n"; + std::cout << "Type in a number: "; + std::cin >> num; SieveOfEratosthenes(num); prime_factorization(num); // Prime factors with their powers in the given number in new line - for (auto it : factors) - { - cout << it.first << " " << it.second << endl; + for (auto it : factors) { + std::cout << it.first << " " << it.second << std::endl; } return 0; diff --git a/math/prime_numbers.cpp b/math/prime_numbers.cpp index 7264ff5287c..4dd54f13657 100644 --- a/math/prime_numbers.cpp +++ b/math/prime_numbers.cpp @@ -1,26 +1,33 @@ +/** + * @file + * @brief Get list of prime numbers + * @see primes_up_to_billion.cpp sieve_of_eratosthenes.cpp + */ #include #include +/** Generate an increasingly large number of primes + * and store in a list + */ std::vector primes(int max) { max++; std::vector res; std::vector numbers(max, false); for (int i = 2; i < max; i++) { if (!numbers[i]) { - for (int j = i; j < max; j += i) - numbers[j] = true; + for (int j = i; j < max; j += i) numbers[j] = true; res.push_back(i); } } return res; } +/** main function */ int main() { std::cout << "Calculate primes up to:\n>> "; int n; std::cin >> n; std::vector ans = primes(n); - for (int i = 0; i < ans.size(); i++) - std::cout << ans[i] << ' '; + for (int i = 0; i < ans.size(); i++) std::cout << ans[i] << ' '; std::cout << std::endl; } diff --git a/math/primes_up_to_10^8.cpp b/math/primes_up_to_billion.cpp similarity index 59% rename from math/primes_up_to_10^8.cpp rename to math/primes_up_to_billion.cpp index db9b56cab32..4fb79a15e7c 100644 --- a/math/primes_up_to_10^8.cpp +++ b/math/primes_up_to_billion.cpp @@ -1,12 +1,19 @@ -#include +/** + * @file + * @brief Compute prime numbers upto 1 billion + * @see prime_numbers.cpp sieve_of_eratosthenes.cpp + */ #include +#include +/** array to store the primes */ char prime[100000000]; +/** Perform Sieve algorithm */ void Sieve(int64_t n) { memset(prime, '1', sizeof(prime)); // intitize '1' to every index - prime[0] = '0'; // 0 is not prime - prime[1] = '0'; // 1 is not prime + prime[0] = '0'; // 0 is not prime + prime[1] = '0'; // 1 is not prime for (int p = 2; p * p <= n; p++) { if (prime[p] == '1') { for (int i = p * p; i <= n; i += p) @@ -15,7 +22,7 @@ void Sieve(int64_t n) { } } - +/** Main function */ int main() { Sieve(100000000); int64_t n; @@ -24,4 +31,6 @@ int main() { std::cout << "YES\n"; else std::cout << "NO\n"; + + return 0; } diff --git a/math/realtime_stats.cpp b/math/realtime_stats.cpp new file mode 100644 index 00000000000..5f353ac4db0 --- /dev/null +++ b/math/realtime_stats.cpp @@ -0,0 +1,193 @@ +/** + * \file + * \brief Compute statistics for data entered in rreal-time + * + * This algorithm is really beneficial to compute statistics on data read in + * realtime. For example, devices reading biometrics data. The algorithm is + * simple enough to be easily implemented in an embedded system. + * \author [Krishna Vedala](https://github.com/kvedala) + */ +#include +#include +#include + +/** + * \namespace statistics + * \brief Statistical algorithms + */ +namespace statistics { + +/** + * continuous mean and variance computance using + * first value as an approximation for the mean. + * If the first number is much far form the mean, the algorithm becomes very + * inaccurate to compute variance and standard deviation. + */ +template +class stats_computer1 { + public: + /** Constructor + * \param[in] x new data sample + */ + void new_val(T x) { + if (n == 0) + K = x; + n++; + T tmp = x - K; + Ex += tmp; + Ex2 += tmp * tmp; + } + + /** return sample mean computed till last sample */ + double mean() const { return K + Ex / n; } + + /** return data variance computed till last sample */ + double variance() const { return (Ex2 - (Ex * Ex) / n) / (n - 1); } + + /** return sample standard deviation computed till last sample */ + double std() const { return std::sqrt(this->variance()); } + + /** short-hand operator to read new sample from input stream + * \n e.g.: `std::cin >> stats1;` + */ + friend std::istream &operator>>(std::istream &input, + stats_computer1 &stat) { + T val; + input >> val; + stat.new_val(val); + return input; + } + + private: + unsigned int n = 0; + double Ex, Ex2; + T K; +}; + +/** + * continuous mean and variance computance using + * Welford's algorithm (very accurate) + */ +template +class stats_computer2 { + public: + /** Constructor + * \param[in] x new data sample + */ + void new_val(T x) { + n++; + double delta = x - mu; + mu += delta / n; + double delta2 = x - mu; + M += delta * delta2; + } + + /** return sample mean computed till last sample */ + double mean() const { return mu; } + + /** return data variance computed till last sample */ + double variance() const { return M / n; } + + /** return sample standard deviation computed till last sample */ + double std() const { return std::sqrt(this->variance()); } + + /** short-hand operator to read new sample from input stream + * \n e.g.: `std::cin >> stats1;` + */ + friend std::istream &operator>>(std::istream &input, + stats_computer2 &stat) { + T val; + input >> val; + stat.new_val(val); + return input; + } + + private: + unsigned int n = 0; + double mu = 0, var = 0, M = 0; +}; + +} // namespace statistics + +using statistics::stats_computer1; +using statistics::stats_computer2; + +/** Test the algorithm implementation + * \param[in] test_data array of data to test the algorithms + */ +void test_function(const float *test_data, const int number_of_samples) { + float mean = 0.f, variance = 0.f; + + stats_computer1 stats01; + stats_computer2 stats02; + + for (int i = 0; i < number_of_samples; i++) { + stats01.new_val(test_data[i]); + stats02.new_val(test_data[i]); + mean += test_data[i]; + } + + mean /= number_of_samples; + + for (int i = 0; i < number_of_samples; i++) { + float temp = test_data[i] - mean; + variance += temp * temp; + } + variance /= number_of_samples; + + std::cout << "<<<<<<<< Test Function >>>>>>>>" << std::endl + << "Expected: Mean: " << mean << "\t Variance: " << variance + << std::endl; + std::cout << "\tMethod 1:" + << "\tMean: " << stats01.mean() + << "\t Variance: " << stats01.variance() + << "\t Std: " << stats01.std() << std::endl; + std::cout << "\tMethod 2:" + << "\tMean: " << stats02.mean() + << "\t Variance: " << stats02.variance() + << "\t Std: " << stats02.std() << std::endl; + + assert(std::abs(stats01.mean() - mean) < 0.01); + assert(std::abs(stats02.mean() - mean) < 0.01); + assert(std::abs(stats02.variance() - variance) < 0.01); + + std::cout << "(Tests passed)" << std::endl; +} + +/** Main function */ +int main(int argc, char **argv) { + const float test_data1[] = {3, 4, 5, -1.4, -3.6, 1.9, 1.}; + test_function(test_data1, sizeof(test_data1) / sizeof(test_data1[0])); + + std::cout + << "Enter data. Any non-numeric data will terminate the data input." + << std::endl; + + stats_computer1 stats1; + stats_computer2 stats2; + + while (1) { + double val; + std::cout << "Enter number: "; + std::cin >> val; + + // check for failure to read input. Happens for + // non-numeric data + if (std::cin.fail()) + break; + + stats1.new_val(val); + stats2.new_val(val); + + std::cout << "\tMethod 1:" + << "\tMean: " << stats1.mean() + << "\t Variance: " << stats1.variance() + << "\t Std: " << stats1.std() << std::endl; + std::cout << "\tMethod 2:" + << "\tMean: " << stats2.mean() + << "\t Variance: " << stats2.variance() + << "\t Std: " << stats2.std() << std::endl; + } + + return 0; +} diff --git a/math/sieve_of_eratosthenes.cpp b/math/sieve_of_eratosthenes.cpp index e600e480d7b..d8fa705313e 100644 --- a/math/sieve_of_eratosthenes.cpp +++ b/math/sieve_of_eratosthenes.cpp @@ -1,69 +1,65 @@ -/* - * Sieve of Eratosthenes is an algorithm to find the primes +/** + * @file + * @brief Get list of prime numbers using Sieve of Eratosthenes + * Sieve of Eratosthenes is an algorithm to find the primes * that is between 2 to N (as defined in main). * - * Time Complexity : O(N * log N) - * Space Complexity : O(N) + * Time Complexity : \f$O(N \cdot\log N)\f$ + *
Space Complexity : \f$O(N)\f$ + * + * @see primes_up_to_billion.cpp prime_numbers.cpp */ #include -using namespace std; +/** Maximum number of primes */ #define MAX 10000000 -int isprime[MAX]; +/** array to store the primes */ +bool isprime[MAX]; -/* - * This is the function that finds the primes and eliminates +/** + * This is the function that finds the primes and eliminates * the multiples. */ -void sieve(int N) -{ - isprime[0] = 0; - isprime[1] = 0; - for (int i = 2; i <= N; i++) - { - if (isprime[i]) - { - for (int j = i * 2; j <= N; j += i) - { - isprime[j] = 0; +void sieve(uint32_t N) { + isprime[0] = false; + isprime[1] = false; + for (uint32_t i = 2; i <= N; i++) { + if (isprime[i]) { + for (uint32_t j = (i << 1); j <= N; j += i) { + isprime[j] = false; } } } } -/* +/** * This function prints out the primes to STDOUT */ -void print(int N) -{ - for (int i = 1; i <= N; i++) - { - if (isprime[i] == 1) - { - cout << i << ' '; +void print(uint32_t N) { + for (uint32_t i = 1; i <= N; i++) { + if (isprime[i]) { + std::cout << i << ' '; } } - cout << '\n'; + std::cout << std::endl; } -/* - * NOTE: This function is important for the - * initialization of the array. +/** + * Initialize the array */ -void init() -{ - for (int i = 1; i < MAX; i++) - { - isprime[i] = 1; +void init() { + for (uint32_t i = 1; i < MAX; i++) { + isprime[i] = true; } } -int main() -{ - int N = 100; +/** main function */ +int main() { + uint32_t N = 100; init(); sieve(N); print(N); + return 0; } diff --git a/math/sqrt_double.cpp b/math/sqrt_double.cpp index 5a0fd1c88a5..c4beec9d8c6 100644 --- a/math/sqrt_double.cpp +++ b/math/sqrt_double.cpp @@ -1,27 +1,35 @@ -#include +/** + * @file + * @brief Calculate the square root of any positive real number in \f$O(\log + * N)\f$ time, with precision fixed using [bisection + * method](https://en.wikipedia.org/wiki/Bisection_method) of root-finding. + * + * @see Can be implemented using faster and better algorithms like + * newton_raphson_method.cpp and false_position.cpp + */ #include +#include -/* Calculate the square root of any -number in O(logn) time, -with precision fixed */ - -double Sqrt(double x) { - if ( x > 0 && x < 1 ) { - return 1/Sqrt(1/x); +/** Bisection method implemented for the function \f$x^2-a=0\f$ + * whose roots are \f$\pm\sqrt{a}\f$ and only the positive root is returned. + */ +double Sqrt(double a) { + if (a > 0 && a < 1) { + return 1 / Sqrt(1 / a); } - double l = 0, r = x; - /* Epsilon is the precision. - A great precision is + double l = 0, r = a; + /* Epsilon is the precision. + A great precision is between 1e-7 and 1e-12. double epsilon = 1e-12; */ double epsilon = 1e-12; - while ( l <= r ) { + while (l <= r) { double mid = (l + r) / 2; - if ( mid * mid > x ) { + if (mid * mid > a) { r = mid; } else { - if ( x - mid * mid < epsilon ) { + if (a - mid * mid < epsilon) { return mid; } l = mid; @@ -29,11 +37,13 @@ double Sqrt(double x) { } return -1; } + +/** main function */ int main() { - double n{}; - std::cin >> n; - assert(n >= 0); - // Change this line for a better precision - std::cout.precision(12); - std::cout << std::fixed << Sqrt(n); + double n{}; + std::cin >> n; + assert(n >= 0); + // Change this line for a better precision + std::cout.precision(12); + std::cout << std::fixed << Sqrt(n); } diff --git a/math/string_fibonacci.cpp b/math/string_fibonacci.cpp new file mode 100644 index 00000000000..eb9b6d7e1a7 --- /dev/null +++ b/math/string_fibonacci.cpp @@ -0,0 +1,89 @@ +/** + * @file + * @brief This Programme returns the Nth fibonacci as a string. + * + * The method used is manual addition with carry and placing it in a string + * which is called string addition This makes it have no bounds or limits + * + * @see fibonacci_large.cpp, fibonacci_fast.cpp, fibonacci.cpp + */ + +#include +#ifdef _MSC_VER +#include // use this for MS Visual C +#else +#include // otherwise +#endif + +/** + * function to add two string numbers + * \param [in] a first number in string to add + * \param [in] b second number in string to add + * \returns sum as a std::string + */ +std::string add(std::string a, std::string b) { + std::string temp = ""; + + // carry flag + int carry = 0; + + // fills up with zeros + while (a.length() < b.length()) { + a = "0" + a; + } + + // fills up with zeros + while (b.length() < a.length()) { + b = "0" + b; + } + + // adds the numbers a and b + for (int i = a.length() - 1; i >= 0; i--) { + char val = static_cast(((a[i] - 48) + (b[i] - 48)) + 48 + carry); + if (val > 57) { + carry = 1; + val -= 10; + } else { + carry = 0; + } + temp = val + temp; + } + + // processes the carry flag + if (carry == 1) { + temp = "1" + temp; + } + + // removes leading zeros. + while (temp[0] == '0' && temp.length() > 1) { + temp = temp.substr(1); + } + + return temp; +} + +/** Fibonacci iterator + * \param [in] n n^th Fibonacci number + */ +void fib_Accurate(uint64_t n) { + std::string tmp = ""; + std::string fibMinus1 = "1"; + std::string fibMinus2 = "0"; + for (uint64_t i = 0; i < n; i++) { + tmp = add(fibMinus1, fibMinus2); + fibMinus2 = fibMinus1; + fibMinus1 = tmp; + } + std::cout << fibMinus2; +} + +/** main function */ +int main() { + int n; + std::cout << "Enter whatever number N you want to find the fibonacci of\n"; + std::cin >> n; + std::cout << n << " th Fibonacci is \n"; + fib_Accurate(n); + + return 0; +} diff --git a/numerical_methods/CMakeLists.txt b/numerical_methods/CMakeLists.txt new file mode 100644 index 00000000000..fc4c343de30 --- /dev/null +++ b/numerical_methods/CMakeLists.txt @@ -0,0 +1,18 @@ +# If necessary, use the RELATIVE flag, otherwise each source file may be listed +# with full pathname. RELATIVE may makes it easier to extract an executable name +# automatically. +file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) +# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) +foreach( testsourcefile ${APP_SOURCES} ) + # I used a simple string replace, to cut off .cpp. + string( REPLACE ".cpp" "" testname ${testsourcefile} ) + add_executable( ${testname} ${testsourcefile} ) + + set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) + if(OpenMP_CXX_FOUND) + target_link_libraries(${testname} OpenMP::OpenMP_CXX) + endif() + install(TARGETS ${testname} DESTINATION "bin/numerical_methods") + +endforeach( testsourcefile ${APP_SOURCES} ) diff --git a/numerical_methods/bisection_method.cpp b/numerical_methods/bisection_method.cpp new file mode 100644 index 00000000000..c93c529d248 --- /dev/null +++ b/numerical_methods/bisection_method.cpp @@ -0,0 +1,75 @@ +/** + * \file + * \brief Solve the equation \f$f(x)=0\f$ using [bisection + * method](https://en.wikipedia.org/wiki/Bisection_method) + * + * Given two points \f$a\f$ and \f$b\f$ such that \f$f(a)<0\f$ and + * \f$f(b)>0\f$, then the \f$(i+1)^\text{th}\f$ approximation is given by: \f[ + * x_{i+1} = \frac{a_i+b_i}{2} + * \f] + * For the next iteration, the interval is selected + * as: \f$[a,x]\f$ if \f$x>0\f$ or \f$[x,b]\f$ if \f$x<0\f$. The Process is + * continued till a close enough approximation is achieved. + * + * \see newton_raphson_method.cpp, false_position.cpp, secant_method.cpp + */ +#include +#include +#include + +#define EPSILON \ + 1e-6 // std::numeric_limits::epsilon() ///< system accuracy limit +#define MAX_ITERATIONS 50000 ///< Maximum number of iterations to check + +/** define \f$f(x)\f$ to find root for + */ +static double eq(double i) { + return (std::pow(i, 3) - (4 * i) - 9); // original equation +} + +/** get the sign of any given number */ +template +int sgn(T val) { + return (T(0) < val) - (val < T(0)); +} + +/** main function */ +int main() { + double a = -1, b = 1, x, z; + int i; + + // loop to find initial intervals a, b + for (int i = 0; i < MAX_ITERATIONS; i++) { + z = eq(a); + x = eq(b); + if (sgn(z) == sgn(x)) { // same signs, increase interval + b++; + a--; + } else { // if opposite signs, we got our interval + break; + } + } + + std::cout << "\nFirst initial: " << a; + std::cout << "\nSecond initial: " << b; + + // start iterations + for (i = 0; i < MAX_ITERATIONS; i++) { + x = (a + b) / 2; + z = eq(x); + std::cout << "\n\nz: " << z << "\t[" << a << " , " << b + << " | Bisect: " << x << "]"; + + if (z < 0) { + a = x; + } else { + b = x; + } + + if (std::abs(z) < EPSILON) // stoping criteria + break; + } + + std::cout << "\n\nRoot: " << x << "\t\tSteps: " << i << std::endl; + return 0; +} diff --git a/numerical_methods/durand_kerner_roots.cpp b/numerical_methods/durand_kerner_roots.cpp new file mode 100644 index 00000000000..9bf0619b829 --- /dev/null +++ b/numerical_methods/durand_kerner_roots.cpp @@ -0,0 +1,339 @@ +/** + * @file + * \brief Compute all possible approximate roots of any given polynomial using + * [Durand Kerner + * algorithm](https://en.wikipedia.org/wiki/Durand%E2%80%93Kerner_method) + * \author [Krishna Vedala](https://github.com/kvedala) + * + * Test the algorithm online: + * https://gist.github.com/kvedala/27f1b0b6502af935f6917673ec43bcd7 + * + * Try the highly unstable Wilkinson's polynomial: + * ``` + * ./numerical_methods/durand_kerner_roots 1 -210 20615 -1256850 53327946 + * -1672280820 40171771630 -756111184500 11310276995381 -135585182899530 + * 1307535010540395 -10142299865511450 63030812099294896 -311333643161390640 + * 1206647803780373360 -3599979517947607200 8037811822645051776 + * -12870931245150988800 13803759753640704000 -8752948036761600000 + * 2432902008176640000 + * ``` + * Sample implementation results to compute approximate roots of the equation + * \f$x^4-1=0\f$:\n + * Error evolution during root approximations computed every
+ * iteration. Roots evolution - shows the initial approximation of the
+ * roots and their convergence to a final approximation along with the iterative
+ * approximations + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef _OPENMP +#include +#endif + +#define ACCURACY 1e-10 /**< maximum accuracy limit */ + +/** + * Evaluate the value of a polynomial with given coefficients + * \param[in] coeffs coefficients of the polynomial + * \param[in] x point at which to evaluate the polynomial + * \returns \f$f(x)\f$ + **/ +std::complex poly_function(const std::valarray &coeffs, + std::complex x) { + double real = 0.f, imag = 0.f; + int n; + + // #ifdef _OPENMP + // #pragma omp target teams distribute reduction(+ : real, imag) + // #endif + for (n = 0; n < coeffs.size(); n++) { + std::complex tmp = + coeffs[n] * std::pow(x, coeffs.size() - n - 1); + real += tmp.real(); + imag += tmp.imag(); + } + + return std::complex(real, imag); +} + +/** + * create a textual form of complex number + * \param[in] x point at which to evaluate the polynomial + * \returns pointer to converted string + */ +const char *complex_str(const std::complex &x) { +#define MAX_BUFF_SIZE 50 + static char msg[MAX_BUFF_SIZE]; + + std::snprintf(msg, MAX_BUFF_SIZE, "% 7.04g%+7.04gj", x.real(), x.imag()); + + return msg; +} + +/** + * check for termination condition + * \param[in] delta point at which to evaluate the polynomial + * \returns `false` if termination not reached + * \returns `true` if termination reached + */ +bool check_termination(long double delta) { + static long double past_delta = INFINITY; + if (std::abs(past_delta - delta) <= ACCURACY || delta < ACCURACY) + return true; + past_delta = delta; + return false; +} + +/** + * Implements Durand Kerner iterative algorithm to compute all roots of a + * polynomial. + * + * \param[in] coeffs coefficients of the polynomial + * \param[out] roots the computed roots of the polynomial + * \param[in] write_log flag whether to save the log file (default = `false`) + * \returns pair of values - number of iterations taken and final accuracy + * achieved + */ +std::pair durand_kerner_algo( + const std::valarray &coeffs, + std::valarray> *roots, bool write_log = false) { + long double tol_condition = 1; + uint32_t iter = 0; + int n; + std::ofstream log_file; + + if (write_log) { + /* + * store intermediate values to a CSV file + */ + log_file.open("durand_kerner.log.csv"); + if (!log_file.is_open()) { + perror("Unable to create a storage log file!"); + std::exit(EXIT_FAILURE); + } + log_file << "iter#,"; + + for (n = 0; n < roots->size(); n++) log_file << "root_" << n << ","; + + log_file << "avg. correction"; + log_file << "\n0,"; + for (n = 0; n < roots->size(); n++) + log_file << complex_str((*roots)[n]) << ","; + } + + bool break_loop = false; + while (!check_termination(tol_condition) && iter < INT16_MAX && + !break_loop) { + tol_condition = 0; + iter++; + break_loop = false; + + if (log_file.is_open()) + log_file << "\n" << iter << ","; + +#ifdef _OPENMP +#pragma omp parallel for shared(break_loop, tol_condition) +#endif + for (n = 0; n < roots->size(); n++) { + if (break_loop) + continue; + + std::complex numerator, denominator; + numerator = poly_function(coeffs, (*roots)[n]); + denominator = 1.0; + for (int i = 0; i < roots->size(); i++) + if (i != n) + denominator *= (*roots)[n] - (*roots)[i]; + + std::complex delta = numerator / denominator; + + if (std::isnan(std::abs(delta)) || std::isinf(std::abs(delta))) { + std::cerr << "\n\nOverflow/underrun error - got value = " + << std::abs(delta) << "\n"; + // return std::pair(iter, tol_condition); + break_loop = true; + } + + (*roots)[n] -= delta; + +#ifdef _OPENMP +#pragma omp critical +#endif + tol_condition = std::max(tol_condition, std::abs(std::abs(delta))); + } + // tol_condition /= (degree - 1); + + if (break_loop) + break; + + if (log_file.is_open()) { + for (n = 0; n < roots->size(); n++) + log_file << complex_str((*roots)[n]) << ","; + } + +#if defined(DEBUG) || !defined(NDEBUG) + if (iter % 500 == 0) { + std::cout << "Iter: " << iter << "\t"; + for (n = 0; n < roots->size(); n++) + std::cout << "\t" << complex_str((*roots)[n]); + std::cout << "\t\tabsolute average change: " << tol_condition + << "\n"; + } +#endif + + if (log_file.is_open()) + log_file << tol_condition; + } + + return std::pair(iter, tol_condition); +} + +/** + * Self test the algorithm by checking the roots for \f$x^2+4=0\f$ to which the + * roots are \f$0 \pm 2i\f$ + */ +void test1() { + const std::valarray coeffs = {1, 0, 4}; // x^2 - 2 = 0 + std::valarray> roots(2); + std::valarray> expected = { + std::complex(0., 2.), + std::complex(0., -2.) // known expected roots + }; + + /* initialize root approximations with random values */ + for (int n = 0; n < roots.size(); n++) { + roots[n] = std::complex(std::rand() % 100, std::rand() % 100); + roots[n] -= 50.f; + roots[n] /= 25.f; + } + + auto result = durand_kerner_algo(coeffs, &roots, false); + + for (int i = 0; i < roots.size(); i++) { + // check if approximations are have < 0.1% error with one of the + // expected roots + bool err1 = false; + for (int j = 0; j < roots.size(); j++) + err1 |= std::abs(std::abs(roots[i] - expected[j])) < 1e-3; + assert(err1); + } + + std::cout << "Test 1 passed! - " << result.first << " iterations, " + << result.second << " accuracy" + << "\n"; +} + +/** + * Self test the algorithm by checking the roots for \f$0.015625x^3-1=0\f$ to + * which the roots are \f$(4+0i),\,(-2\pm3.464i)\f$ + */ +void test2() { + const std::valarray coeffs = {// 0.015625 x^3 - 1 = 0 + 1. / 64., 0., 0., -1.}; + std::valarray> roots(3); + const std::valarray> expected = { + std::complex(4., 0.), std::complex(-2., 3.46410162), + std::complex(-2., -3.46410162) // known expected roots + }; + + /* initialize root approximations with random values */ + for (int n = 0; n < roots.size(); n++) { + roots[n] = std::complex(std::rand() % 100, std::rand() % 100); + roots[n] -= 50.f; + roots[n] /= 25.f; + } + + auto result = durand_kerner_algo(coeffs, &roots, false); + + for (int i = 0; i < roots.size(); i++) { + // check if approximations are have < 0.1% error with one of the + // expected roots + bool err1 = false; + for (int j = 0; j < roots.size(); j++) + err1 |= std::abs(std::abs(roots[i] - expected[j])) < 1e-3; + assert(err1); + } + + std::cout << "Test 2 passed! - " << result.first << " iterations, " + << result.second << " accuracy" + << "\n"; +} + +/*** + * Main function. + * The comandline input arguments are taken as coeffiecients of a + *polynomial. For example, this command + * ```sh + * ./durand_kerner_roots 1 0 -4 + * ``` + * will find roots of the polynomial \f$1\cdot x^2 + 0\cdot x^1 + (-4)=0\f$ + **/ +int main(int argc, char **argv) { + /* initialize random seed: */ + std::srand(std::time(nullptr)); + + if (argc < 2) { + test1(); // run tests when no input is provided + test2(); // and skip tests when input polynomial is provided + std::cout << "Please pass the coefficients of the polynomial as " + "commandline " + "arguments.\n"; + return 0; + } + + int n, degree = argc - 1; // detected polynomial degree + std::valarray coeffs(degree); // create coefficiencts array + + // number of roots = degree - 1 + std::valarray> s0(degree - 1); + + std::cout << "Computing the roots for:\n\t"; + for (n = 0; n < degree; n++) { + coeffs[n] = strtod(argv[n + 1], nullptr); + if (n < degree - 1 && coeffs[n] != 0) + std::cout << "(" << coeffs[n] << ") x^" << degree - n - 1 << " + "; + else if (coeffs[n] != 0) + std::cout << "(" << coeffs[n] << ") x^" << degree - n - 1 + << " = 0\n"; + + /* initialize root approximations with random values */ + if (n < degree - 1) { + s0[n] = std::complex(std::rand() % 100, std::rand() % 100); + s0[n] -= 50.f; + s0[n] /= 50.f; + } + } + + // numerical errors less when the first coefficient is "1" + // hence, we normalize the first coefficient + { + double tmp = coeffs[0]; + coeffs /= tmp; + } + + clock_t end_time, start_time = clock(); + auto result = durand_kerner_algo(coeffs, &s0, true); + end_time = clock(); + + std::cout << "\nIterations: " << result.first << "\n"; + for (n = 0; n < degree - 1; n++) + std::cout << "\t" << complex_str(s0[n]) << "\n"; + std::cout << "absolute average change: " << result.second << "\n"; + std::cout << "Time taken: " + << static_cast(end_time - start_time) / CLOCKS_PER_SEC + << " sec\n"; + + return 0; +} diff --git a/numerical_methods/false_position.cpp b/numerical_methods/false_position.cpp new file mode 100644 index 00000000000..aebd154bb07 --- /dev/null +++ b/numerical_methods/false_position.cpp @@ -0,0 +1,74 @@ +/** + * \file + * \brief Solve the equation \f$f(x)=0\f$ using [false position + * method](https://en.wikipedia.org/wiki/Regula_falsi), also known as the Secant + * method + * + * Given two points \f$a\f$ and \f$b\f$ such that \f$f(a)<0\f$ and + * \f$f(b)>0\f$, then the \f$(i+1)^\text{th}\f$ approximation is given by: \f[ + * x_{i+1} = \frac{a_i\cdot f(b_i) - b_i\cdot f(a_i)}{f(b_i) - f(a_i)} + * \f] + * For the next iteration, the interval is selected + * as: \f$[a,x]\f$ if \f$x>0\f$ or \f$[x,b]\f$ if \f$x<0\f$. The Process is + * continued till a close enough approximation is achieved. + * + * \see newton_raphson_method.cpp, bisection_method.cpp + */ +#include +#include +#include +#include + +#define EPSILON \ + 1e-6 // std::numeric_limits::epsilon() ///< system accuracy limit +#define MAX_ITERATIONS 50000 ///< Maximum number of iterations to check + +/** define \f$f(x)\f$ to find root for + */ +static double eq(double i) { + return (std::pow(i, 3) - (4 * i) - 9); // origial equation +} + +/** get the sign of any given number */ +template +int sgn(T val) { + return (T(0) < val) - (val < T(0)); +} + +/** main function */ +int main() { + double a = -1, b = 1, x, z, m, n, c; + int i; + + // loop to find initial intervals a, b + for (int i = 0; i < MAX_ITERATIONS; i++) { + z = eq(a); + x = eq(b); + if (sgn(z) == sgn(x)) { // same signs, increase interval + b++; + a--; + } else { // if opposite signs, we got our interval + break; + } + } + + std::cout << "\nFirst initial: " << a; + std::cout << "\nSecond initial: " << b; + + for (i = 0; i < MAX_ITERATIONS; i++) { + m = eq(a); + n = eq(b); + + c = ((a * n) - (b * m)) / (n - m); + + a = c; + z = eq(c); + + if (std::abs(z) < EPSILON) { // stoping criteria + break; + } + } + + std::cout << "\n\nRoot: " << c << "\t\tSteps: " << i << std::endl; + return 0; +} diff --git a/numerical_methods/gaussian_elimination.cpp b/numerical_methods/gaussian_elimination.cpp new file mode 100644 index 00000000000..60b5648ec84 --- /dev/null +++ b/numerical_methods/gaussian_elimination.cpp @@ -0,0 +1,76 @@ +/** + * \file + * \brief [Gaussian elimination + * method](https://en.wikipedia.org/wiki/Gaussian_elimination) + */ +#include + +/** Main function */ +int main() { + int mat_size, i, j, step; + + std::cout << "Matrix size: "; + std::cin >> mat_size; + + // create a 2D matrix by dynamic memory allocation + double **mat = new double *[mat_size + 1], **x = new double *[mat_size]; + for (i = 0; i <= mat_size; i++) { + mat[i] = new double[mat_size + 1]; + if (i < mat_size) + x[i] = new double[mat_size + 1]; + } + + // get the matrix elements from user + std::cout << std::endl << "Enter value of the matrix: " << std::endl; + for (i = 0; i < mat_size; i++) { + for (j = 0; j <= mat_size; j++) { + std::cin >> + mat[i][j]; // Enter (mat_size*mat_size) value of the matrix. + } + } + + // perform Gaussian elimination + for (step = 0; step < mat_size - 1; step++) { + for (i = step; i < mat_size - 1; i++) { + double a = (mat[i + 1][step] / mat[step][step]); + + for (j = step; j <= mat_size; j++) + mat[i + 1][j] = mat[i + 1][j] - (a * mat[step][j]); + } + } + + std::cout << std::endl + << "Matrix using Gaussian Elimination method: " << std::endl; + for (i = 0; i < mat_size; i++) { + for (j = 0; j <= mat_size; j++) { + x[i][j] = mat[i][j]; + std::cout << mat[i][j] << " "; + } + std::cout << std::endl; + } + std::cout << std::endl + << "Value of the Gaussian Elimination method: " << std::endl; + for (i = mat_size - 1; i >= 0; i--) { + double sum = 0; + for (j = mat_size - 1; j > i; j--) { + x[i][j] = x[j][j] * x[i][j]; + sum = x[i][j] + sum; + } + if (x[i][i] == 0) + x[i][i] = 0; + else + x[i][i] = (x[i][mat_size] - sum) / (x[i][i]); + + std::cout << "x" << i << "= " << x[i][i] << std::endl; + } + + for (i = 0; i <= mat_size; i++) { + delete[] mat[i]; + if (i < mat_size) + delete[] x[i]; + } + delete[] mat; + delete[] x; + + return 0; +} diff --git a/numerical_methods/lu_decompose.cpp b/numerical_methods/lu_decompose.cpp new file mode 100644 index 00000000000..a0a2d00ab2a --- /dev/null +++ b/numerical_methods/lu_decompose.cpp @@ -0,0 +1,126 @@ +/** + * \file + * \brief [LU decomposition](https://en.wikipedia.org/wiki/LU_decompositon) of a + * square matrix + * \author [Krishna Vedala](https://github.com/kvedala) + */ +#include +#include +#include +#include +#ifdef _OPENMP +#include +#endif + +/** Perform LU decomposition on matrix + * \param[in] A matrix to decompose + * \param[out] L output L matrix + * \param[out] U output U matrix + * \returns 0 if no errors + * \returns negative if error occurred + */ +int lu_decomposition(const std::vector> &A, + std::vector> *L, + std::vector> *U) { + int row, col, j; + int mat_size = A.size(); + + if (mat_size != A[0].size()) { + // check matrix is a square matrix + std::cerr << "Not a square matrix!\n"; + return -1; + } + + // regularize each row + for (row = 0; row < mat_size; row++) { + // Upper triangular matrix +#ifdef _OPENMP +#pragma omp for +#endif + for (col = row; col < mat_size; col++) { + // Summation of L[i,j] * U[j,k] + double lu_sum = 0.; + for (j = 0; j < row; j++) lu_sum += L[0][row][j] * U[0][j][col]; + + // Evaluate U[i,k] + U[0][row][col] = A[row][col] - lu_sum; + } + + // Lower triangular matrix +#ifdef _OPENMP +#pragma omp for +#endif + for (col = row; col < mat_size; col++) { + if (row == col) { + L[0][row][col] = 1.; + continue; + } + + // Summation of L[i,j] * U[j,k] + double lu_sum = 0.; + for (j = 0; j < row; j++) lu_sum += L[0][col][j] * U[0][j][row]; + + // Evaluate U[i,k] + L[0][col][row] = (A[col][row] - lu_sum) / U[0][row][row]; + } + } + + return 0; +} + +/** + * operator to print a matrix + */ +template +std::ostream &operator<<(std::ostream &out, + std::vector> const &v) { + const int width = 10; + const char separator = ' '; + + for (size_t row = 0; row < v.size(); row++) { + for (size_t col = 0; col < v[row].size(); col++) + out << std::left << std::setw(width) << std::setfill(separator) + << v[row][col]; + out << std::endl; + } + + return out; +} + +/** Main function */ +int main(int argc, char **argv) { + int mat_size = 3; // default matrix size + const int range = 50; + const int range2 = range >> 1; + + if (argc == 2) + mat_size = atoi(argv[1]); + + std::srand(std::time(NULL)); // random number initializer + + /* Create a square matrix with random values */ + std::vector> A(mat_size); + std::vector> L(mat_size); // output + std::vector> U(mat_size); // output + for (int i = 0; i < mat_size; i++) { + // calloc so that all valeus are '0' by default + A[i] = std::vector(mat_size); + L[i] = std::vector(mat_size); + U[i] = std::vector(mat_size); + for (int j = 0; j < mat_size; j++) + /* create random values in the limits [-range2, range-1] */ + A[i][j] = static_cast(std::rand() % range - range2); + } + + std::clock_t start_t = std::clock(); + lu_decomposition(A, &L, &U); + std::clock_t end_t = std::clock(); + std::cout << "Time taken: " + << static_cast(end_t - start_t) / CLOCKS_PER_SEC << "\n"; + + std::cout << "A = \n" << A << "\n"; + std::cout << "L = \n" << L << "\n"; + std::cout << "U = \n" << U << "\n"; + + return 0; +} diff --git a/numerical_methods/newton_raphson_method.cpp b/numerical_methods/newton_raphson_method.cpp new file mode 100644 index 00000000000..d086123ca15 --- /dev/null +++ b/numerical_methods/newton_raphson_method.cpp @@ -0,0 +1,59 @@ +/** + * \file + * \brief Solve the equation \f$f(x)=0\f$ using [Newton-Raphson + * method](https://en.wikipedia.org/wiki/Newton%27s_method) for both real and + * complex solutions + * + * The \f$(i+1)^\text{th}\f$ approximation is given by: + * \f[ + * x_{i+1} = x_i - \frac{f(x_i)}{f'(x_i)} + * \f] + * + * \author [Krishna Vedala](https://github.com/kvedala) + * \see bisection_method.cpp, false_position.cpp + */ +#include +#include +#include +#include + +#define EPSILON \ + 1e-6 // std::numeric_limits::epsilon() ///< system accuracy limit +#define MAX_ITERATIONS 50000 ///< Maximum number of iterations to check + +/** define \f$f(x)\f$ to find root for + */ +static double eq(double i) { + return (std::pow(i, 3) - (4 * i) - 9); // original equation +} + +/** define the derivative function \f$f'(x)\f$ + */ +static double eq_der(double i) { + return ((3 * std::pow(i, 2)) - 4); // derivative of equation +} + +/** Main function */ +int main() { + std::srand(std::time(nullptr)); // initialize randomizer + + double z, c = std::rand() % 100, m, n; + int i; + + std::cout << "\nInitial approximation: " << c; + + // start iterations + for (i = 0; i < MAX_ITERATIONS; i++) { + m = eq(c); + n = eq_der(c); + + z = c - (m / n); + c = z; + + if (std::abs(m) < EPSILON) // stoping criteria + break; + } + + std::cout << "\n\nRoot: " << z << "\t\tSteps: " << i << std::endl; + return 0; +} diff --git a/numerical_methods/ode_forward_euler.cpp b/numerical_methods/ode_forward_euler.cpp new file mode 100644 index 00000000000..a4455c57acd --- /dev/null +++ b/numerical_methods/ode_forward_euler.cpp @@ -0,0 +1,210 @@ +/** + * \file + * \authors [Krishna Vedala](https://github.com/kvedala) + * \brief Solve a multivariable first order [ordinary differential equation + * (ODEs)](https://en.wikipedia.org/wiki/Ordinary_differential_equation) using + * [forward Euler + * method](https://en.wikipedia.org/wiki/Numerical_methods_for_ordinary_differential_equations#Euler_method) + * + * \details + * The ODE being solved is: + * \f{eqnarray*}{ + * \dot{u} &=& v\\ + * \dot{v} &=& -\omega^2 u\\ + * \omega &=& 1\\ + * [x_0, u_0, v_0] &=& [0,1,0]\qquad\ldots\text{(initial values)} + * \f} + * The exact solution for the above problem is: + * \f{eqnarray*}{ + * u(x) &=& \cos(x)\\ + * v(x) &=& -\sin(x)\\ + * \f} + * The computation results are stored to a text file `forward_euler.csv` and the + * exact soltuion results in `exact.csv` for comparison. + * Implementation solution + * + * To implement [Van der Pol + * oscillator](https://en.wikipedia.org/wiki/Van_der_Pol_oscillator), change the + * ::problem function to: + * ```cpp + * const double mu = 2.0; + * dy[0] = y[1]; + * dy[1] = mu * (1.f - y[0] * y[0]) * y[1] - y[0]; + * ``` + * \see ode_midpoint_euler.cpp, ode_semi_implicit_euler.cpp + */ + +#include +#include +#include +#include +#include + +/** + * @brief Problem statement for a system with first-order differential + * equations. Updates the system differential variables. + * \note This function can be updated to and ode of any order. + * + * @param[in] x independent variable(s) + * @param[in,out] y dependent variable(s) + * @param[in,out] dy first-derivative of dependent variable(s) + */ +void problem(const double &x, std::valarray *y, + std::valarray *dy) { + const double omega = 1.F; // some const for the problem + dy[0][0] = y[0][1]; // x dot + dy[0][1] = -omega * omega * y[0][0]; // y dot +} + +/** + * @brief Exact solution of the problem. Used for solution comparison. + * + * @param[in] x independent variable + * @param[in,out] y dependent variable + */ +void exact_solution(const double &x, std::valarray *y) { + y[0][0] = std::cos(x); + y[0][1] = -std::sin(x); +} + +/** \addtogroup ode Ordinary Differential Equations + * Integration functions for implementations with solving [ordinary differential + * equations](https://en.wikipedia.org/wiki/Ordinary_differential_equation) + * (ODEs) of any order and and any number of independent variables. + * @{ + */ +/** + * @brief Compute next step approximation using the forward-Euler + * method. @f[y_{n+1}=y_n + dx\cdot f\left(x_n,y_n\right)@f] + * @param[in] dx step size + * @param[in] x take \f$x_n\f$ and compute \f$x_{n+1}\f$ + * @param[in,out] y take \f$y_n\f$ and compute \f$y_{n+1}\f$ + * @param[in,out] dy compute \f$f\left(x_n,y_n\right)\f$ + */ +void forward_euler_step(const double dx, const double &x, + std::valarray *y, std::valarray *dy) { + problem(x, y, dy); + y[0] += dy[0] * dx; +} + +/** + * @brief Compute approximation using the forward-Euler + * method in the given limits. + * @param[in] dx step size + * @param[in] x0 initial value of independent variable + * @param[in] x_max final value of independent variable + * @param[in,out] y take \f$y_n\f$ and compute \f$y_{n+1}\f$ + * @param[in] save_to_file flag to save results to a CSV file (1) or not (0) + * @returns time taken for computation in seconds + */ +double forward_euler(double dx, double x0, double x_max, + std::valarray *y, bool save_to_file = false) { + std::valarray dy = y[0]; + + std::ofstream fp; + if (save_to_file) { + fp.open("forward_euler.csv", std::ofstream::out); + if (!fp.is_open()) { + std::perror("Error! "); + } + } + + std::size_t L = y->size(); + + /* start integration */ + std::clock_t t1 = std::clock(); + double x = x0; + + do { // iterate for each step of independent variable + if (save_to_file && fp.is_open()) { + // write to file + fp << x << ","; + for (int i = 0; i < L - 1; i++) { + fp << y[0][i] << ","; + } + fp << y[0][L - 1] << "\n"; + } + + forward_euler_step(dx, x, y, &dy); // perform integration + x += dx; // update step + } while (x <= x_max); // till upper limit of independent variable + /* end of integration */ + std::clock_t t2 = std::clock(); + + if (fp.is_open()) + fp.close(); + + return static_cast(t2 - t1) / CLOCKS_PER_SEC; +} + +/** @} */ + +/** + * Function to compute and save exact solution for comparison + * + * \param [in] X0 initial value of independent variable + * \param [in] X_MAX final value of independent variable + * \param [in] step_size independent variable step size + * \param [in] Y0 initial values of dependent variables + */ +void save_exact_solution(const double &X0, const double &X_MAX, + const double &step_size, + const std::valarray &Y0) { + double x = X0; + std::valarray y = Y0; + + std::ofstream fp("exact.csv", std::ostream::out); + if (!fp.is_open()) { + std::perror("Error! "); + return; + } + std::cout << "Finding exact solution\n"; + + std::clock_t t1 = std::clock(); + do { + fp << x << ","; + for (int i = 0; i < y.size() - 1; i++) { + fp << y[i] << ","; + } + fp << y[y.size() - 1] << "\n"; + + exact_solution(x, &y); + + x += step_size; + } while (x <= X_MAX); + + std::clock_t t2 = std::clock(); + double total_time = static_cast(t2 - t1) / CLOCKS_PER_SEC; + std::cout << "\tTime = " << total_time << " ms\n"; + + fp.close(); +} + +/** + * Main Function + */ +int main(int argc, char *argv[]) { + double X0 = 0.f; /* initial value of x0 */ + double X_MAX = 10.F; /* upper limit of integration */ + std::valarray Y0 = {1.f, 0.f}; /* initial value Y = y(x = x_0) */ + double step_size; + + if (argc == 1) { + std::cout << "\nEnter the step size: "; + std::cin >> step_size; + } else { + // use commandline argument as independent variable step size + step_size = std::atof(argv[1]); + } + + // get approximate solution + double total_time = forward_euler(step_size, X0, X_MAX, &Y0, true); + std::cout << "\tTime = " << total_time << " ms\n"; + + /* compute exact solution for comparion */ + save_exact_solution(X0, X_MAX, step_size, Y0); + + return 0; +} diff --git a/numerical_methods/ode_midpoint_euler.cpp b/numerical_methods/ode_midpoint_euler.cpp new file mode 100644 index 00000000000..50cf4e4c6c4 --- /dev/null +++ b/numerical_methods/ode_midpoint_euler.cpp @@ -0,0 +1,214 @@ +/** + * \file + * \authors [Krishna Vedala](https://github.com/kvedala) + * \brief Solve a multivariable first order [ordinary differential equation + * (ODEs)](https://en.wikipedia.org/wiki/Ordinary_differential_equation) using + * [midpoint Euler + * method](https://en.wikipedia.org/wiki/Midpoint_method) + * + * \details + * The ODE being solved is: + * \f{eqnarray*}{ + * \dot{u} &=& v\\ + * \dot{v} &=& -\omega^2 u\\ + * \omega &=& 1\\ + * [x_0, u_0, v_0] &=& [0,1,0]\qquad\ldots\text{(initial values)} + * \f} + * The exact solution for the above problem is: + * \f{eqnarray*}{ + * u(x) &=& \cos(x)\\ + * v(x) &=& -\sin(x)\\ + * \f} + * The computation results are stored to a text file `midpoint_euler.csv` and + * the exact soltuion results in `exact.csv` for comparison. Implementation solution + * + * To implement [Van der Pol + * oscillator](https://en.wikipedia.org/wiki/Van_der_Pol_oscillator), change the + * ::problem function to: + * ```cpp + * const double mu = 2.0; + * dy[0] = y[1]; + * dy[1] = mu * (1.f - y[0] * y[0]) * y[1] - y[0]; + * ``` + * \see ode_forward_euler.cpp, ode_semi_implicit_euler.cpp + */ + +#include +#include +#include +#include +#include + +/** + * @brief Problem statement for a system with first-order differential + * equations. Updates the system differential variables. + * \note This function can be updated to and ode of any order. + * + * @param[in] x independent variable(s) + * @param[in,out] y dependent variable(s) + * @param[in,out] dy first-derivative of dependent variable(s) + */ +void problem(const double &x, std::valarray *y, + std::valarray *dy) { + const double omega = 1.F; // some const for the problem + dy[0][0] = y[0][1]; // x dot + dy[0][1] = -omega * omega * y[0][0]; // y dot +} + +/** + * @brief Exact solution of the problem. Used for solution comparison. + * + * @param[in] x independent variable + * @param[in,out] y dependent variable + */ +void exact_solution(const double &x, std::valarray *y) { + y[0][0] = std::cos(x); + y[0][1] = -std::sin(x); +} + +/** \addtogroup ode Ordinary Differential Equations + * @{ + */ +/** + * @brief Compute next step approximation using the midpoint-Euler + * method. + * @f[y_{n+1} = y_n + dx\, f\left(x_n+\frac{1}{2}dx, + * y_n + \frac{1}{2}dx\,f\left(x_n,y_n\right)\right)@f] + * + * @param[in] dx step size + * @param[in] x take \f$x_n\f$ and compute \f$x_{n+1}\f$ + * @param[in,out] y take \f$y_n\f$ and compute \f$y_{n+1}\f$ + * @param[in,out] dy compute \f$f\left(x_n,y_n\right)\f$ + */ +void midpoint_euler_step(const double dx, const double &x, + std::valarray *y, std::valarray *dy) { + problem(x, y, dy); + double tmp_x = x + 0.5 * dx; + + std::valarray tmp_y = y[0] + dy[0] * (0.5 * dx); + + problem(tmp_x, &tmp_y, dy); + + y[0] += dy[0] * dx; +} + +/** + * @brief Compute approximation using the midpoint-Euler + * method in the given limits. + * @param[in] dx step size + * @param[in] x0 initial value of independent variable + * @param[in] x_max final value of independent variable + * @param[in,out] y take \f$y_n\f$ and compute \f$y_{n+1}\f$ + * @param[in] save_to_file flag to save results to a CSV file (1) or not (0) + * @returns time taken for computation in seconds + */ +double midpoint_euler(double dx, double x0, double x_max, + std::valarray *y, bool save_to_file = false) { + std::valarray dy = y[0]; + + std::ofstream fp; + if (save_to_file) { + fp.open("midpoint_euler.csv", std::ofstream::out); + if (!fp.is_open()) { + std::perror("Error! "); + } + } + + std::size_t L = y->size(); + + /* start integration */ + std::clock_t t1 = std::clock(); + double x = x0; + do { // iterate for each step of independent variable + if (save_to_file && fp.is_open()) { + // write to file + fp << x << ","; + for (int i = 0; i < L - 1; i++) { + fp << y[0][i] << ","; + } + fp << y[0][L - 1] << "\n"; + } + + midpoint_euler_step(dx, x, y, &dy); // perform integration + x += dx; // update step + } while (x <= x_max); // till upper limit of independent variable + /* end of integration */ + std::clock_t t2 = std::clock(); + + if (fp.is_open()) + fp.close(); + + return static_cast(t2 - t1) / CLOCKS_PER_SEC; +} + +/** @} */ + +/** + * Function to compute and save exact solution for comparison + * + * \param [in] X0 initial value of independent variable + * \param [in] X_MAX final value of independent variable + * \param [in] step_size independent variable step size + * \param [in] Y0 initial values of dependent variables + */ +void save_exact_solution(const double &X0, const double &X_MAX, + const double &step_size, + const std::valarray &Y0) { + double x = X0; + std::valarray y = Y0; + + std::ofstream fp("exact.csv", std::ostream::out); + if (!fp.is_open()) { + std::perror("Error! "); + return; + } + std::cout << "Finding exact solution\n"; + + std::clock_t t1 = std::clock(); + do { + fp << x << ","; + for (int i = 0; i < y.size() - 1; i++) { + fp << y[i] << ","; + } + fp << y[y.size() - 1] << "\n"; + + exact_solution(x, &y); + + x += step_size; + } while (x <= X_MAX); + + std::clock_t t2 = std::clock(); + double total_time = static_cast(t2 - t1) / CLOCKS_PER_SEC; + std::cout << "\tTime = " << total_time << " ms\n"; + + fp.close(); +} + +/** + * Main Function + */ +int main(int argc, char *argv[]) { + double X0 = 0.f; /* initial value of x0 */ + double X_MAX = 10.F; /* upper limit of integration */ + std::valarray Y0 = {1.f, 0.f}; /* initial value Y = y(x = x_0) */ + double step_size; + + if (argc == 1) { + std::cout << "\nEnter the step size: "; + std::cin >> step_size; + } else { + // use commandline argument as independent variable step size + step_size = std::atof(argv[1]); + } + + // get approximate solution + double total_time = midpoint_euler(step_size, X0, X_MAX, &Y0, true); + std::cout << "\tTime = " << total_time << " ms\n"; + + /* compute exact solution for comparion */ + save_exact_solution(X0, X_MAX, step_size, Y0); + + return 0; +} diff --git a/numerical_methods/ode_semi_implicit_euler.cpp b/numerical_methods/ode_semi_implicit_euler.cpp new file mode 100644 index 00000000000..01904ac1684 --- /dev/null +++ b/numerical_methods/ode_semi_implicit_euler.cpp @@ -0,0 +1,211 @@ +/** + * \file + * \authors [Krishna Vedala](https://github.com/kvedala) + * \brief Solve a multivariable first order [ordinary differential equation + * (ODEs)](https://en.wikipedia.org/wiki/Ordinary_differential_equation) using + * [semi implicit Euler + * method](https://en.wikipedia.org/wiki/Semi-implicit_Euler_method) + * + * \details + * The ODE being solved is: + * \f{eqnarray*}{ + * \dot{u} &=& v\\ + * \dot{v} &=& -\omega^2 u\\ + * \omega &=& 1\\ + * [x_0, u_0, v_0] &=& [0,1,0]\qquad\ldots\text{(initial values)} + * \f} + * The exact solution for the above problem is: + * \f{eqnarray*}{ + * u(x) &=& \cos(x)\\ + * v(x) &=& -\sin(x)\\ + * \f} + * The computation results are stored to a text file `semi_implicit_euler.csv` + * and the exact soltuion results in `exact.csv` for comparison. Implementation solution + * + * To implement [Van der Pol + * oscillator](https://en.wikipedia.org/wiki/Van_der_Pol_oscillator), change the + * ::problem function to: + * ```cpp + * const double mu = 2.0; + * dy[0] = y[1]; + * dy[1] = mu * (1.f - y[0] * y[0]) * y[1] - y[0]; + * ``` + * \see ode_midpoint_euler.cpp, ode_forward_euler.cpp + */ + +#include +#include +#include +#include +#include + +/** + * @brief Problem statement for a system with first-order differential + * equations. Updates the system differential variables. + * \note This function can be updated to and ode of any order. + * + * @param[in] x independent variable(s) + * @param[in,out] y dependent variable(s) + * @param[in,out] dy first-derivative of dependent variable(s) + */ +void problem(const double &x, std::valarray *y, + std::valarray *dy) { + const double omega = 1.F; // some const for the problem + dy[0][0] = y[0][1]; // x dot + dy[0][1] = -omega * omega * y[0][0]; // y dot +} + +/** + * @brief Exact solution of the problem. Used for solution comparison. + * + * @param[in] x independent variable + * @param[in,out] y dependent variable + */ +void exact_solution(const double &x, std::valarray *y) { + y[0][0] = std::cos(x); + y[0][1] = -std::sin(x); +} + +/** \addtogroup ode Ordinary Differential Equations + * @{ + */ +/** + * @brief Compute next step approximation using the semi-implicit-Euler + * method. @f[y_{n+1}=y_n + dx\cdot f\left(x_n,y_n\right)@f] + * @param[in] dx step size + * @param[in] x take \f$x_n\f$ and compute \f$x_{n+1}\f$ + * @param[in,out] y take \f$y_n\f$ and compute \f$y_{n+1}\f$ + * @param[in,out] dy compute \f$f\left(x_n,y_n\right)\f$ + */ +void semi_implicit_euler_step(const double dx, const double &x, + std::valarray *y, + std::valarray *dy) { + problem(x, y, dy); // update dy once + y[0][0] += dx * dy[0][0]; // update y0 + problem(x, y, dy); // update dy once more + + dy[0][0] = 0.f; // ignore y0 + y[0] += dy[0] * dx; // update remaining using new dy +} + +/** + * @brief Compute approximation using the semi-implicit-Euler + * method in the given limits. + * @param[in] dx step size + * @param[in] x0 initial value of independent variable + * @param[in] x_max final value of independent variable + * @param[in,out] y take \f$y_n\f$ and compute \f$y_{n+1}\f$ + * @param[in] save_to_file flag to save results to a CSV file (1) or not (0) + * @returns time taken for computation in seconds + */ +double semi_implicit_euler(double dx, double x0, double x_max, + std::valarray *y, + bool save_to_file = false) { + std::valarray dy = y[0]; + + std::ofstream fp; + if (save_to_file) { + fp.open("semi_implicit_euler.csv", std::ofstream::out); + if (!fp.is_open()) { + std::perror("Error! "); + } + } + + std::size_t L = y->size(); + + /* start integration */ + std::clock_t t1 = std::clock(); + double x = x0; + do { // iterate for each step of independent variable + if (save_to_file && fp.is_open()) { + // write to file + fp << x << ","; + for (int i = 0; i < L - 1; i++) { + fp << y[0][i] << ","; + } + fp << y[0][L - 1] << "\n"; + } + + semi_implicit_euler_step(dx, x, y, &dy); // perform integration + x += dx; // update step + } while (x <= x_max); // till upper limit of independent variable + /* end of integration */ + std::clock_t t2 = std::clock(); + + if (fp.is_open()) + fp.close(); + + return static_cast(t2 - t1) / CLOCKS_PER_SEC; +} + +/** @} */ + +/** + * Function to compute and save exact solution for comparison + * + * \param [in] X0 initial value of independent variable + * \param [in] X_MAX final value of independent variable + * \param [in] step_size independent variable step size + * \param [in] Y0 initial values of dependent variables + */ +void save_exact_solution(const double &X0, const double &X_MAX, + const double &step_size, + const std::valarray &Y0) { + double x = X0; + std::valarray y = Y0; + + std::ofstream fp("exact.csv", std::ostream::out); + if (!fp.is_open()) { + std::perror("Error! "); + return; + } + std::cout << "Finding exact solution\n"; + + std::clock_t t1 = std::clock(); + do { + fp << x << ","; + for (int i = 0; i < y.size() - 1; i++) { + fp << y[i] << ","; + } + fp << y[y.size() - 1] << "\n"; + + exact_solution(x, &y); + + x += step_size; + } while (x <= X_MAX); + + std::clock_t t2 = std::clock(); + double total_time = static_cast(t2 - t1) / CLOCKS_PER_SEC; + std::cout << "\tTime = " << total_time << " ms\n"; + + fp.close(); +} + +/** + * Main Function + */ +int main(int argc, char *argv[]) { + double X0 = 0.f; /* initial value of x0 */ + double X_MAX = 10.F; /* upper limit of integration */ + std::valarray Y0 = {1.f, 0.f}; /* initial value Y = y(x = x_0) */ + double step_size; + + if (argc == 1) { + std::cout << "\nEnter the step size: "; + std::cin >> step_size; + } else { + // use commandline argument as independent variable step size + step_size = std::atof(argv[1]); + } + + // get approximate solution + double total_time = semi_implicit_euler(step_size, X0, X_MAX, &Y0, true); + std::cout << "\tTime = " << total_time << " ms\n"; + + /* compute exact solution for comparion */ + save_exact_solution(X0, X_MAX, step_size, Y0); + + return 0; +} diff --git a/numerical_methods/ordinary_least_squares_regressor.cpp b/numerical_methods/ordinary_least_squares_regressor.cpp new file mode 100644 index 00000000000..43979d0ead6 --- /dev/null +++ b/numerical_methods/ordinary_least_squares_regressor.cpp @@ -0,0 +1,406 @@ +/** + * @file + * \brief Linear regression example using [Ordinary least + * squares](https://en.wikipedia.org/wiki/Ordinary_least_squares) + * + * \author [Krishna Vedala](https://github.com/kvedala) + * Program that gets the number of data samples and number of features per + * sample along with output per sample. It applies OLS regression to compute + * the regression output for additional test data samples. + */ +#include // for print formatting +#include +#include + +/** + * operator to print a matrix + */ +template +std::ostream &operator<<(std::ostream &out, + std::vector> const &v) { + const int width = 10; + const char separator = ' '; + + for (size_t row = 0; row < v.size(); row++) { + for (size_t col = 0; col < v[row].size(); col++) + out << std::left << std::setw(width) << std::setfill(separator) + << v[row][col]; + out << std::endl; + } + + return out; +} + +/** + * operator to print a vector + */ +template +std::ostream &operator<<(std::ostream &out, std::vector const &v) { + const int width = 15; + const char separator = ' '; + + for (size_t row = 0; row < v.size(); row++) + out << std::left << std::setw(width) << std::setfill(separator) + << v[row]; + + return out; +} + +/** + * function to check if given matrix is a square matrix + * \returns 1 if true, 0 if false + */ +template +inline bool is_square(std::vector> const &A) { + // Assuming A is square matrix + size_t N = A.size(); + for (size_t i = 0; i < N; i++) + if (A[i].size() != N) + return false; + return true; +} + +/** + * Matrix multiplication such that if A is size (mxn) and + * B is of size (pxq) then the multiplication is defined + * only when n = p and the resultant matrix is of size (mxq) + * + * \returns resultant matrix + **/ +template +std::vector> operator*(std::vector> const &A, + std::vector> const &B) { + // Number of rows in A + size_t N_A = A.size(); + // Number of columns in B + size_t N_B = B[0].size(); + + std::vector> result(N_A); + + if (A[0].size() != B.size()) { + std::cerr << "Number of columns in A != Number of rows in B (" + << A[0].size() << ", " << B.size() << ")" << std::endl; + return result; + } + + for (size_t row = 0; row < N_A; row++) { + std::vector v(N_B); + for (size_t col = 0; col < N_B; col++) { + v[col] = static_cast(0); + for (size_t j = 0; j < B.size(); j++) + v[col] += A[row][j] * B[j][col]; + } + result[row] = v; + } + + return result; +} + +/** + * multiplication of a matrix with a column vector + * \returns resultant vector + */ +template +std::vector operator*(std::vector> const &A, + std::vector const &B) { + // Number of rows in A + size_t N_A = A.size(); + + std::vector result(N_A); + + if (A[0].size() != B.size()) { + std::cerr << "Number of columns in A != Number of rows in B (" + << A[0].size() << ", " << B.size() << ")" << std::endl; + return result; + } + + for (size_t row = 0; row < N_A; row++) { + result[row] = static_cast(0); + for (size_t j = 0; j < B.size(); j++) result[row] += A[row][j] * B[j]; + } + + return result; +} + +/** + * pre-multiplication of a vector by a scalar + * \returns resultant vector + */ +template +std::vector operator*(float const scalar, std::vector const &A) { + // Number of rows in A + size_t N_A = A.size(); + + std::vector result(N_A); + + for (size_t row = 0; row < N_A; row++) { + result[row] += A[row] * static_cast(scalar); + } + + return result; +} + +/** + * post-multiplication of a vector by a scalar + * \returns resultant vector + */ +template +std::vector operator*(std::vector const &A, float const scalar) { + // Number of rows in A + size_t N_A = A.size(); + + std::vector result(N_A); + + for (size_t row = 0; row < N_A; row++) + result[row] = A[row] * static_cast(scalar); + + return result; +} + +/** + * division of a vector by a scalar + * \returns resultant vector + */ +template +std::vector operator/(std::vector const &A, float const scalar) { + return (1.f / scalar) * A; +} + +/** + * subtraction of two vectors of identical lengths + * \returns resultant vector + */ +template +std::vector operator-(std::vector const &A, std::vector const &B) { + // Number of rows in A + size_t N = A.size(); + + std::vector result(N); + + if (B.size() != N) { + std::cerr << "Vector dimensions shouldbe identical!" << std::endl; + return A; + } + + for (size_t row = 0; row < N; row++) result[row] = A[row] - B[row]; + + return result; +} + +/** + * addition of two vectors of identical lengths + * \returns resultant vector + */ +template +std::vector operator+(std::vector const &A, std::vector const &B) { + // Number of rows in A + size_t N = A.size(); + + std::vector result(N); + + if (B.size() != N) { + std::cerr << "Vector dimensions shouldbe identical!" << std::endl; + return A; + } + + for (size_t row = 0; row < N; row++) result[row] = A[row] + B[row]; + + return result; +} + +/** + * Get matrix inverse using Row-trasnformations. Given matrix must + * be a square and non-singular. + * \returns inverse matrix + **/ +template +std::vector> get_inverse( + std::vector> const &A) { + // Assuming A is square matrix + size_t N = A.size(); + + std::vector> inverse(N); + for (size_t row = 0; row < N; row++) { + // preallocatae a resultant identity matrix + inverse[row] = std::vector(N); + for (size_t col = 0; col < N; col++) + inverse[row][col] = (row == col) ? 1.f : 0.f; + } + + if (!is_square(A)) { + std::cerr << "A must be a square matrix!" << std::endl; + return inverse; + } + + // preallocatae a temporary matrix identical to A + std::vector> temp(N); + for (size_t row = 0; row < N; row++) { + std::vector v(N); + for (size_t col = 0; col < N; col++) + v[col] = static_cast(A[row][col]); + temp[row] = v; + } + + // start transformations + for (size_t row = 0; row < N; row++) { + for (size_t row2 = row; row2 < N && temp[row][row] == 0; row2++) { + // this to ensure diagonal elements are not 0 + temp[row] = temp[row] + temp[row2]; + inverse[row] = inverse[row] + inverse[row2]; + } + + for (size_t col2 = row; col2 < N && temp[row][row] == 0; col2++) { + // this to further ensure diagonal elements are not 0 + for (size_t row2 = 0; row2 < N; row2++) { + temp[row2][row] = temp[row2][row] + temp[row2][col2]; + inverse[row2][row] = inverse[row2][row] + inverse[row2][col2]; + } + } + + if (temp[row][row] == 0) { + // Probably a low-rank matrix and hence singular + std::cerr << "Low-rank matrix, no inverse!" << std::endl; + return inverse; + } + + // set diagonal to 1 + float divisor = static_cast(temp[row][row]); + temp[row] = temp[row] / divisor; + inverse[row] = inverse[row] / divisor; + // Row transformations + for (size_t row2 = 0; row2 < N; row2++) { + if (row2 == row) + continue; + float factor = temp[row2][row]; + temp[row2] = temp[row2] - factor * temp[row]; + inverse[row2] = inverse[row2] - factor * inverse[row]; + } + } + + return inverse; +} + +/** + * matrix transpose + * \returns resultant matrix + **/ +template +std::vector> get_transpose( + std::vector> const &A) { + std::vector> result(A[0].size()); + + for (size_t row = 0; row < A[0].size(); row++) { + std::vector v(A.size()); + for (size_t col = 0; col < A.size(); col++) v[col] = A[col][row]; + + result[row] = v; + } + return result; +} + +/** + * Perform Ordinary Least Squares curve fit. This operation is defined as + * \f[\beta = \left(X^TXX^T\right)Y\f] + * \param X feature matrix with rows representing sample vector of features + * \param Y known regression value for each sample + * \returns fitted regression model polynomial coefficients + */ +template +std::vector fit_OLS_regressor(std::vector> const &X, + std::vector const &Y) { + // NxF + std::vector> X2 = X; + for (size_t i = 0; i < X2.size(); i++) + // add Y-intercept -> Nx(F+1) + X2[i].push_back(1); + // (F+1)xN + std::vector> Xt = get_transpose(X2); + // (F+1)x(F+1) + std::vector> tmp = get_inverse(Xt * X2); + // (F+1)xN + std::vector> out = tmp * Xt; + // cout << endl + // << "Projection matrix: " << X2 * out << endl; + + // Fx1,1 -> (F+1)^th element is the independent constant + return out * Y; +} + +/** + * Given data and OLS model coeffficients, predict + * regression estimates. This operation is defined as + * \f[y_{\text{row}=i} = \sum_{j=\text{columns}}\beta_j\cdot X_{i,j}\f] + * + * \param X feature matrix with rows representing sample vector of features + * \param beta fitted regression model + * \return vector with regression values for each sample + **/ +template +std::vector predict_OLS_regressor(std::vector> const &X, + std::vector const &beta /**< */ +) { + std::vector result(X.size()); + + for (size_t rows = 0; rows < X.size(); rows++) { + // -> start with constant term + result[rows] = beta[X[0].size()]; + for (size_t cols = 0; cols < X[0].size(); cols++) + result[rows] += beta[cols] * X[rows][cols]; + } + // Nx1 + return result; +} + +/** + * main function + */ +int main() { + size_t N, F; + + std::cout << "Enter number of features: "; + // number of features = columns + std::cin >> F; + std::cout << "Enter number of samples: "; + // number of samples = rows + std::cin >> N; + + std::vector> data(N); + std::vector Y(N); + + std::cout + << "Enter training data. Per sample, provide features ad one output." + << std::endl; + + for (size_t rows = 0; rows < N; rows++) { + std::vector v(F); + std::cout << "Sample# " << rows + 1 << ": "; + for (size_t cols = 0; cols < F; cols++) + // get the F features + std::cin >> v[cols]; + data[rows] = v; + // get the corresponding output + std::cin >> Y[rows]; + } + + std::vector beta = fit_OLS_regressor(data, Y); + std::cout << std::endl << std::endl << "beta:" << beta << std::endl; + + size_t T; + std::cout << "Enter number of test samples: "; + // number of test sample inputs + std::cin >> T; + std::vector> data2(T); + // vector Y2(T); + + for (size_t rows = 0; rows < T; rows++) { + std::cout << "Sample# " << rows + 1 << ": "; + std::vector v(F); + for (size_t cols = 0; cols < F; cols++) std::cin >> v[cols]; + data2[rows] = v; + } + + std::vector out = predict_OLS_regressor(data2, beta); + for (size_t rows = 0; rows < T; rows++) std::cout << out[rows] << std::endl; + + return 0; +} diff --git a/numerical_methods/qr_decompose.h b/numerical_methods/qr_decompose.h new file mode 100644 index 00000000000..c9c3691449f --- /dev/null +++ b/numerical_methods/qr_decompose.h @@ -0,0 +1,210 @@ +/** + * @file + * \brief Library functions to compute [QR + * decomposition](https://en.wikipedia.org/wiki/QR_decomposition) of a given + * matrix. + * \author [Krishna Vedala](https://github.com/kvedala) + */ + +#ifndef NUMERICAL_METHODS_QR_DECOMPOSE_H_ +#define NUMERICAL_METHODS_QR_DECOMPOSE_H_ + +#include +#include +#include +#include +#include +#include +#include +#ifdef _OPENMP +#include +#endif + +/** \namespace qr_algorithm + * \brief Functions to compute [QR + * decomposition](https://en.wikipedia.org/wiki/QR_decomposition) of any + * rectangular matrix + */ +namespace qr_algorithm { +/** + * operator to print a matrix + */ +template +std::ostream &operator<<(std::ostream &out, + std::valarray> const &v) { + const int width = 12; + const char separator = ' '; + + out.precision(4); + for (size_t row = 0; row < v.size(); row++) { + for (size_t col = 0; col < v[row].size(); col++) + out << std::right << std::setw(width) << std::setfill(separator) + << v[row][col]; + out << std::endl; + } + + return out; +} + +/** + * operator to print a vector + */ +template +std::ostream &operator<<(std::ostream &out, std::valarray const &v) { + const int width = 10; + const char separator = ' '; + + out.precision(4); + for (size_t row = 0; row < v.size(); row++) { + out << std::right << std::setw(width) << std::setfill(separator) + << v[row]; + } + + return out; +} + +/** + * Compute dot product of two vectors of equal lengths + * + * If \f$\vec{a}=\left[a_0,a_1,a_2,...,a_L\right]\f$ and + * \f$\vec{b}=\left[b_0,b_1,b_1,...,b_L\right]\f$ then + * \f$\vec{a}\cdot\vec{b}=\displaystyle\sum_{i=0}^L a_i\times b_i\f$ + * + * \returns \f$\vec{a}\cdot\vec{b}\f$ + */ +template +inline double vector_dot(const std::valarray &a, const std::valarray &b) { + return (a * b).sum(); + // could also use following + // return std::inner_product(std::begin(a), std::end(a), std::begin(b), + // 0.f); +} + +/** + * Compute magnitude of vector. + * + * If \f$\vec{a}=\left[a_0,a_1,a_2,...,a_L\right]\f$ then + * \f$\left|\vec{a}\right|=\sqrt{\displaystyle\sum_{i=0}^L a_i^2}\f$ + * + * \returns \f$\left|\vec{a}\right|\f$ + */ +template +inline double vector_mag(const std::valarray &a) { + double dot = vector_dot(a, a); + return std::sqrt(dot); +} + +/** + * Compute projection of vector \f$\vec{a}\f$ on \f$\vec{b}\f$ defined as + * \f[\text{proj}_\vec{b}\vec{a}=\frac{\vec{a}\cdot\vec{b}}{\left|\vec{b}\right|^2}\vec{b}\f] + * + * \returns NULL if error, otherwise pointer to output + */ +template +std::valarray vector_proj(const std::valarray &a, + const std::valarray &b) { + double num = vector_dot(a, b); + double deno = vector_dot(b, b); + + /*! check for division by zero using machine epsilon */ + if (deno <= std::numeric_limits::epsilon()) { + std::cerr << "[" << __func__ << "] Possible division by zero\n"; + return a; // return vector a back + } + + double scalar = num / deno; + + return b * scalar; +} + +/** + * Decompose matrix \f$A\f$ using [Gram-Schmidt + *process](https://en.wikipedia.org/wiki/QR_decomposition). + * + * \f{eqnarray*}{ + * \text{given that}\quad A &=& + *\left[\mathbf{a}_1,\mathbf{a}_2,\ldots,\mathbf{a}_{N-1},\right]\\ + * \text{where}\quad\mathbf{a}_i &=& + * \left[a_{0i},a_{1i},a_{2i},\ldots,a_{(M-1)i}\right]^T\quad\ldots\mbox{(column + * vectors)}\\ + * \text{then}\quad\mathbf{u}_i &=& \mathbf{a}_i + *-\sum_{j=0}^{i-1}\text{proj}_{\mathbf{u}_j}\mathbf{a}_i\\ + * \mathbf{e}_i &=&\frac{\mathbf{u}_i}{\left|\mathbf{u}_i\right|}\\ + * Q &=& \begin{bmatrix}\mathbf{e}_0 & \mathbf{e}_1 & \mathbf{e}_2 & \dots & + * \mathbf{e}_{N-1}\end{bmatrix}\\ + * R &=& \begin{bmatrix}\langle\mathbf{e}_0\,,\mathbf{a}_0\rangle & + * \langle\mathbf{e}_1\,,\mathbf{a}_1\rangle & + * \langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots \\ + * 0 & \langle\mathbf{e}_1\,,\mathbf{a}_1\rangle & + * \langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots\\ + * 0 & 0 & \langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & + * \dots\\ \vdots & \vdots & \vdots & \ddots + * \end{bmatrix}\\ + * \f} + */ +template +void qr_decompose( + const std::valarray> &A, /**< input matrix to decompose */ + std::valarray> *Q, /**< output decomposed matrix */ + std::valarray> *R /**< output decomposed matrix */ +) { + std::size_t ROWS = A.size(); // number of rows of A + std::size_t COLUMNS = A[0].size(); // number of columns of A + std::valarray col_vector(ROWS); + std::valarray col_vector2(ROWS); + std::valarray tmp_vector(ROWS); + + for (int i = 0; i < COLUMNS; i++) { + /* for each column => R is a square matrix of NxN */ + int j; + R[0][i] = 0.; /* make R upper triangular */ + + /* get corresponding Q vector */ +#ifdef _OPENMP +// parallelize on threads +#pragma omp for +#endif + for (j = 0; j < ROWS; j++) { + tmp_vector[j] = A[j][i]; /* accumulator for uk */ + col_vector[j] = A[j][i]; + } + for (j = 0; j < i; j++) { + for (int k = 0; k < ROWS; k++) { + col_vector2[k] = Q[0][k][j]; + } + col_vector2 = vector_proj(col_vector, col_vector2); + tmp_vector -= col_vector2; + } + + double mag = vector_mag(tmp_vector); + +#ifdef _OPENMP +// parallelize on threads +#pragma omp for +#endif + for (j = 0; j < ROWS; j++) Q[0][j][i] = tmp_vector[j] / mag; + + /* compute upper triangular values of R */ +#ifdef _OPENMP +// parallelize on threads +#pragma omp for +#endif + for (int kk = 0; kk < ROWS; kk++) { + col_vector[kk] = Q[0][kk][i]; + } + +#ifdef _OPENMP +// parallelize on threads +#pragma omp for +#endif + for (int k = i; k < COLUMNS; k++) { + for (int kk = 0; kk < ROWS; kk++) { + col_vector2[kk] = A[kk][k]; + } + R[0][i][k] = (col_vector * col_vector2).sum(); + } + } +} +} // namespace qr_algorithm + +#endif // NUMERICAL_METHODS_QR_DECOMPOSE_H_ diff --git a/numerical_methods/qr_decomposition.cpp b/numerical_methods/qr_decomposition.cpp new file mode 100644 index 00000000000..237a5c94642 --- /dev/null +++ b/numerical_methods/qr_decomposition.cpp @@ -0,0 +1,58 @@ +/** + * @file + * \brief Program to compute the [QR + * decomposition](https://en.wikipedia.org/wiki/QR_decomposition) of a given + * matrix. + * \author [Krishna Vedala](https://github.com/kvedala) + */ + +#include +#include +#include +#include +#include + +#include "./qr_decompose.h" + +using qr_algorithm::qr_decompose; +using qr_algorithm::operator<<; + +/** + * main function + */ +int main(void) { + unsigned int ROWS, COLUMNS; + + std::cout << "Enter the number of rows and columns: "; + std::cin >> ROWS >> COLUMNS; + + std::cout << "Enter matrix elements row-wise:\n"; + + std::valarray> A(ROWS); + std::valarray> Q(ROWS); + std::valarray> R(COLUMNS); + for (int i = 0; i < std::max(ROWS, COLUMNS); i++) { + if (i < ROWS) { + A[i] = std::valarray(COLUMNS); + Q[i] = std::valarray(COLUMNS); + } + if (i < COLUMNS) { + R[i] = std::valarray(COLUMNS); + } + } + + for (int i = 0; i < ROWS; i++) + for (int j = 0; j < COLUMNS; j++) std::cin >> A[i][j]; + + std::cout << A << "\n"; + + clock_t t1 = clock(); + qr_decompose(A, &Q, &R); + double dtime = static_cast(clock() - t1) / CLOCKS_PER_SEC; + + std::cout << Q << "\n"; + std::cout << R << "\n"; + std::cout << "Time taken to compute: " << dtime << " sec\n "; + + return 0; +} diff --git a/numerical_methods/qr_eigen_values.cpp b/numerical_methods/qr_eigen_values.cpp new file mode 100644 index 00000000000..581e02e4ea2 --- /dev/null +++ b/numerical_methods/qr_eigen_values.cpp @@ -0,0 +1,284 @@ +/** + * @file + * \brief Compute real eigen values and eigen vectors of a symmetric matrix + * using [QR decomposition](https://en.wikipedia.org/wiki/QR_decomposition) + * method. + * \author [Krishna Vedala](https://github.com/kvedala) + */ +#include +#include +#include +#include +#include +#ifdef _OPENMP +#include +#endif + +#include "./qr_decompose.h" +using qr_algorithm::operator<<; + +#define LIMS 9 /**< limit of range of matrix values */ + +/** + * create a symmetric square matrix of given size with random elements. A + * symmetric square matrix will *always* have real eigen values. + * + * \param[out] A matrix to create (must be pre-allocated in memory) + */ +void create_matrix(std::valarray> *A) { + int i, j, tmp, lim2 = LIMS >> 1; + int N = A->size(); + +#ifdef _OPENMP +#pragma omp for +#endif + for (i = 0; i < N; i++) { + A[0][i][i] = (std::rand() % LIMS) - lim2; + for (j = i + 1; j < N; j++) { + tmp = (std::rand() % LIMS) - lim2; + A[0][i][j] = tmp; // summetrically distribute random values + A[0][j][i] = tmp; + } + } +} + +/** + * Perform multiplication of two matrices. + * * R2 must be equal to C1 + * * Resultant matrix size should be R1xC2 + * \param[in] A first matrix to multiply + * \param[in] B second matrix to multiply + * \param[out] OUT output matrix (must be pre-allocated) + * \returns pointer to resultant matrix + */ +void mat_mul(const std::valarray> &A, + const std::valarray> &B, + std::valarray> *OUT) { + int R1 = A.size(); + int C1 = A[0].size(); + int R2 = B.size(); + int C2 = B[0].size(); + if (C1 != R2) { + perror("Matrix dimensions mismatch!"); + return; + } + + for (int i = 0; i < R1; i++) { + for (int j = 0; j < C2; j++) { + OUT[0][i][j] = 0.f; + for (int k = 0; k < C1; k++) { + OUT[0][i][j] += A[i][k] * B[k][j]; + } + } + } +} + +namespace qr_algorithm { +/** Compute eigen values using iterative shifted QR decomposition algorithm as + * follows: + * 1. Use last diagonal element of A as eigen value approximation \f$c\f$ + * 2. Shift diagonals of matrix \f$A' = A - cI\f$ + * 3. Decompose matrix \f$A'=QR\f$ + * 4. Compute next approximation \f$A'_1 = RQ \f$ + * 5. Shift diagonals back \f$A_1 = A'_1 + cI\f$ + * 6. Termination condition check: last element below diagonal is almost 0 + * 1. If not 0, go back to step 1 with the new approximation \f$A_1\f$ + * 2. If 0, continue to step 7 + * 7. Save last known \f$c\f$ as the eigen value. + * 8. Are all eigen values found? + * 1. If not, remove last row and column of \f$A_1\f$ and go back to step 1. + * 2. If yes, stop. + * + * \note The matrix \f$A\f$ gets modified + * + * \param[in,out] A matrix to compute eigen values for + * \param[in] print_intermediates (optional) whether to print intermediate A, Q + * and R matrices (default = `false`) + */ +std::valarray eigen_values(std::valarray> *A, + bool print_intermediates = false) { + int rows = A->size(); + int columns = rows; + int counter = 0, num_eigs = rows - 1; + double last_eig = 0; + + std::valarray> Q(rows); + std::valarray> R(columns); + + /* number of eigen values = matrix size */ + std::valarray eigen_vals(rows); + for (int i = 0; i < rows; i++) { + Q[i] = std::valarray(columns); + R[i] = std::valarray(columns); + } + + /* continue till all eigen values are found */ + while (num_eigs > 0) { + /* iterate with QR decomposition */ + while (std::abs(A[0][num_eigs][num_eigs - 1]) > + std::numeric_limits::epsilon()) { + // initial approximation = last diagonal element + last_eig = A[0][num_eigs][num_eigs]; + for (int i = 0; i < rows; i++) { + A[0][i][i] -= last_eig; /* A - cI */ + } + + qr_decompose(*A, &Q, &R); + + if (print_intermediates) { + std::cout << *A << "\n"; + std::cout << Q << "\n"; + std::cout << R << "\n"; + printf("-------------------- %d ---------------------\n", + ++counter); + } + + // new approximation A' = R * Q + mat_mul(R, Q, A); + + for (int i = 0; i < rows; i++) { + A[0][i][i] += last_eig; /* A + cI */ + } + } + + /* store the converged eigen value */ + eigen_vals[num_eigs] = last_eig; + // A[0][num_eigs][num_eigs]; + if (print_intermediates) { + std::cout << "========================\n"; + std::cout << "Eigen value: " << last_eig << ",\n"; + std::cout << "========================\n"; + } + + num_eigs--; + rows--; + columns--; + } + eigen_vals[0] = A[0][0][0]; + + if (print_intermediates) { + std::cout << Q << "\n"; + std::cout << R << "\n"; + } + + return eigen_vals; +} + +} // namespace qr_algorithm + +/** + * test function to compute eigen values of a 2x2 matrix + * \f[\begin{bmatrix} + * 5 & 7\\ + * 7 & 11 + * \end{bmatrix}\f] + * which are approximately, {15.56158, 0.384227} + */ +void test1() { + std::valarray> X = {{5, 7}, {7, 11}}; + double y[] = {15.56158, 0.384227}; // corresponding y-values + + std::cout << "------- Test 1 -------" << std::endl; + std::valarray eig_vals = qr_algorithm::eigen_values(&X); + + for (int i = 0; i < 2; i++) { + std::cout << i + 1 << "/2 Checking for " << y[i] << " --> "; + bool result = false; + for (int j = 0; j < 2 && !result; j++) { + if (std::abs(y[i] - eig_vals[j]) < 0.1) { + result = true; + std::cout << "(" << eig_vals[j] << ") "; + } + } + assert(result); // ensure that i^th expected eigen value was computed + std::cout << "found\n"; + } + std::cout << "Test 1 Passed\n\n"; +} + +/** + * test function to compute eigen values of a 2x2 matrix + * \f[\begin{bmatrix} + * -4& 4& 2& 0& -3\\ + * 4& -4& 4& -3& -1\\ + * 2& 4& 4& 3& -3\\ + * 0& -3& 3& -1&-1\\ + * -3& -1& -3& -3& 0 + * \end{bmatrix}\f] + * which are approximately, {9.27648, -9.26948, 2.0181, -1.03516, -5.98994} + */ +void test2() { + std::valarray> X = {{-4, 4, 2, 0, -3}, + {4, -4, 4, -3, -1}, + {2, 4, 4, 3, -3}, + {0, -3, 3, -1, -3}, + {-3, -1, -3, -3, 0}}; + double y[] = {9.27648, -9.26948, 2.0181, -1.03516, + -5.98994}; // corresponding y-values + + std::cout << "------- Test 2 -------" << std::endl; + std::valarray eig_vals = qr_algorithm::eigen_values(&X); + + std::cout << X << "\n" + << "Eigen values: " << eig_vals << "\n"; + + for (int i = 0; i < 5; i++) { + std::cout << i + 1 << "/5 Checking for " << y[i] << " --> "; + bool result = false; + for (int j = 0; j < 5 && !result; j++) { + if (std::abs(y[i] - eig_vals[j]) < 0.1) { + result = true; + std::cout << "(" << eig_vals[j] << ") "; + } + } + assert(result); // ensure that i^th expected eigen value was computed + std::cout << "found\n"; + } + std::cout << "Test 2 Passed\n\n"; +} + +/** + * main function + */ +int main(int argc, char **argv) { + int mat_size = 5; + if (argc == 2) { + mat_size = atoi(argv[1]); + } else { // if invalid input argument is given run tests + test1(); + test2(); + std::cout << "Usage: ./qr_eigen_values [mat_size]\n"; + return 0; + } + + if (mat_size < 2) { + fprintf(stderr, "Matrix size should be > 2\n"); + return -1; + } + + // initialize random number generator + std::srand(std::time(nullptr)); + + int i, rows = mat_size, columns = mat_size; + + std::valarray> A(rows); + + for (int i = 0; i < rows; i++) { + A[i] = std::valarray(columns); + } + + /* create a random matrix */ + create_matrix(&A); + + std::cout << A << "\n"; + + clock_t t1 = clock(); + std::valarray eigen_vals = qr_algorithm::eigen_values(&A); + double dtime = static_cast(clock() - t1) / CLOCKS_PER_SEC; + + std::cout << "Eigen vals: "; + for (i = 0; i < mat_size; i++) std::cout << eigen_vals[i] << "\t"; + std::cout << "\nTime taken to compute: " << dtime << " sec\n"; + + return 0; +} diff --git a/numerical_methods/successive_approximation.cpp b/numerical_methods/successive_approximation.cpp new file mode 100644 index 00000000000..351382f2418 --- /dev/null +++ b/numerical_methods/successive_approximation.cpp @@ -0,0 +1,40 @@ +/** + * \file + * \brief Method of successive approximations using [fixed-point + * iteration](https://en.wikipedia.org/wiki/Fixed-point_iteration) method + */ +#include +#include + +/** equation 1 + * \f[f(y) = 3y - \cos y -2\f] + */ +static float eq(float y) { return (3 * y) - cos(y) - 2; } + +/** equation 2 + * \f[f(y) = \frac{\cos y+2}{2}\f] + */ +static float eqd(float y) { return 0.5 * (cos(y) + 2); } + +/** Main function */ +int main() { + float y, x1, x2, x3, sum, s, a, f1, f2, gd; + int i, n; + + for (i = 0; i < 10; i++) { + sum = eq(y); + std::cout << "value of equation at " << i << " " << sum << "\n"; + y++; + } + std::cout << "enter the x1->"; + std::cin >> x1; + std::cout << "enter the no iteration to perform->\n"; + std::cin >> n; + + for (i = 0; i <= n; i++) { + x2 = eqd(x1); + std::cout << "\nenter the x2->" << x2; + x1 = x2; + } + return 0; +} diff --git a/operations_on_datastructures/Array Left Rotation.cpp b/operations_on_datastructures/Array Left Rotation.cpp deleted file mode 100644 index 9eb5d4e5002..00000000000 --- a/operations_on_datastructures/Array Left Rotation.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -using namespace std; -int main() -{ - int n, k; - cout << "Enter size of array=\t"; - cin >> n; - cout << "Enter Number of indeces u want to rotate the array to left=\t"; - cin >> k; - int a[n]; - cout << "Enter elements of array=\t"; - for (int i = 0; i < n; i++) - { - cin >> a[i]; - } - int temp = 0; - for (int i = 0; i < k; i++) - { - temp = a[0]; - for (int j = 0; j < n; j++) - { - if (j == n - 1) - { - a[n - 1] = temp; - } - else - { - a[j] = a[j + 1]; - } - } - } - cout << "Your rotated array is=\t"; - for (int j = 0; j < n; j++) - { - cout << a[j] << " "; - } - getchar(); - return 0; -} diff --git a/operations_on_datastructures/Circular Linked List.cpp b/operations_on_datastructures/Circular Linked List.cpp deleted file mode 100644 index d360f6cd7f3..00000000000 --- a/operations_on_datastructures/Circular Linked List.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include -using namespace std; - -struct node -{ - int val; - node *next; -}; - -node *start; - -void insert(int x) -{ - node *t = start; - - if (start != NULL) - { - while (t->next != start) - { - t = t->next; - } - node *n = new node; - t->next = n; - n->val = x; - n->next = start; - } - else - { - node *n = new node; - n->val = x; - start = n; - n->next = start; - } -} - -void remove(int x) -{ - node *t = start; - node *p; - while (t->val != x) - { - p = t; - t = t->next; - } - p->next = t->next; - delete t; -} - -void search(int x) -{ - node *t = start; - int found = 0; - while (t->next != start) - { - if (t->val == x) - { - cout << "\nFound"; - found = 1; - break; - } - t = t->next; - } - if (found == 0) - { - cout << "\nNot Found"; - } -} - -void show() -{ - node *t = start; - do - { - cout << t->val << "\t"; - t = t->next; - } while (t != start); -} - -int main() -{ - int choice, x; - do - { - cout << "\n1. Insert"; - cout << "\n2. Delete"; - cout << "\n3. Search"; - cout << "\n4. Print"; - cout << "\n\nEnter you choice : "; - cin >> choice; - switch (choice) - { - case 1: - cout << "\nEnter the element to be inserted : "; - cin >> x; - insert(x); - break; - case 2: - cout << "\nEnter the element to be removed : "; - cin >> x; - remove(x); - break; - case 3: - cout << "\nEnter the element to be searched : "; - cin >> x; - search(x); - break; - case 4: - show(); - break; - } - } while (choice != 0); - - return 0; -} diff --git a/operations_on_datastructures/Circular Queue Using Array.cpp b/operations_on_datastructures/Circular Queue Using Array.cpp deleted file mode 100644 index 36d7e22c33d..00000000000 --- a/operations_on_datastructures/Circular Queue Using Array.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -using namespace std; - -int queue[10]; -int front = 0; -int rear = 0; -int count = 0; - -void Enque(int x) -{ - if (count == 10) - { - cout << "\nOverflow"; - } - else - { - queue[rear] = x; - rear = (rear + 1) % 10; - count++; - } -} - -void Deque() -{ - if (front == rear) - { - cout << "\nUnderflow"; - } - - else - { - cout << "\n" - << queue[front] << " deleted"; - front = (front + 1) % 10; - count--; - } -} - -void show() -{ - for (int i = 0; i < count; i++) - { - cout << queue[(i + front) % 10] << "\t"; - } -} - -int main() -{ - int ch, x; - do - { - cout << "\n1. Enque"; - cout << "\n2. Deque"; - cout << "\n3. Print"; - cout << "\nEnter Your Choice : "; - cin >> ch; - if (ch == 1) - { - cout << "\nInsert : "; - cin >> x; - Enque(x); - } - else if (ch == 2) - { - Deque(); - } - else if (ch == 3) - { - show(); - } - } while (ch != 0); - - return 0; -} diff --git a/operations_on_datastructures/Intersection_of_2_arrays.cpp b/operations_on_datastructures/Intersection_of_2_arrays.cpp deleted file mode 100644 index 05652811f43..00000000000 --- a/operations_on_datastructures/Intersection_of_2_arrays.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -int main() -{ - int i, j, m, n; - cout << "Enter size of array 1:"; - cin >> m; - cout << "Enter size of array 2:"; - cin >> n; - int a[m]; - int b[n]; - cout << "Enter elements of array 1:"; - for (i = 0; i < m; i++) - cin >> a[i]; - for (i = 0; i < n; i++) - cin >> b[i]; - i = 0; - j = 0; - while ((i < m) && (j < n)) - { - if (a[i] < b[j]) - i++; - else if (a[i] > b[j]) - j++; - else - { - cout << a[i++] << " "; - j++; - } - } - return 0; -} diff --git a/operations_on_datastructures/Reverse a Linked List using Recusion.cpp b/operations_on_datastructures/Reverse a Linked List using Recusion.cpp deleted file mode 100644 index 0908080cc81..00000000000 --- a/operations_on_datastructures/Reverse a Linked List using Recusion.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include -using namespace std; - -struct node -{ - int val; - node *next; -}; - -node *start; - -void insert(int x) -{ - node *t = start; - if (start != NULL) - { - while (t->next != NULL) - { - t = t->next; - } - node *n = new node; - t->next = n; - n->val = x; - n->next = NULL; - } - else - { - node *n = new node; - n->val = x; - n->next = NULL; - start = n; - } -} - -void reverse(node *p, node *q) -{ - if (q->next == NULL) - { - q->next = p; - p->next = NULL; - start = q; - return; - } - else - { - reverse(q, q->next); - q->next = p; - p->next = NULL; - } -} - -void show() -{ - node *t = start; - while (t != NULL) - { - cout << t->val << "\t"; - t = t->next; - } -} - -int main() -{ - insert(1); - insert(2); - insert(3); - insert(4); - insert(5); - insert(6); - - reverse(start, start->next); - - show(); - - return 0; -} diff --git a/operations_on_datastructures/Union_of_2_arrays.cpp b/operations_on_datastructures/Union_of_2_arrays.cpp deleted file mode 100644 index aaaeb83781b..00000000000 --- a/operations_on_datastructures/Union_of_2_arrays.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -int main() -{ - int m, n, i = 0, j = 0; - cout << "Enter size of both arrays:"; - cin >> m >> n; - int a[m]; - int b[n]; - cout << "Enter elements of array 1:"; - for (i = 0; i < m; i++) - cin >> a[i]; - cout << "Enter elements of array 2:"; - for (i = 0; i < n; i++) - cin >> b[i]; - i = 0; - j = 0; - while ((i < m) && (j < n)) - { - if (a[i] < b[j]) - cout << a[i++] << " "; - else if (a[i] > b[j]) - cout << b[j++] << " "; - else - { - cout << a[i++]; - j++; - } - } - while (i < m) - cout << a[i++] << " "; - while (j < n) - cout << b[j++] << " "; - return 0; -} diff --git a/operations_on_datastructures/array_left_rotation.cpp b/operations_on_datastructures/array_left_rotation.cpp new file mode 100644 index 00000000000..7b8f7f279ad --- /dev/null +++ b/operations_on_datastructures/array_left_rotation.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; +int main() { + int n, k; + cout << "Enter size of array=\t"; + cin >> n; + cout << "Enter Number of indeces u want to rotate the array to left=\t"; + cin >> k; + int a[n]; + cout << "Enter elements of array=\t"; + for (int i = 0; i < n; i++) { + cin >> a[i]; + } + int temp = 0; + for (int i = 0; i < k; i++) { + temp = a[0]; + for (int j = 0; j < n; j++) { + if (j == n - 1) { + a[n - 1] = temp; + } else { + a[j] = a[j + 1]; + } + } + } + cout << "Your rotated array is=\t"; + for (int j = 0; j < n; j++) { + cout << a[j] << " "; + } + getchar(); + return 0; +} diff --git a/operations_on_datastructures/Array Right Rotation.cpp b/operations_on_datastructures/array_right_rotation.cpp similarity index 62% rename from operations_on_datastructures/Array Right Rotation.cpp rename to operations_on_datastructures/array_right_rotation.cpp index 81875766c14..8b01a2003dd 100644 --- a/operations_on_datastructures/Array Right Rotation.cpp +++ b/operations_on_datastructures/array_right_rotation.cpp @@ -1,7 +1,6 @@ #include using namespace std; -int main() -{ +int main() { int n, k; cout << "Enter size of array=\t"; cin >> n; @@ -9,27 +8,20 @@ int main() cin >> k; int a[n]; cout << "Enter elements of array=\t"; - for (int i = 0; i < n; i++) - cin >> a[i]; + for (int i = 0; i < n; i++) cin >> a[i]; int temp = 0; - for (int i = 0; i < k; i++) - { + for (int i = 0; i < k; i++) { temp = a[n - 1]; - for (int j = n - 1; j >= 0; j--) - { - if (j == 0) - { + for (int j = n - 1; j >= 0; j--) { + if (j == 0) { a[j] = temp; - } - else - { + } else { a[j] = a[j - 1]; } } } cout << "Your rotated array is=\t"; - for (int i = 0; i < n; i++) - { + for (int i = 0; i < n; i++) { cout << a[i] << " "; } } diff --git a/operations_on_datastructures/circular_linked_list.cpp b/operations_on_datastructures/circular_linked_list.cpp new file mode 100644 index 00000000000..1119bb5e7f3 --- /dev/null +++ b/operations_on_datastructures/circular_linked_list.cpp @@ -0,0 +1,97 @@ +#include +using namespace std; + +struct node { + int val; + node *next; +}; + +node *start; + +void insert(int x) { + node *t = start; + + if (start != NULL) { + while (t->next != start) { + t = t->next; + } + node *n = new node; + t->next = n; + n->val = x; + n->next = start; + } else { + node *n = new node; + n->val = x; + start = n; + n->next = start; + } +} + +void remove(int x) { + node *t = start; + node *p; + while (t->val != x) { + p = t; + t = t->next; + } + p->next = t->next; + delete t; +} + +void search(int x) { + node *t = start; + int found = 0; + while (t->next != start) { + if (t->val == x) { + cout << "\nFound"; + found = 1; + break; + } + t = t->next; + } + if (found == 0) { + cout << "\nNot Found"; + } +} + +void show() { + node *t = start; + do { + cout << t->val << "\t"; + t = t->next; + } while (t != start); +} + +int main() { + int choice, x; + do { + cout << "\n1. Insert"; + cout << "\n2. Delete"; + cout << "\n3. Search"; + cout << "\n4. Print"; + cout << "\n\nEnter you choice : "; + cin >> choice; + switch (choice) { + case 1: + cout << "\nEnter the element to be inserted : "; + cin >> x; + insert(x); + break; + case 2: + cout << "\nEnter the element to be removed : "; + cin >> x; + remove(x); + break; + case 3: + cout << "\nEnter the element to be searched : "; + cin >> x; + search(x); + break; + case 4: + show(); + break; + } + } while (choice != 0); + + return 0; +} diff --git a/operations_on_datastructures/circular_queue_using_array.cpp b/operations_on_datastructures/circular_queue_using_array.cpp new file mode 100644 index 00000000000..e0e049611da --- /dev/null +++ b/operations_on_datastructures/circular_queue_using_array.cpp @@ -0,0 +1,57 @@ +#include +using namespace std; + +int queue[10]; +int front = 0; +int rear = 0; +int count = 0; + +void Enque(int x) { + if (count == 10) { + cout << "\nOverflow"; + } else { + queue[rear] = x; + rear = (rear + 1) % 10; + count++; + } +} + +void Deque() { + if (front == rear) { + cout << "\nUnderflow"; + } + + else { + cout << "\n" << queue[front] << " deleted"; + front = (front + 1) % 10; + count--; + } +} + +void show() { + for (int i = 0; i < count; i++) { + cout << queue[(i + front) % 10] << "\t"; + } +} + +int main() { + int ch, x; + do { + cout << "\n1. Enque"; + cout << "\n2. Deque"; + cout << "\n3. Print"; + cout << "\nEnter Your Choice : "; + cin >> ch; + if (ch == 1) { + cout << "\nInsert : "; + cin >> x; + Enque(x); + } else if (ch == 2) { + Deque(); + } else if (ch == 3) { + show(); + } + } while (ch != 0); + + return 0; +} diff --git a/operations_on_datastructures/intersection_of_2_arrays.cpp b/operations_on_datastructures/intersection_of_2_arrays.cpp new file mode 100644 index 00000000000..8a3b27edfef --- /dev/null +++ b/operations_on_datastructures/intersection_of_2_arrays.cpp @@ -0,0 +1,26 @@ +#include +int main() { + int i, j, m, n; + cout << "Enter size of array 1:"; + cin >> m; + cout << "Enter size of array 2:"; + cin >> n; + int a[m]; + int b[n]; + cout << "Enter elements of array 1:"; + for (i = 0; i < m; i++) cin >> a[i]; + for (i = 0; i < n; i++) cin >> b[i]; + i = 0; + j = 0; + while ((i < m) && (j < n)) { + if (a[i] < b[j]) + i++; + else if (a[i] > b[j]) + j++; + else { + cout << a[i++] << " "; + j++; + } + } + return 0; +} diff --git a/operations_on_datastructures/reverse_a_linked_list_using_recusion.cpp b/operations_on_datastructures/reverse_a_linked_list_using_recusion.cpp new file mode 100644 index 00000000000..b9540d951a5 --- /dev/null +++ b/operations_on_datastructures/reverse_a_linked_list_using_recusion.cpp @@ -0,0 +1,63 @@ +#include +using namespace std; + +struct node { + int val; + node *next; +}; + +node *start; + +void insert(int x) { + node *t = start; + if (start != NULL) { + while (t->next != NULL) { + t = t->next; + } + node *n = new node; + t->next = n; + n->val = x; + n->next = NULL; + } else { + node *n = new node; + n->val = x; + n->next = NULL; + start = n; + } +} + +void reverse(node *p, node *q) { + if (q->next == NULL) { + q->next = p; + p->next = NULL; + start = q; + return; + } else { + reverse(q, q->next); + q->next = p; + p->next = NULL; + } +} + +void show() { + node *t = start; + while (t != NULL) { + cout << t->val << "\t"; + t = t->next; + } +} + +int main() { + insert(1); + insert(2); + insert(3); + insert(4); + insert(5); + insert(6); + + reverse(start, start->next); + + show(); + + return 0; +} diff --git a/operations_on_datastructures/selectionSortLinkedList.cpp b/operations_on_datastructures/selectionSortLinkedList.cpp deleted file mode 100644 index 52363ceffe7..00000000000 --- a/operations_on_datastructures/selectionSortLinkedList.cpp +++ /dev/null @@ -1,159 +0,0 @@ -#include -using namespace std; - -//node defined -class node -{ -public: - int data; - node *link; - node(int d) - { - data = d; - link = NULL; - } -}; - -//printing the linked list -void print(node *head) -{ - node *current = head; - while (current != NULL) - { - cout << current->data << " "; - current = current->link; - } - cout << endl; -} - -//creating the linked list with 'n' nodes -node *createlist(int n) -{ - node *head = NULL; - node *t = NULL; - for (int i = 0; i < n; i++) - { - node *temp = NULL; - int num; - cin >> num; - temp = new node(num); - if (head == NULL) - { - head = temp; - t = temp; - continue; - } - if (t->link == NULL) - t->link = temp; - t = temp; - } - return head; -} - -//performing selection sort on the linked list in an iterative manner -void my_selection_sort_linked_list(node *&head) -{ - node *min = head; //throughout the algorithm 'min' is used to denote the node with min value out of all the nodes left for scanning - //while scanning if we find a node 'X' with value lesser than min, - //then we update the pointers in such a way that 'X' becomes the predecessor of 'min' - node *current = min->link; // 'current' refers to the current node we are scanning - node *previous = min; //'previous' refers to the node that is previous to the current node - node *temp = NULL; // 'temp' in this algo is used to point to the last node of the sorted part of the linked list. - //eg. If at any time instance the state of the linked list is suppose 1->2->5->3->8->NULL - //then, we see that "1->2" is the sorted part of the LL, and therefore temp will be pointing to the last node of the sorted part,i.e,'2' - //We keep on arranging the Linked list in such a way that after each iteration the node with 'min' value is placed at its correct position. - //Eg. Let suppose initially we have 5->4->1->3->2->NULL - //After 1st iteration : 1->4->5->3->2->NULL and so on - - while (min->link != NULL) //so that all the nodes are scanned or until there exists a node - { - //pick the first node from the unsorted part and assume that it is the minimum and then start scanning from the next node - - while (current != NULL) //suppose you choose the min node to be X, then scan starts from the (X+1)th node until its NULL. current = (X+1)th node and min = X - { - if (current->data < min->data) //if the current node is smaller than the presumed node 'min' - { - if (temp == NULL) //temp stays null for the first iteration, therefore it symbolizes that we are scanning for the first time - { - if (previous == min) //if the 'previous' is pointing to the 'min' node - { - //Update the pointers - head = current; //update the head pointer with the current node - min->link = current->link; - current->link = previous; - min = current; - current = previous->link; - } - else //if the 'previous' is not pointing to the 'min' node - { - //Update the pointers - head = current; //update the head pointer with the current node - previous->link = current->link; - current->link = min; - min = current; - current = previous->link; - } - } - else //if 'temp' is not NULL, i.e., its not the 1st iteration - { - temp->link = current; - previous->link = current->link; - current->link = min; - min = current; - current = previous->link; - } - } - else //if the current node is greater than min, just move the previous and the current pointer a step further - { - previous = previous->link; - current = current->link; - } - } - - //update the pointers. Set 'temp' to the last node in the sorted part. Make 'min' move a step further so that 'min' points to the 1st node of the unsorted part - //start the iteration again - temp = min; - min = min->link; - previous = min; - current = min->link; - } -} - -// Test cases: - -// enter the no. of nodes : 5 -// 8 9 3 1 4 -// original list is : 8 9 3 1 4 -// sorted list is : 1 3 4 8 9 - -// enter the no. of nodes : 3 -// -1 -2 -3 -// original list is : -1 -2 -3 -// sorted list is : -3 -2 -1 - -// enter the no. of nodes : 8 -// 8 7 6 5 4 3 2 1 -// original list is : 8 7 6 5 4 3 2 1 -// sorted list is : 1 2 3 4 5 6 7 8 - -// enter the no. of nodes : 6 -// 5 3 4 1 -2 -4 -// original list is : 5 3 4 1 -2 -4 -// sorted list is : -4 -2 1 3 4 5 - -int main() -{ - node *head = NULL; - int n; - cout << "enter the no. of nodes : "; //taking input from user about the number of nodes in linked list - cin >> n; - if (n == 0) - return 0; - head = createlist(n); //creating the list - cout << "original list is : "; - print(head); //printing the original linked list - my_selection_sort_linked_list(head); //applying selection sort - cout << "sorted list is : "; - print(head); //printing the sorted linked list - return 0; -} \ No newline at end of file diff --git a/operations_on_datastructures/selectionsortlinkedlist.cpp b/operations_on_datastructures/selectionsortlinkedlist.cpp new file mode 100644 index 00000000000..0e8e80def7c --- /dev/null +++ b/operations_on_datastructures/selectionsortlinkedlist.cpp @@ -0,0 +1,172 @@ +#include +using namespace std; + +// node defined +class node { + public: + int data; + node *link; + node(int d) { + data = d; + link = NULL; + } +}; + +// printing the linked list +void print(node *head) { + node *current = head; + while (current != NULL) { + cout << current->data << " "; + current = current->link; + } + cout << endl; +} + +// creating the linked list with 'n' nodes +node *createlist(int n) { + node *head = NULL; + node *t = NULL; + for (int i = 0; i < n; i++) { + node *temp = NULL; + int num; + cin >> num; + temp = new node(num); + if (head == NULL) { + head = temp; + t = temp; + continue; + } + if (t->link == NULL) + t->link = temp; + t = temp; + } + return head; +} + +// performing selection sort on the linked list in an iterative manner +void my_selection_sort_linked_list(node *&head) { + node *min = head; // throughout the algorithm 'min' is used to denote the + // node with min value out of all the nodes left for + // scanning while scanning if we find a node 'X' with + // value lesser than min, then we update the pointers in + // such a way that 'X' becomes the predecessor of 'min' + node *current = + min->link; // 'current' refers to the current node we are scanning + node *previous = min; //'previous' refers to the node that is previous to + // the current node + node *temp = + NULL; // 'temp' in this algo is used to point to the last node of the + // sorted part of the linked list. + // eg. If at any time instance the state of the linked list is + // suppose 1->2->5->3->8->NULL then, we see that "1->2" is the + // sorted part of the LL, and therefore temp will be pointing to + // the last node of the sorted part,i.e,'2' We keep on arranging + // the Linked list in such a way that after each iteration the + // node with 'min' value is placed at its correct position. Eg. + // Let suppose initially we have 5->4->1->3->2->NULL After 1st + // iteration : 1->4->5->3->2->NULL and so on + + while ( + min->link != + NULL) // so that all the nodes are scanned or until there exists a node + { + // pick the first node from the unsorted part and assume that it is the + // minimum and then start scanning from the next node + + while (current != NULL) // suppose you choose the min node to be X, + // then scan starts from the (X+1)th node until + // its NULL. current = (X+1)th node and min = X + { + if (current->data < min->data) // if the current node is smaller + // than the presumed node 'min' + { + if (temp == NULL) // temp stays null for the first iteration, + // therefore it symbolizes that we are + // scanning for the first time + { + if (previous == + min) // if the 'previous' is pointing to the 'min' node + { + // Update the pointers + head = current; // update the head pointer with the + // current node + min->link = current->link; + current->link = previous; + min = current; + current = previous->link; + } else // if the 'previous' is not pointing to the 'min' + // node + { + // Update the pointers + head = current; // update the head pointer with the + // current node + previous->link = current->link; + current->link = min; + min = current; + current = previous->link; + } + } else // if 'temp' is not NULL, i.e., its not the 1st + // iteration + { + temp->link = current; + previous->link = current->link; + current->link = min; + min = current; + current = previous->link; + } + } else // if the current node is greater than min, just move the + // previous and the current pointer a step further + { + previous = previous->link; + current = current->link; + } + } + + // update the pointers. Set 'temp' to the last node in the sorted part. + // Make 'min' move a step further so that 'min' points to the 1st node + // of the unsorted part start the iteration again + temp = min; + min = min->link; + previous = min; + current = min->link; + } +} + +// Test cases: + +// enter the no. of nodes : 5 +// 8 9 3 1 4 +// original list is : 8 9 3 1 4 +// sorted list is : 1 3 4 8 9 + +// enter the no. of nodes : 3 +// -1 -2 -3 +// original list is : -1 -2 -3 +// sorted list is : -3 -2 -1 + +// enter the no. of nodes : 8 +// 8 7 6 5 4 3 2 1 +// original list is : 8 7 6 5 4 3 2 1 +// sorted list is : 1 2 3 4 5 6 7 8 + +// enter the no. of nodes : 6 +// 5 3 4 1 -2 -4 +// original list is : 5 3 4 1 -2 -4 +// sorted list is : -4 -2 1 3 4 5 + +int main() { + node *head = NULL; + int n; + cout << "enter the no. of nodes : "; // taking input from user about the + // number of nodes in linked list + cin >> n; + if (n == 0) + return 0; + head = createlist(n); // creating the list + cout << "original list is : "; + print(head); // printing the original linked list + my_selection_sort_linked_list(head); // applying selection sort + cout << "sorted list is : "; + print(head); // printing the sorted linked list + return 0; +} \ No newline at end of file diff --git a/operations_on_datastructures/union_of_2_arrays.cpp b/operations_on_datastructures/union_of_2_arrays.cpp new file mode 100644 index 00000000000..cdacf1d2e7e --- /dev/null +++ b/operations_on_datastructures/union_of_2_arrays.cpp @@ -0,0 +1,27 @@ +#include +int main() { + int m, n, i = 0, j = 0; + cout << "Enter size of both arrays:"; + cin >> m >> n; + int a[m]; + int b[n]; + cout << "Enter elements of array 1:"; + for (i = 0; i < m; i++) cin >> a[i]; + cout << "Enter elements of array 2:"; + for (i = 0; i < n; i++) cin >> b[i]; + i = 0; + j = 0; + while ((i < m) && (j < n)) { + if (a[i] < b[j]) + cout << a[i++] << " "; + else if (a[i] > b[j]) + cout << b[j++] << " "; + else { + cout << a[i++]; + j++; + } + } + while (i < m) cout << a[i++] << " "; + while (j < n) cout << b[j++] << " "; + return 0; +} diff --git a/others/Buzz_number.cpp b/others/Buzz_number.cpp deleted file mode 100644 index f31038aad61..00000000000 --- a/others/Buzz_number.cpp +++ /dev/null @@ -1,17 +0,0 @@ -//A buzz number is a number that is either divisble by 7 or has last digit as 7. -#include -using namespace std; -int main() -{ - int n, t; - cin >> t; - while (t--) - { - cin >> n; - if ((n % 7 == 0) || (n % 10 == 7)) - cout << n << " is a buzz number" << endl; - else - cout << n << " is not a buzz number" << endl; - } - return 0; -} diff --git a/others/CMakeLists.txt b/others/CMakeLists.txt new file mode 100644 index 00000000000..f049b5f2d31 --- /dev/null +++ b/others/CMakeLists.txt @@ -0,0 +1,18 @@ +# If necessary, use the RELATIVE flag, otherwise each source file may be listed +# with full pathname. RELATIVE may makes it easier to extract an executable name +# automatically. +file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) +# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) +foreach( testsourcefile ${APP_SOURCES} ) + # I used a simple string replace, to cut off .cpp. + string( REPLACE ".cpp" "" testname ${testsourcefile} ) + add_executable( ${testname} ${testsourcefile} ) + + set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) + if(OpenMP_CXX_FOUND) + target_link_libraries(${testname} OpenMP::OpenMP_CXX) + endif() + install(TARGETS ${testname} DESTINATION "bin/others") + +endforeach( testsourcefile ${APP_SOURCES} ) diff --git a/others/Decimal To Binary.cpp b/others/Decimal To Binary.cpp deleted file mode 100644 index 4e2119ebce8..00000000000 --- a/others/Decimal To Binary.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// This function convert decimal to binary number -// -#include -using namespace std; - -int main() -{ - int number; - cout << "Enter a number:"; - cin >> number; - int remainder, binary = 0, var = 1; - - do - { - remainder = number % 2; - number = number / 2; - binary = binary + (remainder * var); - var = var * 10; - - } while (number > 0); - cout << "the binary is :"; - cout << binary; - cout << endl; - return 0; -} diff --git a/others/Decimal To Hexadecimal .cpp b/others/Decimal To Hexadecimal .cpp deleted file mode 100644 index 705f21ba49f..00000000000 --- a/others/Decimal To Hexadecimal .cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include - -using namespace std; - -int main(void) -{ - int valueToConvert = 0; //Holds user input - int hexArray[8]; //Contains hex values backwards - int i = 0; //counter - char HexValues[] = "0123456789ABCDEF"; - - cout << "Enter a Decimal Value" << endl; //Displays request to stdout - cin >> valueToConvert; //Stores value into valueToConvert via user input - - while (valueToConvert > 15) - { //Dec to Hex Algorithm - hexArray[i++] = valueToConvert % 16; //Gets remainder - valueToConvert /= 16; - } - hexArray[i] = valueToConvert; //Gets last value - - cout << "Hex Value: "; - while (i >= 0) - cout << HexValues[hexArray[i--]]; - - cout << endl; - return 0; -} diff --git a/others/GCD_of_n_numbers.cpp b/others/GCD_of_n_numbers.cpp deleted file mode 100644 index 8158052f8fd..00000000000 --- a/others/GCD_of_n_numbers.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//This program aims at calculating the GCD of n numbers by division method -#include -using namepsace std; -int main() -{ - cout << "Enter value of n:" << endl; - cin >> n; - int a[n]; - int i, j, gcd; - cout << "Enter the n numbers:" << endl; - for (i = 0; i < n; i++) - cin >> a[i]; - j = 1; //to access all elements of the array starting from 1 - gcd = a[0]; - while (j < n) - { - if (a[j] % gcd == 0) //value of gcd is as needed so far - j++; //so we check for next element - else - gcd = a[j] % gcd; //calculating GCD by division method - } - cout << "GCD of entered n numbers:" << gcd; -} diff --git a/others/Palindromeofnumber.cpp b/others/Palindromeofnumber.cpp deleted file mode 100644 index 64780399703..00000000000 --- a/others/Palindromeofnumber.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -using namespace std; - -int main() -{ - int num; - cout << "Enter number = "; - cin >> num; - - string s1 = to_string(num); - string s2 = s1; - - reverse(s1.begin(), s1.end()); - - if (s1 == s2) - cout << "true"; - else - cout << "false"; - - return 0; -} diff --git a/others/Paranthesis Matching.cpp b/others/Paranthesis Matching.cpp deleted file mode 100644 index d2bb4d39c3d..00000000000 --- a/others/Paranthesis Matching.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include - -using namespace std; - -#define MAX 100 - -// -------------- stack -------------- - -char stack[MAX]; -int top = -1; - -void push(char ch) -{ - stack[++top] = ch; -} - -char pop() -{ - return stack[top--]; -} - -// -------------- end stack ----------- - -char opening(char ch) -{ - switch (ch) - { - case '}': - return '{'; - case ']': - return '['; - case ')': - return '('; - case '>': - return '<'; - } -} - -int main() -{ - - string exp; - int valid = 1, i = 0; - cout << "Enter The Expression : "; - cin >> exp; - - while (valid == 1 && i < exp.length()) - { - if (exp[i] == '(' || exp[i] == '{' || exp[i] == '[' || exp[i] == '<') - { - push(exp[i]); - } - else if (top >= 0 && stack[top] == opening(exp[i])) - { - pop(); - } - else - { - valid = 0; - } - i++; - } - - // makes sure the stack is empty after processsing (above) - if (valid == 1 && top == -1) - { - cout << "\nCorrect Expression"; - } - else - { - cout << "\nWrong Expression"; - } - - return 0; -} diff --git a/others/Primality Test.cpp b/others/Primality Test.cpp deleted file mode 100644 index ce8fc1706a0..00000000000 --- a/others/Primality Test.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -using namespace std; - -//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 6*k+1 or 6*k-1 for integer values of k. - -bool IsPrime(int number) -{ - if (((!(number & 1)) && number != 2) || (number < 2) || (number % 3 == 0 && number != 3)) - return false; - - for (int k = 1; 36 * k * k - 12 * k < number; ++k) - { - if ((number % (6 * k + 1) == 0) || (number % (6 * k - 1) == 0)) - return false; - } - return true; -} - -int main() -{ - //Main Function - cout << "Enter the value of n to check if Prime\n"; - int n; - cin >> n; - if (IsPrime(n)) - cout << n << " is Prime" << endl; - else - cout << n << " is not Prime" << endl; - - return 0; -} diff --git a/others/Sparse matrix.cpp b/others/Sparse matrix.cpp deleted file mode 100644 index 1861163f15f..00000000000 --- a/others/Sparse matrix.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/*A sparse matrix is a matrix which has number of zeroes greater than (m*n)/2, -where m and n are the dimensions of the matrix.*/ -#include -using namespace std; - -int main() -{ - int m, n; - int counterZeros = 0; - cout << "Enter dimensions of matrix (seperated with space): "; - cin >> m >> n; - int a[m][n]; - cout << "Enter matrix elements:"; - cout << "\n"; - - // reads the matrix from stdin - for (int i = 0; i < m; i++) - { - for (int j = 0; j < n; j++) - { - cout << "element? "; - cin >> a[i][j]; - } - } - - // counts the zero's - for (int i = 0; i < m; i++) - { - for (int j = 0; j < n; j++) - { - if (a[i][j] == 0) - counterZeros++; //Counting number of zeroes - } - } - - // makes sure the matrix is a sparse matrix - if (counterZeros > ((m * n) / 2)) //Checking for sparse matrix - cout << "Sparse matrix"; - else - cout << "Not a sparse matrix"; -} diff --git a/others/Strassen Matrix Multiplication.cpp b/others/Strassen Matrix Multiplication.cpp deleted file mode 100644 index 85b62776385..00000000000 --- a/others/Strassen Matrix Multiplication.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -using namespace std; - -Multiply(int A[][], int B[][], int n) -{ - if (n == 2) - { - int p1 = (a[0][0] + a[1][1]) * (b[0][0] + b[1][1]); - int p2 = (a[1][0] + a[1][1]) * b[0][0]; - int p3 = a[0][0] * (b[0][1] - b[1][1]); - int p4 = a[1][1] * (b[1][0] - b[0][0]); - int p5 = (a[0][0] + a[0][1]) * b[1][1]; - int p6 = (a[1][0] - a[0][0]) * (b[0][0] + b[0][1]); - int p7 = (a[0][1] - a[1][1]) * (b[1][0] + b[1][1]); - - int c[n][n]; - c[0][0] = p1 + p4 - p5 + p7; - c[0][1] = p3 + p5; - c[1][0] = p2 + p4; - c[1][1] = p1 - p2 + p3 + p6; - - return c[][]; - } - else - { - } -} - -int main() -{ - int p, q, r, s; - cout << "Enter the dimensions of Matrices"; - cin >> n; - int A[n][n], ; - int B[n][n], ; - cout << "Enter the elements of Matrix A"; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { - cin >> A[i][j]; - } - } - - cout << "Enter the elements of Matrix B"; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { - cin >> B[i][j]; - } - } - - Multiply(A, B, n); - return 0; -} \ No newline at end of file diff --git a/others/String Fibonacci.cpp b/others/String Fibonacci.cpp deleted file mode 100644 index e5475eec9aa..00000000000 --- a/others/String Fibonacci.cpp +++ /dev/null @@ -1,83 +0,0 @@ -//This Programme returns the Nth fibonacci as a string. -//The method used is manual addition with carry and placing it in a string which is called string addition -//This makes it have no bounds or limits - -#include -#include - -using namespace std; - -string add(string a, string b) -{ - string temp = ""; - - // carry flag - int carry = 0; - - // fills up with zeros - while ((int)a.length() < (int)b.length()) - { - a = "0" + a; - } - - // fills up with zeros - while ((int)b.length() < (int)a.length()) - { - b = "0" + b; - } - - // adds the numbers a and b - for (int i = a.length() - 1; i >= 0; i--) - { - char val = (char)(((a[i] - 48) + (b[i] - 48)) + 48 + carry); - if (val > 57) - { - carry = 1; - val -= 10; - } - else - { - carry = 0; - } - temp = val + temp; - } - - // processes the carry flag - if (carry == 1) - { - temp = "1" + temp; - } - - // removes leading zeros. - while (temp[0] == '0' && temp.length() > 1) - { - temp = temp.substr(1); - } - - return temp; -} - -void fib_Accurate(long long n) -{ - string tmp = ""; - string fibMinus1 = "1"; - string fibMinus2 = "0"; - for (long long i = 0; i < n; i++) - { - tmp = add(fibMinus1, fibMinus2); - fibMinus2 = fibMinus1; - fibMinus1 = tmp; - } - cout << fibMinus2; -} - -int main() -{ - int n; - cout << "Enter whatever number N you want to find the fibonacci of\n"; - cin >> n; - cout << n << " th Fibonacci is \n"; - fib_Accurate(n); - - return 0; -} diff --git a/others/Tower of Hanoi.cpp b/others/Tower of Hanoi.cpp deleted file mode 100644 index 5783d6a9882..00000000000 --- a/others/Tower of Hanoi.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -using namespace std; - -struct tower -{ - int values[10]; - int top; -} F, U, T; - -void show() -{ - cout << "\n\n\tF : "; - for (int i = 0; i < F.top; i++) - { - cout << F.values[i] << "\t"; - } - cout << "\n\tU : "; - for (int i = 0; i < U.top; i++) - { - cout << U.values[i] << "\t"; - } - cout << "\n\tT : "; - for (int i = 0; i < T.top; i++) - { - cout << T.values[i] << "\t"; - } -} - -void mov(tower &From, tower &To) -{ - --From.top; - To.values[To.top] = From.values[From.top]; - ++To.top; -} - -void TH(int n, tower &From, tower &Using, tower &To) -{ - - if (n == 1) - { - mov(From, To); - show(); - } - else - { - TH(n - 1, From, To, Using); - mov(From, To); - show(); - TH(n - 1, Using, From, To); - } -} - -int main() -{ - F.top = 0; - U.top = 0; - T.top = 0; - - int no; - - cout << "\nEnter number of discs : "; - cin >> no; - - for (int i = no; i > 0; i--) - { - F.values[F.top++] = i; - }; - - show(); - TH(no, F, U, T); - - return 0; -} diff --git a/others/buzz_number.cpp b/others/buzz_number.cpp new file mode 100644 index 00000000000..ed9fc5f2888 --- /dev/null +++ b/others/buzz_number.cpp @@ -0,0 +1,20 @@ +/** + * @file + * @brief A buzz number is a number that is either divisible by 7 or has last + * digit as 7. + */ +#include + +/** main function */ +int main() { + int n, t; + std::cin >> t; + while (t--) { + std::cin >> n; + if ((n % 7 == 0) || (n % 10 == 7)) + std::cout << n << " is a buzz number" << std::endl; + else + std::cout << n << " is not a buzz number" << std::endl; + } + return 0; +} diff --git a/others/decimal_to_binary.cpp b/others/decimal_to_binary.cpp new file mode 100644 index 00000000000..11ce064a538 --- /dev/null +++ b/others/decimal_to_binary.cpp @@ -0,0 +1,55 @@ +/** + * @file + * @brief Function to convert decimal number to binary representation + */ +#include + +/** + * This method converts the bit representation and stores it as a decimal + * number. + */ +void method1(int number) { + int remainder, binary = 0, var = 1; + + do { + remainder = number % 2; + number = number / 2; + binary = binary + (remainder * var); + var = var * 10; + } while (number > 0); + std::cout << "Method 1 : " << binary << std::endl; +} + +/** + * This method stores each bit value from LSB to MSB and then prints them back + * from MSB to LSB + */ +void method2(int number) { + int num_bits = 0; + char bit_string[50]; + + do { + bool bit = number & 0x01; // get last bit + if (bit) + bit_string[num_bits++] = '1'; + else + bit_string[num_bits++] = '0'; + number >>= 1; // right shift bit 1 bit + } while (number > 0); + + std::cout << "Method 2 : "; + while (num_bits >= 0) + std::cout << bit_string[num_bits--]; // print from MSB to LSB + std::cout << std::endl; +} + +int main() { + int number; + std::cout << "Enter a number:"; + std::cin >> number; + + method1(number); + method2(number); + + return 0; +} diff --git a/others/decimal_to_hexadecimal.cpp b/others/decimal_to_hexadecimal.cpp new file mode 100644 index 00000000000..a3e544f49f8 --- /dev/null +++ b/others/decimal_to_hexadecimal.cpp @@ -0,0 +1,34 @@ +/** + * @file + * @brief Convert decimal number to hexadecimal representation + */ + +#include + +/** + * Main program + */ +int main(void) { + int valueToConvert = 0; // Holds user input + int hexArray[8]; // Contains hex values backwards + int i = 0; // counter + char HexValues[] = "0123456789ABCDEF"; + + std::cout << "Enter a Decimal Value" + << std::endl; // Displays request to stdout + std::cin >> + valueToConvert; // Stores value into valueToConvert via user input + + while (valueToConvert > 15) { // Dec to Hex Algorithm + hexArray[i++] = valueToConvert % 16; // Gets remainder + valueToConvert /= 16; + // valueToConvert >>= 4; // This will divide by 2^4=16 and is faster + } + hexArray[i] = valueToConvert; // Gets last value + + std::cout << "Hex Value: "; + while (i >= 0) std::cout << HexValues[hexArray[i--]]; + + std::cout << std::endl; + return 0; +} diff --git a/others/Decimal to Roman Numeral.cpp b/others/decimal_to_roman_numeral.cpp similarity index 54% rename from others/Decimal to Roman Numeral.cpp rename to others/decimal_to_roman_numeral.cpp index 0372e800342..ad4aa32c5ad 100644 --- a/others/Decimal to Roman Numeral.cpp +++ b/others/decimal_to_roman_numeral.cpp @@ -1,31 +1,33 @@ -//This Programme Converts a given decimal number in the range [0,4000) -//to both Lower case and Upper case Roman Numeral +/** + * @file + * @brief This Programme Converts a given decimal number in the range [0,4000) + * to both Lower case and Upper case Roman Numeral + */ #include #include -#include +#include #include -using namespace std; -//This functions fills a string with character c, n times and returns it -string fill(char c, int n) -{ - string s = ""; - while (n--) - s += c; +/** This functions fills a string with character c, n times and returns it + * @note This can probably be replace by `memcpy` function. + */ +std::string fill(char c, int n) { + std::string s = ""; + while (n--) s += c; return s; } -//to convert to lowercase Roman Numeral -// the function works recursively -string tolowerRoman(int n) -{ +/** to convert to lowercase Roman Numeral + * the function works recursively + */ +std::string tolowerRoman(int n) { if (n < 4) return fill('i', n); if (n < 6) return fill('i', 5 - n) + "v"; if (n < 9) - return string("v") + fill('i', n - 5); + return std::string("v") + fill('i', n - 5); if (n < 11) return fill('i', 10 - n) + "x"; if (n < 40) @@ -33,7 +35,7 @@ string tolowerRoman(int n) if (n < 60) return fill('x', 5 - n / 10) + 'l' + tolowerRoman(n % 10); if (n < 90) - return string("l") + fill('x', n / 10 - 5) + tolowerRoman(n % 10); + return std::string("l") + fill('x', n / 10 - 5) + tolowerRoman(n % 10); if (n < 110) return fill('x', 10 - n / 10) + "c" + tolowerRoman(n % 10); if (n < 400) @@ -41,7 +43,8 @@ string tolowerRoman(int n) if (n < 600) return fill('c', 5 - n / 100) + 'd' + tolowerRoman(n % 100); if (n < 900) - return string("d") + fill('c', n / 100 - 5) + tolowerRoman(n % 100); + return std::string("d") + fill('c', n / 100 - 5) + + tolowerRoman(n % 100); if (n < 1100) return fill('c', 10 - n / 100) + "m" + tolowerRoman(n % 100); if (n < 4000) @@ -49,16 +52,16 @@ string tolowerRoman(int n) return "?"; } -//to convert to uppercase Roman Numeral -// the function works recursively -string toupperRoman(int n) -{ +/** to convert to uppercase Roman Numeral + * the function works recursively + */ +std::string toupperRoman(int n) { if (n < 4) return fill('I', n); if (n < 6) return fill('I', 5 - n) + "V"; if (n < 9) - return string("V") + fill('I', n - 5); + return std::string("V") + fill('I', n - 5); if (n < 11) return fill('I', 10 - n) + "X"; if (n < 40) @@ -66,7 +69,7 @@ string toupperRoman(int n) if (n < 60) return fill('X', 5 - n / 10) + 'L' + toupperRoman(n % 10); if (n < 90) - return string("L") + fill('X', n / 10 - 5) + toupperRoman(n % 10); + return std::string("L") + fill('X', n / 10 - 5) + toupperRoman(n % 10); if (n < 110) return fill('X', 10 - n / 10) + "C" + toupperRoman(n % 10); if (n < 400) @@ -74,7 +77,8 @@ string toupperRoman(int n) if (n < 600) return fill('C', 5 - n / 100) + 'D' + toupperRoman(n % 100); if (n < 900) - return string("D") + fill('C', n / 100 - 5) + toupperRoman(n % 100); + return std::string("D") + fill('C', n / 100 - 5) + + toupperRoman(n % 100); if (n < 1100) return fill('C', 10 - n / 100) + "M" + toupperRoman(n % 100); if (n < 4000) @@ -82,16 +86,13 @@ string toupperRoman(int n) return "?"; } -//main function - -int main() -{ - +/** main function */ +int main() { int n; - cout << "\t\tRoman numbers converter\n\n"; - cout << "Type in decimal number between 0 up to 4000 (exclusive): "; - cin >> n; - cout << n << " in Upper Roman Numerals is " << toupperRoman(n) << "\n"; - cout << n << " in Lower Roman Numerals is " << tolowerRoman(n) << "\n"; + std::cout << "\t\tRoman numbers converter\n\n"; + std::cout << "Type in decimal number between 0 up to 4000 (exclusive): "; + std::cin >> n; + std::cout << n << " in Upper Roman Numerals is " << toupperRoman(n) << "\n"; + std::cout << n << " in Lower Roman Numerals is " << tolowerRoman(n) << "\n"; return 0; } diff --git a/others/fast_interger_input.cpp b/others/fast_interger_input.cpp index 3358fc8bbe6..87963c9ad88 100644 --- a/others/fast_interger_input.cpp +++ b/others/fast_interger_input.cpp @@ -1,7 +1,15 @@ -// Read integers in the fastest way in c plus plus -#include +/** + * @file + * @brief Read integers from stdin continuously as they are entered without + * waiting for the `\n` character + */ +#include + +/** Function to read the number from stdin. The function reads input until a non + * numeric character is entered. + */ void fastinput(int *number) { -// variable to indicate sign of input integer + // variable to indicate sign of input integer bool negative = false; register int c; *number = 0; @@ -19,7 +27,7 @@ void fastinput(int *number) { // Keep on extracting characters if they are integers // i.e ASCII Value lies from '0'(48) to '9' (57) for (; (c > 47 && c < 58); c = std::getchar()) - *number = *number *10 + c - 48; + *number = *number * 10 + c - 48; // if scanned input has a negative sign, negate the // value of the input number @@ -27,10 +35,10 @@ void fastinput(int *number) { *(number) *= -1; } -// Function Call +/** Main function */ int main() { int number; fastinput(&number); - std::cout << number << "\n"; + std::cout << number << std::endl; return 0; } diff --git a/others/fibonacci.cpp b/others/fibonacci.cpp deleted file mode 100644 index 87ccda6d3dd..00000000000 --- a/others/fibonacci.cpp +++ /dev/null @@ -1,42 +0,0 @@ -//An efficient way to calculate nth fibonacci number faster and simpler than O(nlogn) method of matrix exponentiation -//This works by using both recursion and dynamic programming. -//as 93rd fibonacci exceeds 19 digits, which cannot be stored in a single long long variable, we can only use it till 92nd fibonacci -//we can use it for 10000th fibonacci etc, if we implement bigintegers. -//This algorithm works with the fact that nth fibonacci can easily found if we have already found n/2th or (n+1)/2th fibonacci -//It is a property of fibonacci similar to matrix exponentiation. - -#include -#include -using namespace std; - -const long long MAX = 93; - -long long f[MAX] = {0}; - -long long fib(long long n) -{ - - if (n == 0) - return 0; - if (n == 1 || n == 2) - return (f[n] = 1); - - if (f[n]) - return f[n]; - - long long k = (n % 2 != 0) ? (n + 1) / 2 : n / 2; - - f[n] = (n % 2 != 0) ? (fib(k) * fib(k) + fib(k - 1) * fib(k - 1)) - : (2 * fib(k - 1) + fib(k)) * fib(k); - return f[n]; -} - -int main() -{ - //Main Function - for (long long i = 1; i < 93; i++) - { - cout << i << " th fibonacci number is " << fib(i) << "\n"; - } - return 0; -} diff --git a/others/happy_number.cpp b/others/happy_number.cpp index 7d25a1bbd83..b1debaa54db 100644 --- a/others/happy_number.cpp +++ b/others/happy_number.cpp @@ -1,28 +1,39 @@ -/* 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 */ - -// Copyright 2019 TheAlgorithms contributors +/** + * @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 -int main() { - int n, k, s = 0, d; - std::cout << "Enter a number:"; - std::cin >> n; - s = 0; - k = n; - while (k > 9) { - while (k != 0) { - d = k % 10; - s += d; - k /= 10; +/** + * Checks if a decimal number is a happy number + * \returns true if happy else false + */ +template +bool is_happy(T n) { + T s = 0; // stores sum of digits + while (n > 9) { // while number is > 9, there are more than 1 digit + while (n != 0) { // get digit + T d = n % 10; + s += d; + n /= 10; + } + n = s; + s = 0; } - k = s; - s = 0; - } - if (k == 1) - std::cout << n << " is a happy number" << std::endl; - else - std::cout << n << " is not a happy number" << std::endl; - return 0; + return (n == 1) ? true : false; // true if k == 1 +} + +/** Main function */ +int main() { + int n; + std::cout << "Enter a number:"; + std::cin >> n; + + if (is_happy(n)) + std::cout << n << " is a happy number" << std::endl; + else + std::cout << n << " is not a happy number" << std::endl; + return 0; } diff --git a/others/matrix_exponentiation.cpp b/others/matrix_exponentiation.cpp index 25c411ddacb..d44d225937c 100644 --- a/others/matrix_exponentiation.cpp +++ b/others/matrix_exponentiation.cpp @@ -1,38 +1,64 @@ -/* -Matrix Exponentiation. +/** +@file +@brief Matrix Exponentiation. + The problem can be solved with DP but constraints are high. -ai = bi (for i <= k) -ai = c1*ai-1 + c2*ai-2 + ... + ck*ai-k (for i > k) -Taking the example of Fibonacci series, K=2 -b1 = 1, b2=1 -c1 = 1, c2=1 -a = 0 1 1 2 .... -This way you can find the 10^18 fibonacci number%MOD. +
\f$a_i = b_i\f$ (for \f$i <= k\f$) +
\f$a_i = c_1 a_{i-1} + c_2 a_{i-2} + ... + c_k a_{i-k}\f$ (for \f$i > k\f$) +
Taking the example of Fibonacci series, \f$k=2\f$ +
\f$b_1 = 1,\; b_2=1\f$ +
\f$c_1 = 1,\; c_2=1\f$ +
\f$a = \begin{bmatrix}0& 1& 1& 2& \ldots\end{bmatrix}\f$ +
This way you can find the \f$10^{18}\f$ fibonacci number%MOD. I have given a general way to use it. The program takes the input of B and C matrix. + Steps for Matrix Expo 1. Create vector F1 : which is the copy of B. 2. Create transpose matrix (Learn more about it on the internet) -3. Perform T^(n-1) [transpose matrix to the power n-1] -4. Multiply with F to get the last matrix of size (1xk). +3. Perform \f$T^{n-1}\f$ [transpose matrix to the power n-1] +4. Multiply with F to get the last matrix of size (1\f$\times\f$k). + The first element of this matrix is the required result. */ #include +#include + using std::cin; using std::cout; using std::vector; +/*! shorthand definition for `int64_t` */ #define ll int64_t -#define endl '\n' + +/*! shorthand definition for `std::endl` */ +#define endl std::endl + +/*! shorthand definition for `int64_t` */ #define pb push_back #define MOD 1000000007 -ll ab(ll x) { return x > 0LL ? x : -x; } + +/** returns absolute value */ +inline ll ab(ll x) { return x > 0LL ? x : -x; } + +/** global variable k + * @todo @stepfencurryxiao add documetnation + */ ll k; + +/** global vector variables + * @todo @stepfencurryxiao add documetnation + */ vector a, b, c; -// To multiply 2 matrix -vector> multiply(vector> A, vector> B) { +/** To multiply 2 matrices + * \param [in] A matrix 1 of size (m\f$\times\f$n) + * \param [in] B \p matrix 2 of size (p\f$\times\f$q)\n\note \f$p=n\f$ + * \result matrix of dimension (m\f$\times\f$q) + */ +vector> multiply(const vector> &A, + const vector> &B) { vector> C(k + 1, vector(k + 1)); for (ll i = 1; i <= k; i++) { for (ll j = 1; j <= k; j++) { @@ -44,8 +70,13 @@ vector> multiply(vector> A, vector> B) { return C; } -// computing power of a matrix -vector> power(vector> A, ll p) { +/** computing integer power of a matrix using recursive multiplication. + * @note A must be a square matrix for this algorithm. + * \param [in] A base matrix + * \param [in] p exponent + * \return matrix of same dimension as A + */ +vector> power(const vector> &A, ll p) { if (p == 1) return A; if (p % 2 == 1) { @@ -56,7 +87,10 @@ vector> power(vector> A, ll p) { } } -// main function +/*! Wrapper for Fibonacci + * \param[in] n \f$n^\text{th}\f$ Fibonacci number + * \return \f$n^\text{th}\f$ Fibonacci number + */ ll ans(ll n) { if (n == 0) return 0; @@ -64,8 +98,7 @@ ll ans(ll n) { return b[n - 1]; // F1 vector F1(k + 1); - for (ll i = 1; i <= k; i++) - F1[i] = b[i - 1]; + for (ll i = 1; i <= k; i++) F1[i] = b[i - 1]; // Transpose matrix vector> T(k + 1, vector(k + 1)); @@ -92,8 +125,7 @@ ll ans(ll n) { return res; } -// 1 1 2 3 5 - +/** Main function */ int main() { cin.tie(0); cout.tie(0); diff --git a/others/measure_time_elapsed.cpp b/others/measure_time_elapsed.cpp deleted file mode 100644 index d0830ab79fe..00000000000 --- a/others/measure_time_elapsed.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// To calculate the time taken by a code to execute -#include -#include - -__int64_t getTimeInMicroseconds() { - struct timeval start; - gettimeofday(&start, NULL); - return start.tv_sec * 1000000 + start.tv_usec; -} - -// write function sample(args) - -int main() { - // write code - __int64_t starttime = getTimeInMicroseconds(); - // sample(args) function run - // Any other functions (if present) run - std::cout << getTimeInMicroseconds() - starttime; -} diff --git a/others/palindrome_of_number.cpp b/others/palindrome_of_number.cpp new file mode 100644 index 00000000000..66401ff966a --- /dev/null +++ b/others/palindrome_of_number.cpp @@ -0,0 +1,35 @@ +/** + * @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 +#include + +#ifdef _MSC_VER +// Required to compile std::toString function using MSVC +#include +#else +#include +#endif + +/** Main function */ +int main() { + int num; + std::cout << "Enter number = "; + std::cin >> num; + + std::string s1 = std::to_string(num); // convert number to string + std::string s2 = s1; + + std::reverse(s1.begin(), s1.end()); // reverse the string + + if (s1 == s2) // check if reverse and original string are identical + std::cout << "true"; + else + std::cout << "false"; + + return 0; +} diff --git a/others/paranthesis_matching.cpp b/others/paranthesis_matching.cpp new file mode 100644 index 00000000000..2a6358d94e7 --- /dev/null +++ b/others/paranthesis_matching.cpp @@ -0,0 +1,75 @@ +/** + * @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 +#ifdef _MSC_VER +#include // Visual Studio C requires this include +#else +#include +#endif + +/** check number */ +#define MAX 100 + +//! @{-------------- stack -------------- +//! global stack +char stack[MAX]; + +//! pointer to track stack index +int top = -1; + +//! push byte to stack variable +void push(char ch) { stack[++top] = ch; } + +//! pop a byte out of stack variable +char pop() { return stack[top--]; } + +//! @}-------------- end stack ----------- + +/** return opening paranthesis corresponding to the close paranthesis + * @param[in] ch closed paranthesis character + */ +char opening(char ch) { + switch (ch) { + case '}': + return '{'; + case ']': + return '['; + case ')': + return '('; + case '>': + return '<'; + } + return '\0'; +} + +int main() { + std::string exp; + int valid = 1, i = 0; + std::cout << "Enter The Expression : "; + std::cin >> exp; + + while (valid == 1 && i < exp.length()) { + if (exp[i] == '(' || exp[i] == '{' || exp[i] == '[' || exp[i] == '<') { + push(exp[i]); + } else if (top >= 0 && stack[top] == opening(exp[i])) { + pop(); + } else { + valid = 0; + } + i++; + } + + // makes sure the stack is empty after processsing (above) + if (valid == 1 && top == -1) { + std::cout << "\nCorrect Expression"; + } else { + std::cout << "\nWrong Expression"; + } + + return 0; +} diff --git a/others/pascal_triangle.cpp b/others/pascal_triangle.cpp index 101100018fa..4ea58f3f1e4 100644 --- a/others/pascal_triangle.cpp +++ b/others/pascal_triangle.cpp @@ -1,63 +1,75 @@ -#include - -using namespace std; - -void show_pascal(int **arr, int n) -{ - //pint Pascal's Triangle - for (int i = 0; i < n; ++i) - { - for (int j = 0; j < n + i; ++j) - { - if (arr[i][j] == 0) - cout << " "; - else - cout << arr[i][j]; - } - cout << endl; - } +/** + * @file + * @brief Pascal's triangle implementation + */ +#ifdef _MSC_VER +#include // required for Visual C +#else +#include +#endif +#include +#include + +/** + * Print the triangle + * \param [in] arr 2D-array containing Pascal numbers + * \param [in] n depth of Pascal triangle to print + */ +void show_pascal(int **arr, int n) { + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n + i; ++j) { + if (arr[i][j] == 0) + std::cout << std::setw(4) << " "; + else + std::cout << std::setw(4) << arr[i][j]; + } + std::cout << std::endl; + } } -int **pascal_triangle(int **arr, int n) -{ - for (int i = 0; i < n; ++i) - { - for (int j = n - i - 1; j < n + i; ++j) - { - if (j == n - i - 1 || j == n + i - 1) - arr[i][j] = 1; //The edge of the Pascal triangle goes in 1 - else - arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j + 1]; - } - } - - return arr; +/** + * Print the triangle + * \param [in,out] arr array containing Pascal numbers + * \param [in] n depth of Pascal triangle to print + * \result arr pointer returned + */ +int **pascal_triangle(int **arr, int n) { + for (int i = 0; i < n; ++i) { + for (int j = n - i - 1; j < n + i; ++j) { + if (j == n - i - 1 || j == n + i - 1) + arr[i][j] = 1; // The edge of the Pascal triangle goes in 1 + else + arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j + 1]; + } + } + + return arr; } -int main() -{ - int n = 0; - - cout << "Set Pascal's Triangle Height" << endl; - cin >> n; - - //memory allocation (Assign two-dimensional array to store Pascal triangle) - int **arr = new int*[n]; - for (int i = 0; i < n; ++i) - { - arr[i] = new int[2 * n - 1]; - memset(arr[i], 0, sizeof(int)*(2 * n - 1)); - } - - pascal_triangle(arr, n); - show_pascal(arr, n); - - //deallocation - for (int i = 0; i < n; ++i) - { - delete[] arr[i]; - } - delete[] arr; - - return 0; +/** + * main function + */ +int main() { + int n = 0; + + std::cout << "Set Pascal's Triangle Height" << std::endl; + std::cin >> n; + + // memory allocation (Assign two-dimensional array to store Pascal triangle) + int **arr = new int *[n]; + for (int i = 0; i < n; ++i) { + arr[i] = new int[2 * n - 1]; + memset(arr[i], 0, sizeof(int) * (2 * n - 1)); + } + + pascal_triangle(arr, n); + show_pascal(arr, n); + + // deallocation + for (int i = 0; i < n; ++i) { + delete[] arr[i]; + } + delete[] arr; + + return 0; } diff --git a/others/primality_test.cpp b/others/primality_test.cpp new file mode 100644 index 00000000000..faec6589cff --- /dev/null +++ b/others/primality_test.cpp @@ -0,0 +1,42 @@ +/** + * @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\pm1\f$ for + * > integer values of k. + * This gives a 3x speed improvement. + */ +#include + +/** Check if a number is prime + * \param[in] number number to check + * \returns true if prime else false + */ +bool IsPrime(int number) { + if (((!(number & 1)) && number != 2) || (number < 2) || + (number % 3 == 0 && number != 3)) + return false; + + for (int k = 1; 36 * k * k - 12 * k < number; ++k) { + if ((number % (6 * k + 1) == 0) || (number % (6 * k - 1) == 0)) + return false; + } + return true; +} + +/** main function */ +int main() { + // Main Function + std::cout << "Enter the value of n to check if Prime\n"; + int n; + std::cin >> n; + if (IsPrime(n)) + std::cout << n << " is Prime" << std::endl; + else + std::cout << n << " is not Prime" << std::endl; + + return 0; +} diff --git a/others/sieve_of_Eratosthenes.cpp b/others/sieve_of_Eratosthenes.cpp deleted file mode 100644 index e87ad498367..00000000000 --- a/others/sieve_of_Eratosthenes.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Sieve of Eratosthenes is an algorithm to find the primes - * that is between 2 to N (as defined in main). - * - * Time Complexity : O(N) - * Space Complexity : O(N) - */ - -#include -using namespace std; - -#define MAX 10000000 - -int primes[MAX]; - -/* - * This is the function that finds the primes and eliminates - * the multiples. - */ -void sieve(int N) -{ - primes[0] = 1; - primes[1] = 1; - for (int i = 2; i <= N; i++) - { - if (primes[i] == 1) - continue; - for (int j = i + i; j <= N; j += i) - primes[j] = 1; - } -} - -/* - * This function prints out the primes to STDOUT - */ -void print(int N) -{ - for (int i = 0; i <= N; i++) - if (primes[i] == 0) - cout << i << ' '; - cout << '\n'; -} - -/* - * NOTE: This function is important for the - * initialization of the array. - */ -void init() -{ - for (int i = 0; i < MAX; i++) - primes[i] = 0; -} - -int main() -{ - int N = 100; - init(); - sieve(N); - print(N); -} diff --git a/others/smallest-circle.cpp b/others/smallest-circle.cpp deleted file mode 100644 index 48437cd8681..00000000000 --- a/others/smallest-circle.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include -#include -#include - -using namespace std; - -struct Point -{ - double x, y; - Point(double a = 0.0, double b = 0.0) - { - x = a; - y = b; - } -}; - -double LenghtLine(Point A, Point B) -{ - return sqrt(abs((B.x - A.x) * (B.x - A.x)) + abs((B.y - A.y) * (B.y - A.y))); -} - -double TriangleArea(Point A, Point B, Point C) -{ - double a = LenghtLine(A, B); - double b = LenghtLine(B, C); - double c = LenghtLine(C, A); - double p = (a + b + c) / 2; - return sqrt(p * (p - a) * (p - b) * (p - c)); -} - -bool PointInCircle(vector &P, Point Center, double R) -{ - for (size_t i = 0; i < P.size(); i++) - { - if (LenghtLine(P[i], Center) > R) - return false; - } - return true; -} - -double circle(vector P) -{ - double minR = INT8_MAX; - double R; - Point C; - Point minC; - for (size_t i = 0; i < P.size() - 2; i++) - for (size_t j = i + 1; j < P.size(); j++) - for (size_t k = j + 1; k < P.size(); k++) - { - C.x = -0.5 * ((P[i].y * (P[j].x * P[j].x + P[j].y * P[j].y - P[k].x * P[k].x - P[k].y * P[k].y) + P[j].y * (P[k].x * P[k].x + P[k].y * P[k].y - P[i].x * P[i].x - P[i].y * P[i].y) + P[k].y * (P[i].x * P[i].x + P[i].y * P[i].y - P[j].x * P[j].x - P[j].y * P[j].y)) / (P[i].x * (P[j].y - P[k].y) + P[j].x * (P[k].y - P[i].y) + P[k].x * (P[i].y - P[j].y))); - C.y = 0.5 * ((P[i].x * (P[j].x * P[j].x + P[j].y * P[j].y - P[k].x * P[k].x - P[k].y * P[k].y) + P[j].x * (P[k].x * P[k].x + P[k].y * P[k].y - P[i].x * P[i].x - P[i].y * P[i].y) + P[k].x * (P[i].x * P[i].x + P[i].y * P[i].y - P[j].x * P[j].x - P[j].y * P[j].y)) / (P[i].x * (P[j].y - P[k].y) + P[j].x * (P[k].y - P[i].y) + P[k].x * (P[i].y - P[j].y))); - R = (LenghtLine(P[i], P[j]) * LenghtLine(P[j], P[k]) * LenghtLine(P[k], P[i])) / (4 * TriangleArea(P[i], P[j], P[k])); - if (!PointInCircle(P, C, R)) - { - continue; - } - if (R <= minR) - { - minR = R; - minC = C; - } - } - for (size_t i = 0; i < P.size() - 1; i++) - for (size_t j = i + 1; j < P.size(); j++) - { - C.x = (P[i].x + P[j].x) / 2; - C.y = (P[i].y + P[j].y) / 2; - R = LenghtLine(C, P[i]); - if (!PointInCircle(P, C, R)) - { - continue; - } - if (R <= minR) - { - minR = R; - minC = C; - } - } - cout << minC.x << " " << minC.y << endl; - return minR; -} - -void test() -{ - vector Pv(5); - Pv.push_back(Point(0, 0)); - Pv.push_back(Point(1, 3)); - Pv.push_back(Point(4, 1)); - Pv.push_back(Point(5, 4)); - Pv.push_back(Point(3, -2)); - cout << circle(Pv) << endl; -} - -void test2() -{ - vector Pv(4); - Pv.push_back(Point(0, 0)); - Pv.push_back(Point(0, 2)); - Pv.push_back(Point(2, 2)); - Pv.push_back(Point(2, 0)); - cout << circle(Pv) << endl; -} - -void test3() -{ - vector Pv(3); - Pv.push_back(Point(0.5, 1)); - Pv.push_back(Point(3.5, 3)); - Pv.push_back(Point(2.5, 0)); - cout << circle(Pv) << endl; -} -int main() -{ - test(); - cout << endl; - test2(); - cout << endl; - test3(); - return 0; -} diff --git a/others/smallest_circle.cpp b/others/smallest_circle.cpp new file mode 100644 index 00000000000..9ee4353eb4e --- /dev/null +++ b/others/smallest_circle.cpp @@ -0,0 +1,205 @@ +/** + * @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 +#include +#include + +/** Define a point */ +struct Point { + double x, /**< abscissa */ + y; /**< ordinate */ + + /** construct a point + * \param [in] a absicca (default = 0.0) + * \param [in] b ordinate (default = 0.0) + */ + explicit Point(double a = 0.f, double b = 0.f) { + x = a; + y = b; + } +}; + +/** Compute the Euclidian distance between two points \f$A\equiv(x_1,y_1)\f$ and + * \f$B\equiv(x_2,y_2)\f$ using the formula: + * \f[d=\sqrt{\left(x_1-x_2\right)^2+\left(y_1-y_2\right)^2}\f] + * + * \param [in] A point A + * \param [in] B point B + * \return ditance + */ +double LenghtLine(const Point &A, const Point &B) { + double dx = B.x - A.x; + double dy = B.y - A.y; + return std::sqrt((dx * dx) + (dy * dy)); +} + +/** + * Compute the area of triangle formed by three points using [Heron's + * formula](https://en.wikipedia.org/wiki/Heron%27s_formula). + * If the lengths of the sides of the triangle are \f$a,\,b,\,c\f$ and + * \f$s=\displaystyle\frac{a+b+c}{2}\f$ is the semi-perimeter then the area is + * given by \f[A=\sqrt{s(s-a)(s-b)(s-c)}\f] + * \param [in] A vertex A + * \param [in] B vertex B + * \param [in] C vertex C + * \returns area of triangle + */ +double TriangleArea(const Point &A, const Point &B, const Point &C) { + double a = LenghtLine(A, B); + double b = LenghtLine(B, C); + double c = LenghtLine(C, A); + double p = (a + b + c) / 2; + return std::sqrt(p * (p - a) * (p - b) * (p - c)); +} + +/** + * Check if a set of points lie within given circle. This is true if the + * distance of all the points from the centre of the circle is less than the + * radius of the circle + * \param [in] P set of points to check + * \param [in] Center coordinates to centre of the circle + * \param [in] R radius of the circle + * \returns True if P lies on or within the circle + * \returns False if P lies outside the circle + */ +bool PointInCircle(const std::vector &P, const Point &Center, double R) { + for (size_t i = 0; i < P.size(); i++) { + if (LenghtLine(P[i], Center) > R) + return false; + } + return true; +} + +/** + * Find the centre and radius of a circle enclosing a set of points.\n + * The function returns the radius of the circle and prints the coordinated of + * the centre of the circle. + * \param [in] P vector of points + * \returns radius of the circle + */ +double circle(const std::vector &P) { + double minR = INFINITY; + double R; + Point C; + Point minC; + + /* This code is invalid and does not give correct result for TEST 3 */ + // for each point in the list + for (size_t i = 0; i < P.size() - 2; i++) + // for every subsequent point in the list + for (size_t j = i + 1; j < P.size(); j++) + // for every subsequent point in the list + for (size_t k = j + 1; k < P.size(); k++) { + // here, we now have picked three points from the given set of + // points that we can use + // viz., P[i], P[j] and P[k] + C.x = -0.5 * ((P[i].y * (P[j].x * P[j].x + P[j].y * P[j].y - + P[k].x * P[k].x - P[k].y * P[k].y) + + P[j].y * (P[k].x * P[k].x + P[k].y * P[k].y - + P[i].x * P[i].x - P[i].y * P[i].y) + + P[k].y * (P[i].x * P[i].x + P[i].y * P[i].y - + P[j].x * P[j].x - P[j].y * P[j].y)) / + (P[i].x * (P[j].y - P[k].y) + + P[j].x * (P[k].y - P[i].y) + + P[k].x * (P[i].y - P[j].y))); + C.y = 0.5 * ((P[i].x * (P[j].x * P[j].x + P[j].y * P[j].y - + P[k].x * P[k].x - P[k].y * P[k].y) + + P[j].x * (P[k].x * P[k].x + P[k].y * P[k].y - + P[i].x * P[i].x - P[i].y * P[i].y) + + P[k].x * (P[i].x * P[i].x + P[i].y * P[i].y - + P[j].x * P[j].x - P[j].y * P[j].y)) / + (P[i].x * (P[j].y - P[k].y) + + P[j].x * (P[k].y - P[i].y) + + P[k].x * (P[i].y - P[j].y))); + R = (LenghtLine(P[i], P[j]) * LenghtLine(P[j], P[k]) * + LenghtLine(P[k], P[i])) / + (4 * TriangleArea(P[i], P[j], P[k])); + if (!PointInCircle(P, C, R)) { + continue; + } + if (R <= minR) { + minR = R; + minC = C; + } + } + + // for each point in the list + for (size_t i = 0; i < P.size() - 1; i++) + // for every subsequent point in the list + for (size_t j = i + 1; j < P.size(); j++) { + // check for diameterically opposite points + C.x = (P[i].x + P[j].x) / 2; + C.y = (P[i].y + P[j].y) / 2; + R = LenghtLine(C, P[i]); + if (!PointInCircle(P, C, R)) { + continue; + } + if (R <= minR) { + minR = R; + minC = C; + } + } + std::cout << minC.x << " " << minC.y << std::endl; + return minR; +} + +/** Test case: result should be: + * \n Circle with + * \n radius 3.318493136080724 + * \n centre at (3.0454545454545454, 1.3181818181818181) + */ +void test() { + std::vector Pv; + Pv.push_back(Point(0, 0)); + Pv.push_back(Point(5, 4)); + Pv.push_back(Point(1, 3)); + Pv.push_back(Point(4, 1)); + Pv.push_back(Point(3, -2)); + std::cout << circle(Pv) << std::endl; +} + +/** Test case: result should be: + * \n Circle with + * \n radius 1.4142135623730951 + * \n centre at (1.0, 1.0) + */ +void test2() { + std::vector Pv; + Pv.push_back(Point(0, 0)); + Pv.push_back(Point(0, 2)); + Pv.push_back(Point(2, 2)); + Pv.push_back(Point(2, 0)); + std::cout << circle(Pv) << std::endl; +} + +/** Test case: result should be: + * \n Circle with + * \n radius 1.821078397711709 + * \n centre at (2.142857142857143, 1.7857142857142856) + * @todo This test fails + */ +void test3() { + std::vector Pv; + Pv.push_back(Point(0.5, 1)); + Pv.push_back(Point(3.5, 3)); + Pv.push_back(Point(2.5, 0)); + Pv.push_back(Point(2, 1.5)); + std::cout << circle(Pv) << std::endl; +} + +/** Main program */ +int main() { + test(); + std::cout << std::endl; + test2(); + std::cout << std::endl; + test3(); + return 0; +} diff --git a/others/sparse_matrix.cpp b/others/sparse_matrix.cpp new file mode 100644 index 00000000000..a358f0da472 --- /dev/null +++ b/others/sparse_matrix.cpp @@ -0,0 +1,48 @@ +/** @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 + +/** main function */ +int main() { + int m, n; + int counterZeros = 0; + + std::cout << "Enter dimensions of matrix (seperated with space): "; + std::cin >> m; + std::cin >> n; + + int **a = new int *[m]; + for (int i = 0; i < m; i++) a[i] = new int[n]; + + std::cout << "Enter matrix elements:"; + std::cout << "\n"; + + // reads the matrix from stdin + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + std::cout << "element? "; + std::cin >> a[i][j]; + } + } + + // counts the zero's + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (a[i][j] == 0) + counterZeros++; // Counting number of zeroes + } + } + + // makes sure the matrix is a sparse matrix + if (counterZeros > ((m * n) / 2)) // Checking for sparse matrix + std::cout << "Sparse matrix"; + else + std::cout << "Not a sparse matrix"; + + for (int i = 0; i < m; i++) delete[] a[i]; + delete[] a; + return 0; +} diff --git a/others/spiral_print.cpp b/others/spiral_print.cpp index e6e6899ef6d..02dc3183aee 100644 --- a/others/spiral_print.cpp +++ b/others/spiral_print.cpp @@ -1,78 +1,81 @@ +/** + * @file + * @brief Print the elements of a matrix traversing it spirally + */ #include -using namespace std; - -void genArray(int a[][10], int r, int c) -{ +/** 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, int r, int c) { int value = 1; - for (int i = 0; i < r; i++) - { - for (int j = 0; j < c; j++) - { + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { a[i][j] = value; - cout << a[i][j] << " "; + std::cout << a[i][j] << " "; value++; } - cout << endl; + std::cout << std::endl; } } -void spiralPrint(int a[][10], int r, int c) -{ +/** Traverse the matrix spirally and print the sequence of elements + * \param [in] a matrix to read from + * \param [in] r number of rows + * \param [in] c number of columns + */ +void spiralPrint(int **a, int r, int c) { int startRow = 0, endRow = r - 1; int startCol = 0, endCol = c - 1; int cnt = 0; - while (startRow <= endRow && startCol <= endCol) - { - - ///Print start row - for (int i = startCol; i <= endCol; i++, cnt++) - { - cout << a[startRow][i] << " "; + while (startRow <= endRow && startCol <= endCol) { + /// Print start row + for (int i = startCol; i <= endCol; i++, cnt++) { + std::cout << a[startRow][i] << " "; } startRow++; - ///Print the end col - for (int i = startRow; i <= endRow; i++, cnt++) - { - cout << a[i][endCol] << " "; + /// Print the end col + for (int i = startRow; i <= endRow; i++, cnt++) { + std::cout << a[i][endCol] << " "; } endCol--; - ///Print the end row - if (cnt == r * c) - { + /// Print the end row + if (cnt == r * c) { break; } - for (int i = endCol; i >= startCol; i--, cnt++) - { - cout << a[endRow][i] << " "; + for (int i = endCol; i >= startCol; i--, cnt++) { + std::cout << a[endRow][i] << " "; } endRow--; - ///Print the start Col - if (cnt == r * c) - { + /// Print the start Col + if (cnt == r * c) { break; } - for (int i = endRow; i >= startRow; i--, cnt++) - { - cout << a[i][startCol] << " "; + for (int i = endRow; i >= startRow; i--, cnt++) { + std::cout << a[i][startCol] << " "; } startCol++; } } -int main() -{ - int a[10][10]; - +/** main function */ +int main() { int r, c; - cin >> r >> c; + std::cin >> r >> c; + int **a = new int *[r]; + for (int i = 0; i < r; i++) a[i] = new int[c]; + genArray(a, r, c); spiralPrint(a, r, c); + for (int i = 0; i < r; i++) delete[] a[i]; + delete[] a; return 0; } diff --git a/others/stairs_pattern.cpp b/others/stairs_pattern.cpp index 281446a2fbf..a3b8b0a44d6 100644 --- a/others/stairs_pattern.cpp +++ b/others/stairs_pattern.cpp @@ -1,31 +1,35 @@ -/* -This program is use to print the following pattern - ** - ** - **** - **** - ****** - ****** -******** -******** -where number of pairs line is given by user +/** + * @file +@brief This program is use to print the following pattern
+   \*\*
+   \*\*
+  \*\*\*\*
+  \*\*\*\*
+ \*\*\*\*\*\*
+ \*\*\*\*\*\*
+\*\*\*\*\*\*\*\*
+********
+where number of pairs line is given by user */ -#include +#include + +/** main function */ int main() { -int l, st = 2, x, r, z, n, sp; -std::cout << "enter Index "; -std::cin >> x; -z = x; -for (r = 1; r <= x; r++) { -z = z - 1; -for (n = 1; n <= 2; n++) { -for (sp = 1; sp <= z; sp++) { -std::cout << " "; + int l, st = 2, x, r, z, n, sp; + std::cout << "enter Index "; + std::cin >> x; + z = x; + for (r = 1; r <= x; r++) { + z = z - 1; + for (n = 1; n <= 2; n++) { + for (sp = 1; sp <= z; sp++) { + std::cout << " "; + } + for (l = 1; l <= st; l++) { + std::cout << "*"; + } + std::cout << std::endl; + } + st = st + 2; + } } -for (l = 1; l <= st; l++) { -std::cout << "*"; -} -std::cout <<"\n"; -} -st = st + 2; -}} diff --git a/others/tower_of_hanoi.cpp b/others/tower_of_hanoi.cpp new file mode 100644 index 00000000000..323b2e424a5 --- /dev/null +++ b/others/tower_of_hanoi.cpp @@ -0,0 +1,85 @@ +/** + * @file + * @brief Solve the [Tower of + * Hanoi](https://en.wikipedia.org/wiki/Tower_of_Hanoi) problem. + */ +#include + +/** + * Define the state of tower + */ +struct tower { + //! Values in the tower + int values[10]; + //! top tower ID + int top; +}; + +/** Display the towers */ +void show(const struct tower *const F, const struct tower *const T, + const struct tower *const U) { + std::cout << "\n\n\tF : "; + for (int i = 0; i < F->top; i++) { + std::cout << F->values[i] << "\t"; + } + std::cout << "\n\tU : "; + for (int i = 0; i < U->top; i++) { + std::cout << U->values[i] << "\t"; + } + std::cout << "\n\tT : "; + for (int i = 0; i < T->top; i++) { + std::cout << T->values[i] << "\t"; + } +} + +/** Move one disc from one tower to another + * \param [in,out] From tower to move disk *from* + * \param [in,out] To tower to move disk *to* + */ +void mov(tower *From, tower *To) { + --From->top; + To->values[To->top] = From->values[From->top]; + ++To->top; +} + +/** + * Recursive algorithm to solve the puzzle + * \param [in] n starting number of disks + * \param [in,out] From tower to move disks from + * \param [in,out] Using temporary tower for the puzzle + * \param [in,out] To tower to move disk to + */ +void TH(int n, tower *From, tower *Using, tower *To) { + if (n == 1) { + mov(From, To); + show(From, To, Using); + } else { + TH(n - 1, From, To, Using); + mov(From, To); + show(From, To, Using); + TH(n - 1, Using, From, To); + } +} + +/** Main function */ +int main() { + struct tower F, U, T; + + F.top = 0; + U.top = 0; + T.top = 0; + + int no; + + std::cout << "\nEnter number of discs : "; + std::cin >> no; + + for (int i = no; i > 0; i--) { + F.values[F.top++] = i; + } + + show(&F, &T, &U); + TH(no, &F, &U, &T); + + return 0; +} diff --git a/others/vector_important_functions.cpp b/others/vector_important_functions.cpp index e0a70eedacd..d23ff9c978d 100644 --- a/others/vector_important_functions.cpp +++ b/others/vector_important_functions.cpp @@ -1,45 +1,43 @@ -// A C++ program to demonstrate working of sort(), -// reverse() +/** + * @file + * @brief A C++ program to demonstrate working of std::sort(), std::reverse() + */ #include #include +#include // For accumulate operation #include -#include //For accumulate operation -using namespace std; -int main() -{ - // Initializing vector with array values - int arr[] = {10, 20, 5, 23 ,42 , 15}; - int n = sizeof(arr)/sizeof(arr[0]); - vector vect(arr, arr+n); +/** Main function */ +int main() { + // Initializing vector with array values + int arr[] = {10, 20, 5, 23, 42, 15}; + int n = sizeof(arr) / sizeof(arr[0]); + std::vector vect(arr, arr + n); - cout << "Vector is: "; - for (int i=0; i -// calculates the probability of the events A or B for independent events - +/** + * 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 A and B + */ double addition_rule_independent(double A, double B) { return (A + B) - (A * B); } -// calculates the probability of the events A or B for dependent events -// note that if value of B_given_A is unknown, use chainrule to find it - +/** Calculates the probability of the events A or B for dependent events + * note that if value of B_given_A is unknown, use chainrule to find it + * \parama [in] A probability of event A + * \parama [in] B probability of event B + * \parama [in] B_given_A probability of event B condition A + * \returns probability of A and B + */ double addition_rule_dependent(double A, double B, double B_given_A) { return (A + B) - (A * B_given_A); } +/** Main function */ int main() { double A = 0.5; double B = 0.25; double B_given_A = 0.05; - std::cout << "independent P(A or B) = " - << addition_rule_independent(A, B) << std::endl; + std::cout << "independent P(A or B) = " << addition_rule_independent(A, B) + << std::endl; std::cout << "dependent P(A or B) = " - << addition_rule_dependent(A, B, B_given_A) << std::endl; + << addition_rule_dependent(A, B, B_given_A) << std::endl; return 0; } diff --git a/probability/bayes_theorem.cpp b/probability/bayes_theorem.cpp index d30be6c9ab1..aaa557a9456 100644 --- a/probability/bayes_theorem.cpp +++ b/probability/bayes_theorem.cpp @@ -1,24 +1,28 @@ +/** + * @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 probability of A given that the event B + * has occured'. + */ #include -// bayes' theorem > https://en.wikipedia.org/wiki/Bayes%27_theorem - -// bayes' theorem allows one to find P(A|B) given P(B|A) -// or P(B|A) given P(A|B) and P(A) and P(B) - -// note P(A|B) is read 'The probability of A given that the event B has occured' - -// returns P(A|B) - +/** returns P(A|B) + */ double bayes_AgivenB(double BgivenA, double A, double B) { return (BgivenA * A) / B; } -// returns P(B|A) - +/** returns P(B|A) + */ double bayes_BgivenA(double AgivenB, double A, double B) { return (AgivenB * B) / A; } +/** Main function + */ int main() { double A = 0.01; double B = 0.1; diff --git a/probability/binomial_dist.cpp b/probability/binomial_dist.cpp index b21a3e0fcef..1f30c504800 100644 --- a/probability/binomial_dist.cpp +++ b/probability/binomial_dist.cpp @@ -1,81 +1,100 @@ -#include +/** + * @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 : probability of success + * * x : desired successes + */ #include +#include -// the binomial distribution models the number of -// successes in a sequence of n independent events - -// n : number of trials -// p : probability of success -// x : desired successes - -// finds the expected value of a binomial distribution - -double binomial_expected(double n, double p) { - return n * p; -} - -// finds the variance of the binomial distribution - -double binomial_variance(double n, double p) { - return n * p * (1 - p); -} - -// finds the standard deviation of the binomial distribution - +/** finds the expected value of a binomial distribution + * \param [in] n + * \param [in] p + * \returns \f$\mu=np\f$ + */ +double binomial_expected(double n, double p) { return n * p; } + +/** finds the variance of the binomial distribution + * \param [in] n + * \param [in] p + * \returns \f$\sigma^2 = n\cdot p\cdot (1-p)\f$ + */ +double binomial_variance(double n, double p) { return n * p * (1 - p); } + +/** finds the standard deviation of the binomial distribution + * \param [in] n + * \param [in] p + * \returns \f$\sigma = \sqrt{\sigma^2} = \sqrt{n\cdot p\cdot (1-p)}\f$ + */ double binomial_standard_deviation(double n, double p) { - return sqrt(binomial_variance(n, p)); + return std::sqrt(binomial_variance(n, p)); } -// Computes n choose r -// n being the trials and r being the desired successes - +/** Computes n choose r + * \param [in] n + * \param [in] r + * \returns \f$\displaystyle {n\choose r} = + * \frac{n!}{r!(n-r)!} = \frac{n\times(n-1)\times(n-2)\times\cdots(n-r)}{r!} + * \f$ + */ double nCr(double n, double r) { double numerator = n; double denominator = r; - for (int i = n - 1 ; i >= ((n - r) + 1); i--) { + for (int i = n - 1; i >= ((n - r) + 1); i--) { numerator *= i; } - for (int i = 1; i < r ; i++) { + for (int i = 1; i < r; i++) { denominator *= i; } return numerator / denominator; } -// calculates the probability of exactly x successes - +/** calculates the probability of exactly x successes + * \returns \f$\displaystyle P(n,p,x) = {n\choose x} p^x (1-p)^{n-x}\f$ + */ double binomial_x_successes(double n, double p, double x) { - return nCr(n, x) * pow(p, x) * pow(1-p, n-x); + return nCr(n, x) * std::pow(p, x) * std::pow(1 - p, n - x); } -// calculates the probability of a result within a range (inclusive, inclusive) - -double binomial_range_successes( - double n, double p, double lower_bound, double upper_bound) { +/** calculates the probability of a result within a range (inclusive, inclusive) + * \returns \f$\displaystyle \left.P(n,p)\right|_{x_0}^{x_1} = + * \sum_{i=x_0}^{x_1} P(i) + * =\sum_{i=x_0}^{x_1} {n\choose i} p^i (1-p)^{n-i}\f$ + */ +double binomial_range_successes(double n, double p, double lower_bound, + double upper_bound) { double probability = 0; for (int i = lower_bound; i <= upper_bound; i++) { - probability += nCr(n, i) * pow(p, i) * pow(1 - p, n - i); + probability += nCr(n, i) * std::pow(p, i) * std::pow(1 - p, n - i); } return probability; } +/** main function */ int main() { - std::cout << "expected value : " - < +/** + * @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 +#include -// The Poisson distribution counts how many -// events occur over a set time interval -// https://en.wikipedia.org/wiki/Poisson_distribution - -// calculate the events per unit time -// e.g 5 dollars every 2 mins = 5 / 2 = 2.5 - +/** + * poisson rate:\n + * calculate the events per unit time\n + * e.g 5 dollars every 2 mins = 5 / 2 = 2.5 + */ double poisson_rate(double events, double timeframe) { return events / timeframe; } -// calculate the expected value over a time -// e.g rate of 2.5 over 10 mins = 2.5 x 10 = 25 - -double poisson_expected(double rate, double time) { - return rate * time; -} - -// find the factorial of a given number +/** + * calculate the expected value over a time + * e.g rate of 2.5 over 10 mins = 2.5 x 10 = 25 + */ +double poisson_expected(double rate, double time) { return rate * time; } +/** + * Compute factorial of a given number + */ double fact(double x) { double x_fact = x; for (int i = x - 1; i > 0; i--) { @@ -33,14 +39,18 @@ double fact(double x) { return x_fact; } -// find the probability of x successes in a Poisson dist - +/** + * Find the probability of x successes in a Poisson dist. + * \f[p(\mu,x) = \frac{\mu^x e^{-\mu}}{x!}\f] + */ double poisson_x_successes(double expected, double x) { - return (pow(expected, x) * exp(-expected)) / fact(x); + return (std::pow(expected, x) * std::exp(-expected)) / fact(x); } -// probability of a success in range for Poisson dist (inclusive, inclusive) - +/** + * probability of a success in range for Poisson dist (inclusive, inclusive) + * \f[P = \sum_i p(\mu,i)\f] + */ double poisson_range_successes(double expected, double lower, double upper) { double probability = 0; for (int i = lower; i <= upper; i++) { @@ -49,6 +59,9 @@ double poisson_range_successes(double expected, double lower, double upper) { return probability; } +/** + * main function + */ int main() { double rate, expected; rate = poisson_rate(3, 1); @@ -57,10 +70,10 @@ int main() { expected = poisson_expected(rate, 2); std::cout << "Poisson expected : " << expected << std::endl; - std::cout << "Poisson 0 successes : " - < -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++; -} -void remove(int index) -{ - cnt[a[index]]--; - if (cnt[a[index]] == 0) - ans--; -} - -bool mycmp(query x, query y) -{ - if (x.l / bucket_size != y.l / bucket_size) - return x.l / bucket_size < y.l / bucket_size; - return x.r < y.r; -} - -int main() -{ - int n, t, i, j, k = 0; - scanf("%d", &n); - for (i = 0; i < n; i++) - scanf("%d", &a[i]); - bucket_size = ceil(sqrt(n)); - scanf("%d", &t); - for (i = 0; i < t; i++) - { - scanf("%d %d", &q[i].l, &q[i].r); - q[i].l--; - q[i].r--; - q[i].i = i; - } - sort(q, q + t, mycmp); - int left = 0, right = 0; - for (i = 0; i < t; i++) - { - int L = q[i].l, R = q[i].r; - while (left < L) - { - remove(left); - left++; - } - while (left > L) - { - add(left - 1); - left--; - } - while (right <= R) - { - add(right); - right++; - } - while (right > R + 1) - { - remove(right - 1); - right--; - } - bucket[q[i].i] = ans; - } - for (i = 0; i < t; i++) - printf("%d\n", bucket[i]); - return 0; -} diff --git a/range_queries/bit.cpp b/range_queries/bit.cpp index e5e36ed24da..a1878705b44 100644 --- a/range_queries/bit.cpp +++ b/range_queries/bit.cpp @@ -3,66 +3,50 @@ using namespace std; -class Bit -{ +class Bit { int n; vector bit; - inline int offset(int x) - { - return (x & (-x)); - } - - public: + inline int offset(int x) { return (x & (-x)); } - Bit(vector& arr) - { - n = arr.size(); - bit.assign(n + 1, 0); - for (int i = 0; i < n; ++i) - { - update(i, arr[i]); - } + public: + Bit(vector& arr) { + n = arr.size(); + bit.assign(n + 1, 0); + for (int i = 0; i < n; ++i) { + update(i, arr[i]); } - Bit(int x) - { + } + Bit(int x) { n = x; bit.assign(n + 1, 0); } - void update(int id, int val) - { + void update(int id, int val) { // Add val at id id++; - while (id <= n) - { + while (id <= n) { bit[id] += val; id += offset(id); } } - int sum(int id) - { + int sum(int id) { // Get prefix sum upto id. id++; int res = 0; - while (id > 0) - { + while (id > 0) { res += bit[id]; id -= offset(id); } return res; } - int sum_range(int l, int r) - { - return sum(r) - sum(l - 1); - } + int sum_range(int l, int r) { return sum(r) - sum(l - 1); } }; -int main() -{ +int main() { int n = 5; - vector arr = { 1, 2, 3, 4, 5 }; + vector arr = {1, 2, 3, 4, 5}; Bit x(arr); assert(x.sum_range(0, 0) == 1); @@ -72,5 +56,5 @@ int main() assert(x.sum_range(0, 0) == 6); assert(x.sum_range(0, 1) == 8); assert(x.sum_range(0, 2) == 11); - return 0; + return 0; } diff --git a/range_queries/FenwickTree.cpp b/range_queries/fenwicktree.cpp similarity index 70% rename from range_queries/FenwickTree.cpp rename to range_queries/fenwicktree.cpp index a4d1a02de3c..fb7cbaac4f8 100644 --- a/range_queries/FenwickTree.cpp +++ b/range_queries/fenwicktree.cpp @@ -1,4 +1,4 @@ -#include +#include using namespace std; /** @@ -6,43 +6,41 @@ using namespace std; * twos complement works good on this * also using ` x - (x & (x - 1)) ` */ -#define lowbit(x) (x & (-x) ) +#define lowbit(x) (x & (-x)) const int maxn = 1e5 + 7; int tree[maxn] = {0}, - range; // segement of [1...range], notice it must be less than `maxn` + range; // segement of [1...range], notice it must be less than `maxn` void update(int x, int c) { - while(x <= range) { + while (x <= range) { tree[x] += c; x += lowbit(x); } } int query(int x) { int ans = 0; - while(x) { + while (x) { ans += tree[x]; x -= lowbit(x); } return ans; } -int query_segement(int l, int r) { - return query(r) - query(l - 1); -} +int query_segement(int l, int r) { return query(r) - query(l - 1); } int main() { cin >> range; - for(int i = 1; i <= range; i++) { + for (int i = 1; i <= range; i++) { int num; cin >> num; update(i, num); } int q; cin >> q; - while(q--) { + while (q--) { int op; cin >> op; - if(op == 0) { + if (op == 0) { int l, r; cin >> l >> r; cout << query_segement(l, r) << endl; diff --git a/range_queries/mo.cpp b/range_queries/mo.cpp new file mode 100644 index 00000000000..d281ef077ee --- /dev/null +++ b/range_queries/mo.cpp @@ -0,0 +1,64 @@ +#include +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++; +} +void remove(int index) { + cnt[a[index]]--; + if (cnt[a[index]] == 0) + ans--; +} + +bool mycmp(query x, query y) { + if (x.l / bucket_size != y.l / bucket_size) + return x.l / bucket_size < y.l / bucket_size; + return x.r < y.r; +} + +int main() { + int n, t, i, j, k = 0; + scanf("%d", &n); + for (i = 0; i < n; i++) scanf("%d", &a[i]); + bucket_size = ceil(sqrt(n)); + scanf("%d", &t); + for (i = 0; i < t; i++) { + scanf("%d %d", &q[i].l, &q[i].r); + q[i].l--; + q[i].r--; + q[i].i = i; + } + sort(q, q + t, mycmp); + int left = 0, right = 0; + for (i = 0; i < t; i++) { + int L = q[i].l, R = q[i].r; + while (left < L) { + remove(left); + left++; + } + while (left > L) { + add(left - 1); + left--; + } + while (right <= R) { + add(right); + right++; + } + while (right > R + 1) { + remove(right - 1); + right--; + } + bucket[q[i].i] = ans; + } + for (i = 0; i < t; i++) printf("%d\n", bucket[i]); + return 0; +} diff --git a/range_queries/segTree.cpp b/range_queries/segTree.cpp deleted file mode 100644 index ee81453e167..00000000000 --- a/range_queries/segTree.cpp +++ /dev/null @@ -1,92 +0,0 @@ -//#include -#incldue -#define MAX 4000000 -using namespace std; -typedef long long ll; -void ConsTree(ll arr[], ll segtree[], ll low, ll high, ll pos) -{ - if (low == high) - { - segtree[pos] = arr[low]; - return; - } - ll mid = (low + high) / 2; - ConsTree(arr, segtree, low, mid, 2 * pos + 1); - ConsTree(arr, segtree, mid + 1, high, 2 * pos + 2); - segtree[pos] = segtree[2 * pos + 1] + segtree[2 * pos + 2]; -} -ll query(ll segtree[], ll lazy[], ll qlow, ll qhigh, ll low, ll high, ll pos) -{ - if (low > high) - return 0; - if (qlow > high || qhigh < low) - return 0; - if (lazy[pos] != 0) - { - segtree[pos] += lazy[pos] * (high - low + 1); - if (low != high) - { - lazy[2 * pos + 1] += lazy[pos]; - lazy[2 * pos + 2] += lazy[pos]; - } - lazy[pos] = 0; - } - if (qlow <= low && qhigh >= high) - return segtree[pos]; - ll mid = (low + high) / 2; - return query(segtree, lazy, qlow, qhigh, low, mid, 2 * pos + 1) + query(segtree, lazy, qlow, qhigh, mid + 1, high, 2 * pos + 2); -} -void update(ll segtree[], ll lazy[], ll start, ll end, ll delta, ll low, ll high, ll pos) -{ - if (low > high) - return; - if (lazy[pos] != 0) - { - segtree[pos] += lazy[pos] * (high - low + 1); - if (low != high) - { - lazy[2 * pos + 1] += lazy[pos]; - lazy[2 * pos + 2] += lazy[pos]; - } - lazy[pos] = 0; - } - if (start > high || end < low) - return; - if (start <= low && end >= high) - { - segtree[pos] += delta * (high - low + 1); - if (low != high) - { - lazy[2 * pos + 1] += delta; - lazy[2 * pos + 2] += delta; - } - return; - } - ll mid = (low + high) / 2; - update(segtree, lazy, start, end, delta, low, mid, 2 * pos + 1); - update(segtree, lazy, start, end, delta, mid + 1, high, 2 * pos + 2); - segtree[pos] = segtree[2 * pos + 1] + segtree[2 * pos + 2]; -} -int main() -{ - ll n, c; - scanf("%lld %lld", &n, &c); - ll arr[n] = {0}, p, q, v, choice; - ll segtree[MAX], lazy[MAX] = {0}; - ConsTree(arr, segtree, 0, n - 1, 0); - while (c--) - { - scanf("%lld", &choice); - if (choice == 0) - { - scanf("%lld %lld %lld", &p, &q, &v); - update(segtree, lazy, p - 1, q - 1, v, 0, n - 1, 0); - } - else - { - scanf("%lld %lld", &p, &q); - printf("%lld\n", query(segtree, lazy, p - 1, q - 1, 0, n - 1, 0)); - } - } - return 0; -} diff --git a/range_queries/segtree.cpp b/range_queries/segtree.cpp new file mode 100644 index 00000000000..602b3fd9567 --- /dev/null +++ b/range_queries/segtree.cpp @@ -0,0 +1,79 @@ +//#include +#incldue < iostream > +#define MAX 4000000 +using namespace std; +typedef long long ll; +void ConsTree(ll arr[], ll segtree[], ll low, ll high, ll pos) { + if (low == high) { + segtree[pos] = arr[low]; + return; + } + ll mid = (low + high) / 2; + ConsTree(arr, segtree, low, mid, 2 * pos + 1); + ConsTree(arr, segtree, mid + 1, high, 2 * pos + 2); + segtree[pos] = segtree[2 * pos + 1] + segtree[2 * pos + 2]; +} +ll query(ll segtree[], ll lazy[], ll qlow, ll qhigh, ll low, ll high, ll pos) { + if (low > high) + return 0; + if (qlow > high || qhigh < low) + return 0; + if (lazy[pos] != 0) { + segtree[pos] += lazy[pos] * (high - low + 1); + if (low != high) { + lazy[2 * pos + 1] += lazy[pos]; + lazy[2 * pos + 2] += lazy[pos]; + } + lazy[pos] = 0; + } + if (qlow <= low && qhigh >= high) + return segtree[pos]; + ll mid = (low + high) / 2; + return query(segtree, lazy, qlow, qhigh, low, mid, 2 * pos + 1) + + query(segtree, lazy, qlow, qhigh, mid + 1, high, 2 * pos + 2); +} +void update(ll segtree[], ll lazy[], ll start, ll end, ll delta, ll low, + ll high, ll pos) { + if (low > high) + return; + if (lazy[pos] != 0) { + segtree[pos] += lazy[pos] * (high - low + 1); + if (low != high) { + lazy[2 * pos + 1] += lazy[pos]; + lazy[2 * pos + 2] += lazy[pos]; + } + lazy[pos] = 0; + } + if (start > high || end < low) + return; + if (start <= low && end >= high) { + segtree[pos] += delta * (high - low + 1); + if (low != high) { + lazy[2 * pos + 1] += delta; + lazy[2 * pos + 2] += delta; + } + return; + } + ll mid = (low + high) / 2; + update(segtree, lazy, start, end, delta, low, mid, 2 * pos + 1); + update(segtree, lazy, start, end, delta, mid + 1, high, 2 * pos + 2); + segtree[pos] = segtree[2 * pos + 1] + segtree[2 * pos + 2]; +} +int main() { + ll n, c; + scanf("%lld %lld", &n, &c); + ll arr[n] = {0}, p, q, v, choice; + ll segtree[MAX], lazy[MAX] = {0}; + ConsTree(arr, segtree, 0, n - 1, 0); + while (c--) { + scanf("%lld", &choice); + if (choice == 0) { + scanf("%lld %lld %lld", &p, &q, &v); + update(segtree, lazy, p - 1, q - 1, v, 0, n - 1, 0); + } else { + scanf("%lld %lld", &p, &q); + printf("%lld\n", query(segtree, lazy, p - 1, q - 1, 0, n - 1, 0)); + } + } + return 0; +} diff --git a/search/CMakeLists.txt b/search/CMakeLists.txt new file mode 100644 index 00000000000..5fd1ae59113 --- /dev/null +++ b/search/CMakeLists.txt @@ -0,0 +1,18 @@ +# If necessary, use the RELATIVE flag, otherwise each source file may be listed +# with full pathname. RELATIVE may makes it easier to extract an executable name +# automatically. +file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) +# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) +foreach( testsourcefile ${APP_SOURCES} ) + # I used a simple string replace, to cut off .cpp. + string( REPLACE ".cpp" "" testname ${testsourcefile} ) + add_executable( ${testname} ${testsourcefile} ) + + set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) + if(OpenMP_CXX_FOUND) + target_link_libraries(${testname} OpenMP::OpenMP_CXX) + endif() + install(TARGETS ${testname} DESTINATION "bin/search") + +endforeach( testsourcefile ${APP_SOURCES} ) diff --git a/search/Interpolation Search.cpp b/search/Interpolation Search.cpp deleted file mode 100644 index f52ce4f4fb1..00000000000 --- a/search/Interpolation Search.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -int InterpolationSearch(int A[], int n, int x) -{ - int low = 0; - int high = n - 1; - while (low <= high) - { - int mid = low + (((high - 1) * (x - A[low])) / (A[high] - A[low])); - if (x == A[mid]) - return mid; // Found x, return (exit) - else if (x < A[mid]) - high = mid - 1; // X lies before mid - else - low = mid + 1; // x lies after mid - } - return -1; -} - -int main() -{ - int A[] = {2, 4, 5, 7, 13, 14, 15, 23}; - int x = 17; - int index = InterpolationSearch(A, 8, x); // passed array A inside the InterpolationSearch function - if (index != -1) - std::cout << "Number " << x << " is at " << index; - else - std::cout << "Number " << x << " not found"; -} - -// randomly set x bcoz array was defined by us , therefore not reasonable for asking input. -// We could have asked for input if array elements were inputed by the user. diff --git a/search/Linear Search.cpp b/search/Linear Search.cpp deleted file mode 100644 index 97e82043712..00000000000 --- a/search/Linear Search.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -using namespace std; - -int LinearSearch(int *array, int size, int key) -{ - for (int i = 0; i < size; ++i) - { - if (array[i] == key) - { - return i; - } - } - - return -1; -} - -int main() -{ - int size; - cout << "\nEnter the size of the Array : "; - cin >> size; - - int array[size]; - int key; - - //Input array - cout << "\nEnter the Array of " << size << " numbers : "; - for (int i = 0; i < size; i++) - { - cin >> array[i]; - } - - cout << "\nEnter the number to be searched : "; - cin >> key; - - int index = LinearSearch(array, size, key); - if (index != -1) - { - cout << "\nNumber found at index : " << index; - } - else - { - cout << "\nNot found"; - } - - return 0; -} diff --git a/search/binary_search.cpp b/search/binary_search.cpp index 9933c98166e..66da31d7fca 100644 --- a/search/binary_search.cpp +++ b/search/binary_search.cpp @@ -1,34 +1,56 @@ +/** + * @file + * @brief [Binary search + * algorithm](https://en.wikipedia.org/wiki/Binary_search_algorithm) + */ #include -// binary_search function -int binary_search(int a[], int l, int r, int key) { + +/** binary_search function + * \param [in] a array to sort + * \param [in] r right hand limit = \f$n-1\f$ + * \param [in] key value to find + * \returns index if T is found + * \return -1 if T is not found + */ +int binary_search(int a[], int r, int key) { + int l = 0; + while (l <= r) { - int m = l + (r - l) / 2; - if (key == a[m]) - return m; - else if (key < a[m]) - r = m - 1; - else - l = m + 1; - } - return -1; - } + int m = l + (r - l) / 2; + if (key == a[m]) + return m; + else if (key < a[m]) + r = m - 1; + else + l = m + 1; + } + return -1; +} + +/** main function */ int main(int argc, char const* argv[]) { int n, key; std::cout << "Enter size of array: "; std::cin >> n; std::cout << "Enter array elements: "; + int* a = new int[n]; -// this loop use for store value in Array + + // this loop use for store value in Array for (int i = 0; i < n; i++) { std::cin >> a[i]; - } + } + std::cout << "Enter search key: "; std::cin >> key; -// this is use for find value in given array - int res = binary_search(a, 0, n - 1, key); + + // this is use for find value in given array + int res = binary_search(a, n - 1, key); if (res != -1) - std::cout << key << " found at index " << res << std::endl; + std::cout << key << " found at index " << res << std::endl; else - std::cout << key << " not found" << std::endl; + std::cout << key << " not found" << std::endl; + + delete[] a; return 0; } diff --git a/search/exponential_search.cpp b/search/exponential_search.cpp index b8343fa0214..f57cbf96b51 100644 --- a/search/exponential_search.cpp +++ b/search/exponential_search.cpp @@ -1,56 +1,84 @@ -// Copyright 2020 Divide-et-impera-11 -#include +/** + * \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 of the search grows by exponential every time. + * If the key is larger than the last element of array, the start of + * block(block_front) will be equal to the end of block(block_size) and the + * algorithm return null ponter, every other cases the algoritm return fom the + * loop. + */ +#include +#include #include -#include -using namespaces std; -// Binary Search Algorithm(use by struzik algorithm) -// Time Complexity O(log n) where 'n' is the number of elements -// Worst Time Complexity O(log n) -// Best Time Complexity Ω(1) -// Space Complexity O(1) -// Auxiliary Space Complexity O(1) -template inline Type* binary_s(Type *array, size_t size, Type key) { -int32_t lower_index(0), upper_index(size - 1), middle_index; -while (lower_index <= upper_index) { - middle_index = floor((lower_index + upper_index) / 2); - if (*(array + middle_index) < key) lower_index = (middle_index + 1); - else if (*(array + middle_index) > key)upper_index = (middle_index - 1); - else return (array + middle_index); - } -return nullptr; +#ifdef _MSC_VER +#include // use for MS Visual C++ +#else +#include // for all other compilers +#endif + +/** Binary Search Algorithm (used by ::struzik_search)\n + * * Time Complexity O(log n) where 'n' is the number of elements + * * Worst Time Complexity O(log n) + * * Best Time Complexity Ω(1) + * * Space Complexity O(1) + * * Auxiliary Space Complexity O(1) + * \returns pointer to value in the array + * \returns `nullptr` if value not found + */ +template +inline Type* binary_s(Type* array, size_t size, Type key) { + int32_t lower_index(0), upper_index(size - 1), middle_index; + + while (lower_index <= upper_index) { + middle_index = std::floor((lower_index + upper_index) / 2); + + if (*(array + middle_index) < key) + lower_index = (middle_index + 1); + else if (*(array + middle_index) > key) + upper_index = (middle_index - 1); + else + return (array + middle_index); + } + + return nullptr; } -// Struzik Search Algorithm(Exponential) -// Time Complexity O(log i)where i is the position of search key in the list -// Worst Time Complexity O(log i) -// Best Time Complexity Ω(1) -// Space Complexity O(1) -// Auxiliary Space Complexity O(1) -/* Tha algorithm try to search the range where the key should be. -If it has been found we do a binary search there. -The range of the search grows by exponential every time. -If the key is larger than the last element of array, -the start of block(block_front) will be equal to the end of block(block_size) -and the algorithm return null ponter, -every other cases the algoritm return fom the loop. */ -template Type* struzik_search(Type* array, size_t size, Type key) { - uint32_t block_front(0), block_size = size == 0 ? 0 : 1; - while (block_front != block_size) { + +/** Struzik Search Algorithm(Exponential) + * * Time Complexity O(log i) where i is the position of search key in the list + * * Worst Time Complexity O(log i) + * * Best Time Complexity Ω(1) + * * Space Complexity O(1) + * * Auxiliary Space Complexity O(1) + */ +template +Type* struzik_search(Type* array, size_t size, Type key) { + uint32_t block_front(0), block_size = size == 0 ? 0 : 1; + while (block_front != block_size) { if (*(array + block_size - 1) < key) { - block_front = block_size; - (block_size * 2 - 1 < size) ? (block_size *= 2) : block_size = size; - continue; + block_front = block_size; + (block_size * 2 - 1 < size) ? (block_size *= 2) : block_size = size; + continue; } - return binary_s(array + block_front, (block_size - block_front), key); - } -return nullptr; + return binary_s(array + block_front, (block_size - block_front), + key); + } + return nullptr; } + +/** Main function */ int main() { -// TEST CASES -int *sorted_array = new int[7]{7, 10, 15, 23, 70, 105, 203}; -assert(struzik_search(sorted_array, 7, 0) == nullptr); -assert(struzik_search(sorted_array, 7, 1000) == nullptr); -assert(struzik_search(sorted_array, 7, 50) == nullptr); -assert(struzik_search(sorted_array, 7, 7) == sorted_array); -// TEST CASES -return 0; + // TEST CASES + int* sorted_array = new int[7]{7, 10, 15, 23, 70, 105, 203}; + assert(struzik_search(sorted_array, 7, 0) == nullptr); + assert(struzik_search(sorted_array, 7, 1000) == nullptr); + assert(struzik_search(sorted_array, 7, 50) == nullptr); + assert(struzik_search(sorted_array, 7, 7) == sorted_array); + // TEST CASES + delete[] sorted_array; + return 0; } diff --git a/search/hash_search.cpp b/search/hash_search.cpp index 94d87b58aaa..6e4caffc30e 100644 --- a/search/hash_search.cpp +++ b/search/hash_search.cpp @@ -1,100 +1,139 @@ -// Copyright 2020 Arctic2333 -#include -#include -#define MAX 6 // Determines how much data -# define HASHMAX 5 // Determines the length of the hash table /** - * Hash Search Algorithm - * Best Time Complexity Ω(1) - * 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, that is, we link a chain list after the data, - * and store all the records whose keywords are synonyms in the same linear chain list. */ -int data[MAX] = { 1, 10, 15, 5, 8, 7}; // test data + * \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, that is, we link a chain list after the data, and store all the + * records whose keywords are synonyms in the same linear chain list. + * + * @warning This program is only for educational purposes. It has serious flaws + * in implementation with regards to memory management resulting in large + * amounts of memory leaks. + * @todo fix the program for memory leaks and better structure in C++ and not C + * fashion + */ +#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; - struct list * next; -} -node, * link; -node hashtab[HASHMAX]; -int counter = 1; -/* int h(int key) + int key; //!< key value for node + struct list* next; //!< pointer to next link in the chain +} node, /**< define node as one item list */ + *link; ///< pointer to nodes + +node hashtab[HASHMAX]; ///< array of nodes + +// int counter = 1; + +/** * Mode of hash detection : - * Division method */ -int h(int key) { - return key % HASHMAX; -} -/* void create_list(int key) + * Division method + * \param [in] key to hash + * \returns hash value for `key` + */ +int h(int key) { return key % HASHMAX; } + +/** * The same after the remainder will be added after the same hash header * To avoid conflict, zipper method is used - * Insert elements into the linked list in the header */ + * Insert elements into the linked list in the header + * \param [in] key key to add to list + * \warning dynamic memory allocated to `n` never gets freed. + * \todo fix memory leak + */ void create_list(int key) { // Construct hash table link p, n; int index; - n = (link) malloc(sizeof(node)); - n -> key = key; - n -> next = NULL; + n = (link)malloc(sizeof(node)); + n->key = key; + n->next = NULL; index = h(key); p = hashtab[index].next; if (p != NULL) { - n -> next = p; + n->next = p; hashtab[index].next = n; } else { - hashtab[index].next = n; } + hashtab[index].next = n; + } } -/* int hash_search(int key) - * Input the key to be searched, and get the hash header position through the H (int key) function, - * then one-dimensional linear search. - * If found @return element depth and number of searches - * If not found @return -1 */ -int hash_search(int key) { // Hash lookup function + +/** + * Input the key to be searched, and get the hash header position through the H + * (int key) function, then one-dimensional linear search. If found @return + * element depth and number of searches If not found @return -1 + */ +int hash_search(int key, int* counter) { // Hash lookup function link pointer; int index; - counter = 0; + + *counter = 0; index = h(key); pointer = hashtab[index].next; - printf("data[%d]:", index); + + std::cout << "data[" << index << "]:"; + while (pointer != NULL) { - counter++; - printf("data[%d]:", pointer -> key); - if (pointer -> key == key) + counter[0]++; + std::cout << "data[" << pointer->key << "]:"; + if (pointer->key == key) return 1; else - pointer = pointer -> next; + pointer = pointer->next; } + return 0; } + +/** main function */ int main() { link p; - int key, index, i; // Key is the value to be found + int key, index, i, counter; // Key is the value to be found index = 0; + // You can write the input mode here while (index < MAX) { // Construct hash table create_list(data[index]); index++; } + for (i = 0; i < HASHMAX; i++) { // Output hash table - printf("hashtab [%d]", i); - printf("\n"); + std::cout << "hashtab [" << i << "]\n"; + p = hashtab[i].next; + while (p != NULL) { - printf("please int key:"); - if (p -> key > 0) - printf("[%d]", p -> key); - p = p -> next; + std::cout << "please int key:"; + if (p->key > 0) + std::cout << "[" << p->key << "]"; + p = p->next; } - printf("\n"); + std::cout << std::endl; } + while (key != -1) { // You can write the input mode here // test key = 10 key = 10; - if (hash_search(key)) - printf("search time = %d\n", counter); + if (hash_search(key, &counter)) + std::cout << "search time = " << counter << std::endl; else - printf("no found!\n"); + std::cout << "no found!\n"; key = -1; // Exit test - /* The test sample is returned as: data[0]:data[5]:data[15]:data[10]:search time = 3 - * The search is successful. There are 10 in this set of data */ + /* The test sample is returned as: + * data[0]:data[5]:data[15]:data[10]:search time = 3 The search is + * successful. There are 10 in this set of data */ } + return 0; } diff --git a/search/interpolation_search.cpp b/search/interpolation_search.cpp index afa9e7c5091..4339dc3661e 100644 --- a/search/interpolation_search.cpp +++ b/search/interpolation_search.cpp @@ -1,36 +1,61 @@ -#include - -// function to search the value in an array using interpolation search -int search(int arr[], int value, int len) { - int low = 0, high, mid; - high = len-1; - while (arr[low] <= value && arr[high] >= value) { - mid = (low + ((value-arr[low])*(high-low)) / (arr[high]-arr[low])); - if (arr[mid] > value) - high = mid-1; - else if (arr[mid] < value) - low = mid+1; - else - return mid; - } - if (arr[low] == value) - return low; - return 0; +/** + * \file + * \brief [Interpolation + * search](https://en.wikipedia.org/wiki/Interpolation_search) algorithm + */ +#include + +/** function to search the value in an array using interpolation search + * \param [in] arr array to search in + * \param [in] value value to search for + * \param [in] len length of array + * \returns index where the value is found + * \returns 0 if not found + */ +int interpolation_search(int arr[], int value, int len) { + int low = 0, high, mid; + high = len - 1; + + while (arr[low] <= value && arr[high] >= value) { + mid = (low + + ((value - arr[low]) * (high - low)) / (arr[high] - arr[low])); + if (arr[mid] > value) + high = mid - 1; + else if (arr[mid] < value) + low = mid + 1; + else + return mid; + } + + if (arr[low] == value) + return low; + + return -1; } +/** main function */ int main() { - int n, value, array[100], re; - std::cout << "Enter the size of array(less than 100) : "; - std::cin >> n; - std::cout << "array in ascending (increasing) order : " << std::endl; - for (int i=0; i < n; i++) - std::cin >> array[i]; - std::cout << "Enter the value you want to search : "; - std::cin >> value; - re = search(array, value, n); - if (re == 0) - std::cout << "Entered value is not in the array" << std::endl; - else - std::cout << "The value is at the position " << re << std::endl; - return 0; - } + int n, value, re; + + std::cout << "Enter the size of array(less than 100) : "; + std::cin >> n; + + int *array = new int[n]; + + std::cout << "array in ascending (increasing) order : " << std::endl; + + for (int i = 0; i < n; i++) std::cin >> array[i]; + + std::cout << "Enter the value you want to search : "; + std::cin >> value; + + re = interpolation_search(array, value, n); + + if (re == -1) + std::cout << "Entered value is not in the array" << std::endl; + else + std::cout << "The value is at the position " << re << std::endl; + + delete[] array; + return 0; +} diff --git a/search/interpolation_search2.cpp b/search/interpolation_search2.cpp new file mode 100644 index 00000000000..93fa6cd836e --- /dev/null +++ b/search/interpolation_search2.cpp @@ -0,0 +1,46 @@ +/** + * \file + * \brief [Interpolation + * search](https://en.wikipedia.org/wiki/Interpolation_search) algorithm + */ +#include + +/** function to search the value in an array using interpolation search + * \param [in] arr array to search in + * \param [in] value value to search for + * \param [in] len length of array + * \returns index where the value is found + * \returns -1 if not found + */ +int InterpolationSearch(int A[], int n, int x) { + int low = 0; + int high = n - 1; + while (low <= high) { + int mid = low + (((high - 1) * (x - A[low])) / (A[high] - A[low])); + if (x == A[mid]) + return mid; // Found x, return (exit) + else if (x < A[mid]) + high = mid - 1; // X lies before mid + else + low = mid + 1; // x lies after mid + } + + return -1; +} + +/** main function */ +int main() { + int A[] = {2, 4, 5, 7, 13, 14, 15, 23}; + int x = 17; + + ///< passed array A inside the InterpolationSearch function + int index = InterpolationSearch(A, 8, x); + if (index < 0) + std::cout << "Number " << x << " not found" << std::endl; + else + std::cout << "Number " << x << " is at " << index << std::endl; +} + +// randomly set x bcoz array was defined by us , therefore not reasonable for +// asking input. We could have asked for input if array elements were inputed by +// the user. diff --git a/search/jump_search.cpp b/search/jump_search.cpp index 0ee7e4e001d..f7b100a4e03 100644 --- a/search/jump_search.cpp +++ b/search/jump_search.cpp @@ -1,33 +1,36 @@ -// C++ program to implement Jump Search - -#include -using namespace std; - -int jumpSearch(int arr[], int x, int n) -{ +/** + * \file + * \brief C++ program to implement [Jump + * Search](https://en.wikipedia.org/wiki/Jump_search) + */ +#include +#include +#include + +/** jump search implementation + */ +int jumpSearch(int arr[], int x, int n) { // Finding block size to be jumped - int step = sqrt(n); + int step = std::sqrt(n); // Finding the block where element is // present (if it is present) int prev = 0; - while (arr[min(step, n)-1] < x) - { + while (arr[std::min(step, n) - 1] < x) { prev = step; - step += sqrt(n); + step += std::sqrt(n); if (prev >= n) return -1; } // Doing a linear search for x in block // beginning with prev. - while (arr[prev] < x) - { + while (arr[prev] < x) { prev++; // If we reached next block or end of // array, element is not present. - if (prev == min(step, n)) + if (prev == std::min(step, n)) return -1; } // If element is found @@ -38,10 +41,8 @@ int jumpSearch(int arr[], int x, int n) } // Driver program to test function -int main() -{ - int arr[] = { 0, 1, 1, 2, 3, 5, 8, 13, 21, - 34, 55, 89, 144, 233, 377, 610 }; +int main() { + int arr[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610}; int x = 55; int n = sizeof(arr) / sizeof(arr[0]); @@ -49,6 +50,6 @@ int main() int index = jumpSearch(arr, x, n); // Print the index where 'x' is located - cout << "\nNumber " << x << " is at index " << index; + std::cout << "\nNumber " << x << " is at index " << index; return 0; } diff --git a/search/linear_search.cpp b/search/linear_search.cpp new file mode 100644 index 00000000000..14250695112 --- /dev/null +++ b/search/linear_search.cpp @@ -0,0 +1,53 @@ +/** + * \file + * \brief [Linear search + * algorithm](https://en.wikipedia.org/wiki/Linear_search) + */ +#include + +/** + * Algorithm implementation + * \param [in] array array to search in + * \param [in] size length of array + * \param [in] key key value to search for + * \returns index where the key-value occurs in the array + * \returns -1 if key-value not found + */ +int LinearSearch(int *array, int size, int key) { + for (int i = 0; i < size; ++i) { + if (array[i] == key) { + return i; + } + } + + return -1; +} + +/** main function */ +int main() { + int size; + std::cout << "\nEnter the size of the Array : "; + std::cin >> size; + + int *array = new int[size]; + int key; + + // Input array + std::cout << "\nEnter the Array of " << size << " numbers : "; + for (int i = 0; i < size; i++) { + std::cin >> array[i]; + } + + std::cout << "\nEnter the number to be searched : "; + std::cin >> key; + + int index = LinearSearch(array, size, key); + if (index != -1) { + std::cout << "\nNumber found at index : " << index; + } else { + std::cout << "\nNot found"; + } + + delete[] array; + return 0; +} diff --git a/search/median_search.cpp b/search/median_search.cpp index be95b599f94..7379cad26e9 100644 --- a/search/median_search.cpp +++ b/search/median_search.cpp @@ -1,72 +1,78 @@ -#include -#include -#include -#include -#include -#include -#include -using namespace std; -vectorv; -vectors1; -vectors2; -vectors3; +/** + * \file + * \brief [Median search](https://en.wikipedia.org/wiki/Median_search) algorithm + * \warning This core is erroneous and gives invorrect answers. Tested using + * cases from [here](https://brilliant.org/wiki/median-finding-algorithm/) + * \ingroup median search + * \{ + */ +#include +#include +#include + +/** + * @todo add documentation + */ template -void comp(X x) -{ - if(s1.size()>=x && s1.size()+s2.size()x) - { - sort(s1.begin(),s1.end()); - cout<x) - { - sort(s3.begin(),s3.end()); - cout< *s1, std::vector *s2, + std::vector *s3) { + if (s1->size() >= x && s1->size() + s2->size() < x) { + std::cout << (*s2)[0] << " is the " << x + 1 << "th element from front"; + } else if (s1->size() > x) { + std::sort(s1->begin(), s1->end()); + std::cout << (*s1)[x] << " is the " << x + 1 << "th element from front"; + } else if (s1->size() + s2->size() <= x && s3->size() > x) { + std::sort(s3->begin(), s3->end()); + std::cout << (*s3)[x - s1->size() - s2->size()] << " is the " << x + 1 + << "th element from front"; + } else { + std::cout << x + 1 << " is invalid location"; } } -int main() -{ - for(int i=0;i<1000;i++) - { - v.push_back(rand()%1000); - } - for(int r:v) - { - cout<>x; - comp(x-1); + std::cout << "enter the no. to be searched form begining:- "; + std::cin >> x; + comp(x - 1, &s1, &s2, &s3); + return 0; } +/// } diff --git a/search/searching.cpp b/search/searching.cpp deleted file mode 100644 index 6a9dcac7dd9..00000000000 --- a/search/searching.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include - -using namespace std; -char paragraph; - -int main() -{ - string paragraph; - cout << "Please enter your paragraph: \n"; - getline(cin, paragraph); - cout << "\nHello, your paragraph is:\n " << paragraph << "!\n"; - cout << "\nThe size of your paragraph = " << paragraph.size() << " characters. \n\n"; - - if (paragraph.empty()) - { - cout << "\nThe paragraph is empty" << endl; - } - else - { - while (true) - { - string word; - cout << "Please enter the word you are searching for: "; - getline(cin, word); - cout << "Hello, your word is " << word << "!\n"; - if (paragraph.find(word) == string::npos) - { - cout << word << " does not exist in the sentence" << endl; - } - else - { - cout << "The word " << word << " is now found at location " << paragraph.find(word) << endl - << endl; - } - system("pause"); - } - } -} diff --git a/search/ternary_search.cpp b/search/ternary_search.cpp index 4cb8d19d996..73b89da7a2a 100644 --- a/search/ternary_search.cpp +++ b/search/ternary_search.cpp @@ -1,128 +1,140 @@ -/* +/** + * \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. - * - * Time Complexity : O(log3 n) - * Space Complexity : O(1) (without the array) + * + * * Time Complexity : O(log3 n) + * * Space Complexity : O(1) (without the array) */ #include -using namespace std; -/* - * The absolutePrecision can be modified to fit preference but +/** + * The absolutePrecision can be modified to fit preference but * it is recommended to not go lower than 10 due to errors that * may occur. - * + */ +#define absolutePrecision 10 +/** * The value of _target should be decided or can be decided later * by using the variable of the function. */ - #define _target 10 -#define absolutePrecision 10 -#define MAX 10000000 -int N = 21; -int A[MAX] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 10}; +#define MAX 10000000 ///< Maximum length of array -/* +/** * get_input function is to receive input from standard IO + * @todo @christianbender Get input from STDIO or write input to memory as done + * above. */ -void get_input() -{ - // TODO: Get input from STDIO or write input to memory as done above. -} - -/* - * This is the iterative method of the ternary search which returns the index of the element. +void get_input() {} + +/** + * This is the iterative method of the ternary search which returns the index of + * the element. + * \param[in] left lower interval limit + * \param[in] right upper interval limit + * \param[in] A array to search in + * \param[in] target value to search for + * \returns index where the target value was found + * \returns -1 if target value not found */ -int it_ternary_search(int left, int right, int A[], int target) -{ - while (1) - { - if (left < right) - { - if (right - left < absolutePrecision) - { - for (int i = left; i <= right; i++) - if (A[i] == target) - return i; - - return -1; - } - - int oneThird = (left + right) / 3 + 1; - int twoThird = (left + right) * 2 / 3 + 1; - - if (A[oneThird] == target) - return oneThird; - else if (A[twoThird] == target) - return twoThird; - - else if (target > A[twoThird]) - left = twoThird + 1; - else if (target < A[oneThird]) - right = oneThird - 1; - - else - left = oneThird + 1, right = twoThird - 1; +int it_ternary_search(int left, int right, int A[], int target) { + while (1) { + if (left < right) { + if (right - left < absolutePrecision) { + for (int i = left; i <= right; i++) + if (A[i] == target) + return i; + + return -1; + } + + int oneThird = (left + right) / 3 + 1; + int twoThird = (left + right) * 2 / 3 + 1; + + if (A[oneThird] == target) + return oneThird; + else if (A[twoThird] == target) + return twoThird; + + else if (target > A[twoThird]) + left = twoThird + 1; + else if (target < A[oneThird]) + right = oneThird - 1; + + else + left = oneThird + 1, right = twoThird - 1; + } else { + return -1; + } } - else - return -1; - } } -/* - * This is the recursive method of the ternary search which returns the index of the element. +/** + * This is the recursive method of the ternary search which returns the index of + * the element. + * \param[in] left lower interval limit + * \param[in] right upper interval limit + * \param[in] A array to search in + * \param[in] target value to search for + * \returns index where the target value was found + * \returns -1 if target value not found */ -int rec_ternary_search(int left, int right, int A[], int target) -{ - if (left < right) - { - if (right - left < absolutePrecision) - { - for (int i = left; i <= right; i++) - if (A[i] == target) - return i; - - return -1; +int rec_ternary_search(int left, int right, int A[], int target) { + if (left < right) { + if (right - left < absolutePrecision) { + for (int i = left; i <= right; i++) + if (A[i] == target) + return i; + + return -1; + } + + int oneThird = (left + right) / 3 + 1; + int twoThird = (left + right) * 2 / 3 + 1; + + if (A[oneThird] == target) + return oneThird; + if (A[twoThird] == target) + return twoThird; + + if (target < A[oneThird]) + return rec_ternary_search(left, oneThird - 1, A, target); + if (target > A[twoThird]) + return rec_ternary_search(twoThird + 1, right, A, target); + + return rec_ternary_search(oneThird + 1, twoThird - 1, A, target); + } else { + return -1; } - - int oneThird = (left + right) / 3 + 1; - int twoThird = (left + right) * 2 / 3 + 1; - - if (A[oneThird] == target) - return oneThird; - if (A[twoThird] == target) - return twoThird; - - if (target < A[oneThird]) - return rec_ternary_search(left, oneThird - 1, A, target); - if (target > A[twoThird]) - return rec_ternary_search(twoThird + 1, right, A, target); - - return rec_ternary_search(oneThird + 1, twoThird - 1, A, target); - } - else - return -1; } -/* +/** * ternary_search is a template function - * You could either use it_ternary_search or rec_ternary_search according to preference. + * You could either use it_ternary_search or rec_ternary_search according to + * preference. + * \param [in] N length of array + * \param[in] A array to search in + * \param[in] target value to search for */ -void ternary_search(int N, int A[], int target) -{ - cout << it_ternary_search(0, N - 1, A, target) << '\t'; - cout << rec_ternary_search(0, N - 1, A, target) << '\t'; - cout << '\n'; +void ternary_search(int N, int A[], int target) { + std::cout << it_ternary_search(0, N - 1, A, target) << '\t'; + std::cout << rec_ternary_search(0, N - 1, A, target) << '\t'; + std::cout << std::endl; } -int main() -{ - get_input(); - ternary_search(N, A, _target); - return 0; +/** Main function */ +int main() { + int N = 21; + int A[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 10}; + get_input(); + ternary_search(N, A, _target); + return 0; } diff --git a/search/text_search.cpp b/search/text_search.cpp new file mode 100644 index 00000000000..ee66a506a8a --- /dev/null +++ b/search/text_search.cpp @@ -0,0 +1,42 @@ +/** + * \file + * \brief Search for words in a long textual paragraph. + */ +#include +#include +#ifdef _MSC_VER +#include // required for MS Visual C++ +#else +#include +#endif + +/** Main function + */ +int main() { + std::string paragraph; + std::cout << "Please enter your paragraph: \n"; + std::getline(std::cin, paragraph); + std::cout << "\nHello, your paragraph is:\n " << paragraph << "!\n"; + std::cout << "\nThe size of your paragraph = " << paragraph.size() + << " characters. \n\n"; + + if (paragraph.empty()) { + std::cout << "\nThe paragraph is empty" << std::endl; + } else { + while (true) { + std::string word; + std::cout << "Please enter the word you are searching for: "; + std::getline(std::cin, word); + std::cout << "Hello, your word is " << word << "!\n"; + if (paragraph.find(word) == std::string::npos) { + std::cout << word << " does not exist in the sentence" + << std::endl; + } else { + std::cout << "The word " << word << " is now found at location " + << paragraph.find(word) << std::endl + << std::endl; + } + std::cin.get(); + } + } +} diff --git a/sorting/BeadSort.cpp b/sorting/BeadSort.cpp deleted file mode 100644 index c8e27b2507e..00000000000 --- a/sorting/BeadSort.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// C++ program to implement gravity/bead sort -#include -#include -using namespace std; - -#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++) - if (a[i] > max) - max = a[i]; - - // allocating memory - unsigned char beads[max*len]; - memset(beads, 0, sizeof(beads)); - - // mark the beads - for (int i = 0; i < len; i++) - for (int j = 0; j < a[i]; j++) - BEAD(i, j) = 1; - - for (int j = 0; j < max; j++) - { - // count how many beads are on each post - int sum = 0; - for (int i=0; i < len; i++) - { - sum += BEAD(i, j); - BEAD(i, j) = 0; - } - - // Move beads down - for (int i = len - sum; i < len; i++) - BEAD(i, j) = 1; - } - - // Put sorted values in array using beads - for (int i = 0; i < len; i++) - { - int j; - for (j = 0; j < max && BEAD(i, j); j++); - - a[i] = j; - } -} - -// driver function to test the algorithm -int main() -{ - int a[] = {5, 3, 1, 7, 4, 1, 1, 20}; - int len = sizeof(a)/sizeof(a[0]); - - beadSort(a, len); - - for (int i = 0; i < len; i++) - printf("%d ", a[i]); - - return 0; -} diff --git a/sorting/BitonicSort.cpp b/sorting/BitonicSort.cpp deleted file mode 100644 index 6ad2489d229..00000000000 --- a/sorting/BitonicSort.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// 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 -#include -using namespace std; - -/*The parameter dir indicates the sorting direction, ASCENDING - or DESCENDING; if (a[i] > a[j]) agrees with the direction, - then a[i] and a[j] are interchanged.*/ -void compAndSwap(int a[], int i, int j, int dir) -{ - if (dir == (a[i] > a[j])) - swap(a[i], a[j]); -} - -/*It recursively sorts a bitonic sequence in ascending order, - if dir = 1, and in descending order otherwise (means dir=0). - The sequence to be sorted starts at index position low, - the parameter cnt is the number of elements to be sorted.*/ -void bitonicMerge(int a[], int low, int cnt, int dir) -{ - if (cnt > 1) - { - int k = cnt / 2; - for (int i = low; i < low + k; i++) - compAndSwap(a, i, i + k, dir); - bitonicMerge(a, low, k, dir); - bitonicMerge(a, low + k, k, dir); - } -} - -/* This function first produces a bitonic sequence by recursively - sorting its two halves in opposite sorting orders, and then - calls bitonicMerge to make them in the same order */ -void bitonicSort(int a[], int low, int cnt, int dir) -{ - if (cnt > 1) - { - int k = cnt / 2; - - // sort in ascending order since dir here is 1 - bitonicSort(a, low, k, 1); - - // sort in descending order since dir here is 0 - bitonicSort(a, low + k, k, 0); - - // Will merge wole sequence in ascending order - // since dir=1. - bitonicMerge(a, low, cnt, dir); - } -} - -/* Caller of bitonicSort for sorting the entire array of - length N in ASCENDING order */ -void sort(int a[], int N, int up) -{ - bitonicSort(a, 0, N, up); -} - -// Driver code -int main() -{ - int a[] = {3, 7, 4, 8, 6, 2, 1, 5}; - int N = sizeof(a) / sizeof(a[0]); - - int up = 1; // means sort in ascending order - sort(a, N, up); - - printf("Sorted array: \n"); - for (int i = 0; i < N; i++) - printf("%d ", a[i]); - return 0; -} diff --git a/sorting/Bubble Sort.cpp b/sorting/Bubble Sort.cpp deleted file mode 100644 index b160ac4790a..00000000000 --- a/sorting/Bubble Sort.cpp +++ /dev/null @@ -1,83 +0,0 @@ -//Bubble Sort - -#include -#include -using namespace std; - -int main() -{ - int n; - short swap_check = 1; - cout << "Enter the amount of numbers to sort: "; - cin >> n; - vector numbers; - cout << "Enter " << n << " numbers: "; - int num; - - //Input - for (int i = 0; i < n; i++) - { - cin >> num; - numbers.push_back(num); - } - - //Bubble Sorting - for (int i = 0; (i < n) && (swap_check == 1); i++) - { - swap_check = 0; - for (int j = 0; j < n - 1 - i; j++) - { - if (numbers[j] > numbers[j + 1]) - { - swap_check = 1; - swap(numbers[j], numbers[j + 1]);// by changing swap location. I mean, j. If the number is greater than j + 1, then it means the location. - } - } - } - - //Output - cout << "\nSorted Array : "; - for (int i = 0; i < numbers.size(); i++) - { - if (i != numbers.size() - 1) - { - cout << numbers[i] << ", "; - } - else - { - cout << numbers[i] << endl; - } - } - return 0; -} - -/*The working principle of the Bubble sort algorithm: - -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, the largest number is expired and when iterations are completed, the sorting takes place. - -What is Swap? - -Swap in the software means that two variables are displaced. -An additional variable is required for this operation. x = 5, y = 10. -We want x = 10, y = 5. Here we create the most variable to do it. - -int z; -z = x; -x = y; -y = z; - -The above process is a typical displacement process. -When x assigns the value to x, the old value of x is lost. -That's why we created a variable z to create the first value of the value of x, and finally, we have assigned to y. - -Bubble Sort Algorithm Analysis (Best Case - Worst Case - Average Case) - -Bubble Sort Worst Case Performance is O (n²). Why is that? Because if you remember Big O Notation, we were calculating the complexity of the algorithms in the nested loops. -The n * (n - 1) product gives us O (n²) performance. In the worst case all the steps of the cycle will occur. -Bubble Sort (Avarage Case) Performance. Bubble Sort is not an optimal algorithm. -in average, O (n²) performance is taken. -Bubble Sort Best Case Performance. O (n). -However, you 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. -* / diff --git a/sorting/CMakeLists.txt b/sorting/CMakeLists.txt new file mode 100644 index 00000000000..00877bb613a --- /dev/null +++ b/sorting/CMakeLists.txt @@ -0,0 +1,20 @@ +# If necessary, use the RELATIVE flag, otherwise each source file may be listed +# with full pathname. RELATIVE may makes it easier to extract an executable name +# automatically. +file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) +# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) +foreach( testsourcefile ${APP_SOURCES} ) + # I used a simple string replace, to cut off .cpp. + string( REPLACE ".cpp" "" testname ${testsourcefile} ) + add_executable( ${testname} ${testsourcefile} ) + + set_target_properties(${testname} PROPERTIES + LINKER_LANGUAGE CXX + CXX_STANDARD 14) + if(OpenMP_CXX_FOUND) + target_link_libraries(${testname} OpenMP::OpenMP_CXX) + endif() + install(TARGETS ${testname} DESTINATION "bin/sorting") + +endforeach( testsourcefile ${APP_SOURCES} ) diff --git a/sorting/CocktailSelectionSort.cpp b/sorting/CocktailSelectionSort.cpp deleted file mode 100644 index cac6a361871..00000000000 --- a/sorting/CocktailSelectionSort.cpp +++ /dev/null @@ -1,109 +0,0 @@ -//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 -using namespace std; - -//Iterative Version - -void CocktailSelectionSort(vector &vec, int low, int high) -{ - while (low <= high) - { - int minimum = vec[low]; - int minimumindex = low; - int maximum = vec[high]; - int maximumindex = high; - - for (int i = low; i <= high; i++) - { - if (vec[i] >= maximum) - { - maximum = vec[i]; - maximumindex = i; - } - if (vec[i] <= minimum) - { - minimum = vec[i]; - minimumindex = i; - } - } - if (low != maximumindex || high != minimumindex) - { - swap(vec[low], vec[minimumindex]); - swap(vec[high], vec[maximumindex]); - } - else - { - swap(vec[low], vec[high]); - } - - low++; - high--; - } -} - -//Recursive Version - -void CocktailSelectionSort(vector &vec, int low, int high) -{ - - if (low >= high) - return; - - int minimum = vec[low]; - int minimumindex = low; - int maximum = vec[high]; - int maximumindex = high; - - for (int i = low; i <= high; i++) - { - if (vec[i] >= maximum) - { - maximum = vec[i]; - maximumindex = i; - } - if (vec[i] <= minimum) - { - minimum = vec[i]; - minimumindex = i; - } - } - if (low != maximumindex || high != minimumindex) - { - swap(vec[low], vec[minimumindex]); - swap(vec[high], vec[maximumindex]); - } - else - { - swap(vec[low], vec[high]); - } - - CocktailSelectionSort(vec, low + 1, high - 1); -} - -//main function, select any one of iterative or recursive version - -int main() -{ - - int n; - cout << "Enter number of elements\n"; - cin >> n; - std::vector v(n); - cout << "Enter all the elements\n"; - for (int i = 0; i < n; ++i) - { - cin >> v[i]; - } - - CocktailSelectionSort(v, 0, n - 1); - cout << "Sorted elements are\n"; - for (int i = 0; i < n; ++i) - { - cout << v[i] << " "; - } - - return 0; -} diff --git a/sorting/Counting_Sort.cpp b/sorting/Counting_Sort.cpp deleted file mode 100644 index bda37bbd8ca..00000000000 --- a/sorting/Counting_Sort.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -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++) - if (Arr[i] < min) - min = Arr[i]; - return min; -} - -void Print(int Arr[], int N) -{ - for (int i = 0; i < N; i++) - cout << Arr[i] << ", "; -} - -int *Counting_Sort(int Arr[], int N) -{ - - int max = Max(Arr, N); - int min = Min(Arr, N); - int *Sorted_Arr = new int[N]; - - int *Count = new int[max - min + 1]; - - for (int i = 0; i < N; i++) - Count[Arr[i] - min]++; - - for (int i = 1; i < (max - min + 1); i++) - Count[i] += Count[i - 1]; - - for (int i = N - 1; i >= 0; i--) - { - Sorted_Arr[Count[Arr[i] - min] - 1] = Arr[i]; - Count[Arr[i] - min]--; - } - - return Sorted_Arr; -} - -int main() -{ - - int Arr[] = {47, 65, 20, 66, 25, 53, 64, 69, 72, 22, 74, 25, 53, 15, 42, 36, 4, 69, 86, 19}, N = 20; - int *Sorted_Arr; - - cout << "\n\tOrignal Array = "; - Print(Arr, N); - Sorted_Arr = Counting_Sort(Arr, N); - cout << "\n\t Sorted Array = "; - Print(Sorted_Arr, N); - cout << endl; - - return 0; -} diff --git a/sorting/Insertion Sort.cpp b/sorting/Insertion Sort.cpp deleted file mode 100644 index 2563acaf8f2..00000000000 --- a/sorting/Insertion Sort.cpp +++ /dev/null @@ -1,40 +0,0 @@ -//Insertion Sort - -#include -using namespace std; - -int main() -{ - int n; - cout << "\nEnter the length of your array : "; - cin >> n; - int Array[n]; - cout << "\nEnter any " << n << " Numbers for Unsorted Array : "; - - //Input - for (int i = 0; i < n; i++) - { - cin >> Array[i]; - } - - //Sorting - for (int i = 1; i < n; i++) - { - int temp = Array[i]; - int j = i - 1; - while (j >= 0 && temp < Array[j]) - { - Array[j + 1] = Array[j]; - j--; - } - Array[j + 1] = temp; - } - - //Output - cout << "\nSorted Array : "; - for (int i = 0; i < n; i++) - { - cout << Array[i] << "\t"; - } - return 0; -} diff --git a/sorting/Merge Sort.cpp b/sorting/Merge Sort.cpp deleted file mode 100644 index b8edc8851f4..00000000000 --- a/sorting/Merge Sort.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include -using namespace std; - -void merge(int arr[], int l, int m, int r) -{ - int i, j, k; - int n1 = m - l + 1; - int n2 = r - m; - - int L[n1], R[n2]; - - for (i = 0; i < n1; i++) - L[i] = arr[l + i]; - for (j = 0; j < n2; j++) - R[j] = arr[m + 1 + j]; - - i = 0; - j = 0; - k = l; - while (i < n1 && j < n2) - { - if (L[i] <= R[j]) - { - arr[k] = L[i]; - i++; - } - else - { - arr[k] = R[j]; - j++; - } - k++; - } - - while (i < n1) - { - arr[k] = L[i]; - i++; - k++; - } - - while (j < n2) - { - arr[k] = R[j]; - j++; - k++; - } -} - -void mergeSort(int arr[], int l, int r) -{ - if (l < r) - { - - int m = l + (r - l) / 2; - - mergeSort(arr, l, m); - mergeSort(arr, m + 1, r); - - merge(arr, l, m, r); - } -} - -void show(int A[], int size) -{ - int i; - for (i = 0; i < size; i++) - cout << A[i] << "\n"; -} - -int main() -{ - int size; - cout << "\nEnter the number of elements : "; - - cin >> size; - - int arr[size]; - - cout << "\nEnter the unsorted elements : "; - - for (int i = 0; i < size; ++i) - { - cout << "\n"; - cin >> arr[i]; - } - - mergeSort(arr, 0, size); - - cout << "Sorted array\n"; - show(arr, size); - return 0; -} diff --git a/sorting/NumericStringSort.cpp b/sorting/NumericStringSort.cpp deleted file mode 100644 index 02f6964ba14..00000000000 --- a/sorting/NumericStringSort.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//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, -//even though we know the correct sorting order is 1,2,3,10,20,30,100,200,300 - -//This Programme uses a comparator to sort the array in Numerical order instead of Alphanumeric order - -#include -#include -#include -using namespace std; - -bool NumericSort(string a, string b) -{ - while (a[0] == '0') - { - a.erase(a.begin()); - } - while (b[0] == '0') - { - b.erase(b.begin()); - } - int n = a.length(); - int m = b.length(); - if (n == m) - return a < b; - return n < m; -} - -int main() -{ - - int n; - cout << "Enter number of elements to be sorted Numerically\n"; - cin >> n; - - vector v(n); - cout << "Enter the string of Numbers\n"; - for (int i = 0; i < n; i++) - { - cin >> v[i]; - } - - sort(v.begin(), v.end()); - cout << "Elements sorted normally \n"; - for (int i = 0; i < n; i++) - { - cout << v[i] << " "; - } - cout << "\n"; - - sort(v.begin(), v.end(), NumericSort); - cout << "Elements sorted Numerically \n"; - for (int i = 0; i < n; i++) - { - cout << v[i] << " "; - } - - return 0; -} diff --git a/sorting/OddEven Sort.cpp b/sorting/OddEven Sort.cpp deleted file mode 100644 index 62842c1745a..00000000000 --- a/sorting/OddEven Sort.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* C++ implementation Odd Even Sort */ -#include -#include - -using namespace std; - -void oddEven(vector &arr, int size) -{ - bool sorted = false; - while (!sorted) - { - sorted = true; - for (int i = 1; i < size - 1; i += 2) //Odd - { - if (arr[i] > arr[i + 1]) - { - swap(arr[i], arr[i + 1]); - sorted = false; - } - } - - for (int i = 0; i < size - 1; i += 2) //Even - { - if (arr[i] > arr[i + 1]) - { - swap(arr[i], arr[i + 1]); - sorted = false; - } - } - } -} - -void show(vector A, int size) -{ - int i; - for (i = 0; i < size; i++) - cout << A[i] << "\n"; -} - -int main() -{ - int size, temp; - cout << "\nEnter the number of elements : "; - cin >> size; - - vector arr; - - cout << "\nEnter the unsorted elements : \n"; - - for (int i = 0; i < size; ++i) - { - cin >> temp; - arr.push_back(temp); - } - - oddEven(arr, size); - - cout << "Sorted array\n"; - show(arr, size); - return 0; -} diff --git a/sorting/Radix Sort.cpp b/sorting/Radix Sort.cpp deleted file mode 100644 index 09c91bb2248..00000000000 --- a/sorting/Radix Sort.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include -#include -using namespace std; -void radixsort(int a[], int n) -{ - int count[10]; - int output[n]; - memset(output, 0, sizeof(output)); - memset(count, 0, sizeof(count)); - int max = 0; - for (int i = 0; i < n; ++i) - { - if (a[i] > max) - { - max = a[i]; - } - } - int maxdigits = 0; - while (max) - { - maxdigits++; - max /= 10; - } - for (int j = 0; j < maxdigits; j++) - { - for (int i = 0; i < n; i++) - { - int t = pow(10, j); - count[(a[i] % (10 * t)) / t]++; - } - int k = 0; - for (int p = 0; p < 10; p++) - { - for (int i = 0; i < n; i++) - { - int t = pow(10, j); - if ((a[i] % (10 * t)) / t == p) - { - output[k] = a[i]; - k++; - } - } - } - memset(count, 0, sizeof(count)); - for (int i = 0; i < n; ++i) - { - a[i] = output[i]; - } - } -} -void print(int a[], int n) -{ - for (int i = 0; i < n; ++i) - { - cout << a[i] << " "; - } - cout << endl; -} -int main(int argc, char const *argv[]) -{ - int a[] = {170, 45, 75, 90, 802, 24, 2, 66}; - int n = sizeof(a) / sizeof(a[0]); - radixsort(a, n); - print(a, n); - return 0; -} \ No newline at end of file diff --git a/sorting/Selection Sort.cpp b/sorting/Selection Sort.cpp deleted file mode 100644 index 5b8724141aa..00000000000 --- a/sorting/Selection Sort.cpp +++ /dev/null @@ -1,39 +0,0 @@ -//Selection Sort - -#include -using namespace std; - -int main() -{ - int Array[6]; - cout << "\nEnter any 6 Numbers for Unsorted Array : "; - - //Input - for (int i = 0; i < 6; i++) - { - cin >> Array[i]; - } - - //Selection Sorting - for (int i = 0; i < 6; i++) - { - int min = i; - for (int j = i + 1; j < 6; j++) - { - if (Array[j] < Array[min]) - { - min = j; //Finding the smallest number in Array - } - } - int temp = Array[i]; - Array[i] = Array[min]; - Array[min] = temp; - } - - //Output - cout << "\nSorted Array : "; - for (int i = 0; i < 6; i++) - { - cout << Array[i] << "\t"; - } -} diff --git a/sorting/Shell Sort.cpp b/sorting/Shell Sort.cpp deleted file mode 100644 index b08c7ffd826..00000000000 --- a/sorting/Shell Sort.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -using namespace std; - -int main() -{ - int size = 10; - int array[size]; - // Input - cout << "\nHow many numbers do want to enter in unsorted array : "; - cin >> size; - cout << "\nEnter the numbers for unsorted array : "; - for (int i = 0; i < size; i++) - { - cin >> array[i]; - } - - // Sorting - for (int i = size / 2; i > 0; i = i / 2) - { - for (int j = i; j < size; j++) - { - for (int k = j - i; k >= 0; k = k - i) - { - if (array[k] < array[k + i]) - { - break; - } - else - { - int temp = array[k + i]; - array[k + i] = array[k]; - array[k] = temp; - } - } - } - } - - // Output - cout << "\nSorted array : "; - for (int i = 0; i < size; ++i) - { - cout << array[i] << "\t"; - } - return 0; -} diff --git a/sorting/Slow Sort.cpp b/sorting/Slow Sort.cpp deleted file mode 100644 index f8f7e74b804..00000000000 --- a/sorting/Slow Sort.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//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 Stolfi in their paper Pessimal Algorithms and Simplexity Analysis. -//This algorithm multiplies a single problem into multiple subproblems -//It is interesting because it is provably the least efficient sorting algorithm that can be built asymptotically, -//and with the restriction that such an algorithm, while being slow, must still all the time be working towards a result. - -#include -using namespace std; - -void SlowSort(int a[], int i, int j) -{ - if (i >= j) - return; - int m = i + (j - i) / 2; //midpoint, implemented this way to avoid overflow - int temp; - SlowSort(a, i, m); - SlowSort(a, m + 1, j); - if (a[j] < a[m]) - { - temp = a[j]; //swapping a[j] & a[m] - a[j] = a[m]; - a[m] = temp; - } - SlowSort(a, i, j - 1); -} - -//Sample Main function - -int main() -{ - int size; - cout << "\nEnter the number of elements : "; - - cin >> size; - - int arr[size]; - - cout << "\nEnter the unsorted elements : "; - - for (int i = 0; i < size; ++i) - { - cout << "\n"; - cin >> arr[i]; - } - - SlowSort(arr, 0, size); - - cout << "Sorted array\n"; - - for (int i = 0; i < size; ++i) - { - cout << arr[i] << " "; - } - return 0; -} diff --git a/sorting/bead_sort.cpp b/sorting/bead_sort.cpp new file mode 100644 index 00000000000..f3276bfcd9f --- /dev/null +++ b/sorting/bead_sort.cpp @@ -0,0 +1,56 @@ +// C++ program to implement gravity/bead sort +#include +#include + +#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++) + if (a[i] > max) + max = a[i]; + + // allocating memory + unsigned char *beads = new unsigned char[max * len]; + memset(beads, 0, max * len); + + // mark the beads + for (int i = 0; i < len; i++) + for (int j = 0; j < a[i]; j++) BEAD(i, j) = 1; + + for (int j = 0; j < max; j++) { + // count how many beads are on each post + int sum = 0; + for (int i = 0; i < len; i++) { + sum += BEAD(i, j); + BEAD(i, j) = 0; + } + + // Move beads down + for (int i = len - sum; i < len; i++) BEAD(i, j) = 1; + } + + // Put sorted values in array using beads + for (int i = 0; i < len; i++) { + int j; + for (j = 0; j < max && BEAD(i, j); j++) { + } + + a[i] = j; + } + delete[] beads; +} + +// driver function to test the algorithm +int main() { + int a[] = {5, 3, 1, 7, 4, 1, 1, 20}; + int len = sizeof(a) / sizeof(a[0]); + + beadSort(a, len); + + for (int i = 0; i < len; i++) printf("%d ", a[i]); + + return 0; +} diff --git a/sorting/bitonic_sort.cpp b/sorting/bitonic_sort.cpp new file mode 100644 index 00000000000..0fbb995acfd --- /dev/null +++ b/sorting/bitonic_sort.cpp @@ -0,0 +1,64 @@ +// 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 +#include + +/*The parameter dir indicates the sorting direction, ASCENDING + or DESCENDING; if (a[i] > a[j]) agrees with the direction, + then a[i] and a[j] are interchanged.*/ +void compAndSwap(int a[], int i, int j, int dir) { + if (dir == (a[i] > a[j])) + std::swap(a[i], a[j]); +} + +/*It recursively sorts a bitonic sequence in ascending order, + if dir = 1, and in descending order otherwise (means dir=0). + The sequence to be sorted starts at index position low, + the parameter cnt is the number of elements to be sorted.*/ +void bitonicMerge(int a[], int low, int cnt, int dir) { + if (cnt > 1) { + int k = cnt / 2; + for (int i = low; i < low + k; i++) compAndSwap(a, i, i + k, dir); + bitonicMerge(a, low, k, dir); + bitonicMerge(a, low + k, k, dir); + } +} + +/* This function first produces a bitonic sequence by recursively + sorting its two halves in opposite sorting orders, and then + calls bitonicMerge to make them in the same order */ +void bitonicSort(int a[], int low, int cnt, int dir) { + if (cnt > 1) { + int k = cnt / 2; + + // sort in ascending order since dir here is 1 + bitonicSort(a, low, k, 1); + + // sort in descending order since dir here is 0 + bitonicSort(a, low + k, k, 0); + + // Will merge wole sequence in ascending order + // since dir=1. + bitonicMerge(a, low, cnt, dir); + } +} + +/* Caller of bitonicSort for sorting the entire array of + length N in ASCENDING order */ +void sort(int a[], int N, int up) { bitonicSort(a, 0, N, up); } + +// Driver code +int main() { + int a[] = {3, 7, 4, 8, 6, 2, 1, 5}; + int N = sizeof(a) / sizeof(a[0]); + + int up = 1; // means sort in ascending order + sort(a, N, up); + + std::cout << "Sorted array: \n"; + for (int i = 0; i < N; i++) std::cout << a[i] << " "; + return 0; +} diff --git a/sorting/bubble_sort.cpp b/sorting/bubble_sort.cpp new file mode 100644 index 00000000000..c43e425fcd9 --- /dev/null +++ b/sorting/bubble_sort.cpp @@ -0,0 +1,83 @@ +/** + * @file + * @brief Bubble sort algorithm + * + * The working principle of the Bubble sort algorithm: + +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, the largest number is +expired and when iterations are completed, the sorting takes place. + +What is Swap? + +Swap in the software means that two variables are displaced. +An additional variable is required for this operation. x = 5, y = 10. +We want x = 10, y = 5. Here we create the most variable to do it. + +int z; +z = x; +x = y; +y = z; + +The above process is a typical displacement process. +When x assigns the value to x, the old value of x is lost. +That's why we created a variable z to create the first value of the value of x, +and finally, we have assigned to y. + +Bubble Sort Algorithm Analysis (Best Case - Worst Case - Average Case) + +Bubble Sort Worst Case Performance is O (n²). Why is that? Because if you +remember Big O Notation, we were calculating the complexity of the algorithms in +the nested loops. The n * (n - 1) product gives us O (n²) performance. In the +worst case all the steps of the cycle will occur. Bubble Sort (Avarage Case) +Performance. Bubble Sort is not an optimal algorithm. in average, O (n²) +performance is taken. Bubble Sort Best Case Performance. O (n). However, you +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 + +int main() { + int n; + bool swap_check = true; + std::cout << "Enter the amount of numbers to sort: "; + std::cin >> n; + std::vector numbers; + std::cout << "Enter " << n << " numbers: "; + int num; + + // Input + for (int i = 0; i < n; i++) { + std::cin >> num; + numbers.push_back(num); + } + + // Bubble Sorting + for (int i = 0; (i < n) && (swap_check); i++) { + swap_check = false; + for (int j = 0; j < n - 1 - i; j++) { + if (numbers[j] > numbers[j + 1]) { + swap_check = true; + std::swap(numbers[j], + numbers[j + 1]); // by changing swap location. + // I mean, j. If the number is + // greater than j + 1, then it + // means the location. + } + } + } + + // Output + std::cout << "\nSorted Array : "; + for (int i = 0; i < numbers.size(); i++) { + if (i != numbers.size() - 1) { + std::cout << numbers[i] << ", "; + } else { + std::cout << numbers[i] << std::endl; + } + } + return 0; +} diff --git a/sorting/bucketSort.cpp b/sorting/bucketSort.cpp deleted file mode 100644 index 0ffbf8e4cb7..00000000000 --- a/sorting/bucketSort.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// C++ program to sort an array using bucket sort -#include -#include -#include -using namespace std; - -// Function to sort arr[] of size n using bucket sort -void bucketSort(float arr[], int n) -{ - // 1) Create n empty buckets - vector b[n]; - - // 2) Put array elements in different buckets - for (int i = 0; i < n; i++) - { - int bi = n * arr[i]; // Index in bucket - b[bi].push_back(arr[i]); - } - - // 3) Sort individual buckets - for (int i = 0; i < n; i++) - sort(b[i].begin(), b[i].end()); - - // 4) Concatenate all buckets into arr[] - int index = 0; - for (int i = 0; i < n; i++) - for (int j = 0; j < b[i].size(); j++) - arr[index++] = b[i][j]; -} - -/* Driver program to test above funtion */ -int main() -{ - float arr[] = {0.897, 0.565, 0.656, 0.1234, 0.665, 0.3434}; - int n = sizeof(arr) / sizeof(arr[0]); - bucketSort(arr, n); - - cout << "Sorted array is \n"; - for (int i = 0; i < n; i++) - cout << arr[i] << " "; - return 0; -} diff --git a/sorting/bucket_sort.cpp b/sorting/bucket_sort.cpp new file mode 100644 index 00000000000..c43865281bc --- /dev/null +++ b/sorting/bucket_sort.cpp @@ -0,0 +1,36 @@ +// C++ program to sort an array using bucket sort +#include +#include +#include + +// Function to sort arr[] of size n using bucket sort +void bucketSort(float arr[], int n) { + // 1) Create n empty buckets + std::vector *b = new std::vector[n]; + + // 2) Put array elements in different buckets + for (int i = 0; i < n; i++) { + int bi = n * arr[i]; // Index in bucket + b[bi].push_back(arr[i]); + } + + // 3) Sort individual buckets + for (int i = 0; i < n; i++) std::sort(b[i].begin(), b[i].end()); + + // 4) Concatenate all buckets into arr[] + int index = 0; + for (int i = 0; i < n; i++) + for (int j = 0; j < b[i].size(); j++) arr[index++] = b[i][j]; + delete[] b; +} + +/* Driver program to test above funtion */ +int main() { + float arr[] = {0.897, 0.565, 0.656, 0.1234, 0.665, 0.3434}; + int n = sizeof(arr) / sizeof(arr[0]); + bucketSort(arr, n); + + std::cout << "Sorted array is \n"; + for (int i = 0; i < n; i++) std::cout << arr[i] << " "; + return 0; +} diff --git a/sorting/cocktail_selection_sort.cpp b/sorting/cocktail_selection_sort.cpp new file mode 100644 index 00000000000..157acafcecb --- /dev/null +++ b/sorting/cocktail_selection_sort.cpp @@ -0,0 +1,102 @@ +// 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 +#include +#include + +// Iterative Version + +void CocktailSelectionSort(std::vector *vec, int low, int high) { + while (low <= high) { + int minimum = (*vec)[low]; + int minimumindex = low; + int maximum = (*vec)[high]; + int maximumindex = high; + + for (int i = low; i <= high; i++) { + if ((*vec)[i] >= maximum) { + maximum = (*vec)[i]; + maximumindex = i; + } + if ((*vec)[i] <= minimum) { + minimum = (*vec)[i]; + minimumindex = i; + } + } + if (low != maximumindex || high != minimumindex) { + std::swap((*vec)[low], (*vec)[minimumindex]); + std::swap((*vec)[high], (*vec)[maximumindex]); + } else { + std::swap((*vec)[low], (*vec)[high]); + } + + low++; + high--; + } +} + +// Recursive Version + +void CocktailSelectionSort_v2(std::vector *vec, int low, int high) { + if (low >= high) + return; + + int minimum = (*vec)[low]; + int minimumindex = low; + int maximum = (*vec)[high]; + int maximumindex = high; + + for (int i = low; i <= high; i++) { + if ((*vec)[i] >= maximum) { + maximum = (*vec)[i]; + maximumindex = i; + } + if ((*vec)[i] <= minimum) { + minimum = (*vec)[i]; + minimumindex = i; + } + } + if (low != maximumindex || high != minimumindex) { + std::swap((*vec)[low], (*vec)[minimumindex]); + std::swap((*vec)[high], (*vec)[maximumindex]); + } else { + std::swap((*vec)[low], (*vec)[high]); + } + + CocktailSelectionSort(vec, low + 1, high - 1); +} + +// main function, select any one of iterative or recursive version + +int main() { + int n; + std::cout << "Enter number of elements\n"; + std::cin >> n; + std::vector v(n); + std::cout << "Enter all the elements\n"; + for (int i = 0; i < n; ++i) { + std::cin >> v[i]; + } + + int method; + std::cout << "Enter method: \n\t0: iterative\n\t1: recursive:\t"; + std::cin >> method; + + if (method == 0) { + CocktailSelectionSort(&v, 0, n - 1); + } else if (method == 1) { + CocktailSelectionSort_v2(&v, 0, n - 1); + } else { + std::cerr << "Unknown method" << std::endl; + return -1; + } + std::cout << "Sorted elements are\n"; + for (int i = 0; i < n; ++i) { + std::cout << v[i] << " "; + } + + return 0; +} diff --git a/sorting/comb_sort.cpp b/sorting/comb_sort.cpp new file mode 100644 index 00000000000..1b0a4d70633 --- /dev/null +++ b/sorting/comb_sort.cpp @@ -0,0 +1,49 @@ +// Kind of better version of Bubble sort. +// While Bubble sort is comparering adjacent value, Combsort is using gap larger +// than 1 Best case: O(n) Worst case: O(n ^ 2) + +#include +#include + +int a[100005]; +int n; + +int FindNextGap(int x) { + x = (x * 10) / 13; + + return std::max(1, x); +} + +void CombSort(int a[], int l, int r) { + // Init gap + int gap = n; + + // Initialize swapped as true to make sure that loop runs + bool swapped = true; + + // Keep running until gap = 1 or none elements were swapped + while (gap != 1 || swapped) { + // Find next gap + gap = FindNextGap(gap); + + swapped = false; + + // Compare all elements with current gap + for (int i = l; i <= r - gap; ++i) { + if (a[i] > a[i + gap]) { + std::swap(a[i], a[i + gap]); + swapped = true; + } + } + } +} + +int main() { + std::cin >> n; + for (int i = 1; i <= n; ++i) std::cin >> a[i]; + + CombSort(a, 1, n); + + for (int i = 1; i <= n; ++i) std::cout << a[i] << ' '; + return 0; +} diff --git a/sorting/combsort.cpp b/sorting/combsort.cpp deleted file mode 100644 index 2209c96fc55..00000000000 --- a/sorting/combsort.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//Kind of better version of Bubble sort. -//While Bubble sort is comparering adjacent value, Combsort is using gap larger than 1 -//Best case: O(n) -//Worst case: O(n ^ 2) - -#include - -using namespace std; - -int a[100005]; -int n; - -int FindNextGap(int x) -{ - x = (x * 10) / 13; - - return max(1, x); -} - -void CombSort(int a[], int l, int r) -{ - //Init gap - int gap = n; - - //Initialize swapped as true to make sure that loop runs - bool swapped = true; - - //Keep running until gap = 1 or none elements were swapped - while (gap != 1 || swapped) - { - //Find next gap - gap = FindNextGap(gap); - - swapped = false; - - // Compare all elements with current gap - for (int i = l; i <= r - gap; ++i) - { - if (a[i] > a[i + gap]) - { - swap(a[i], a[i + gap]); - swapped = true; - } - } - } -} - -int main() -{ - cin >> n; - for (int i = 1; i <= n; ++i) - cin >> a[i]; - - CombSort(a, 1, n); - - for (int i = 1; i <= n; ++i) - cout << a[i] << ' '; - return 0; -} diff --git a/sorting/counting_sort.cpp b/sorting/counting_sort.cpp new file mode 100644 index 00000000000..1fbfc0fa3a3 --- /dev/null +++ b/sorting/counting_sort.cpp @@ -0,0 +1,57 @@ +#include +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++) + if (Arr[i] < min) + min = Arr[i]; + return min; +} + +void Print(int Arr[], int N) { + for (int i = 0; i < N; i++) cout << Arr[i] << ", "; +} + +int *Counting_Sort(int Arr[], int N) { + int max = Max(Arr, N); + int min = Min(Arr, N); + int *Sorted_Arr = new int[N]; + + int *Count = new int[max - min + 1]; + + for (int i = 0; i < N; i++) Count[Arr[i] - min]++; + + for (int i = 1; i < (max - min + 1); i++) Count[i] += Count[i - 1]; + + for (int i = N - 1; i >= 0; i--) { + Sorted_Arr[Count[Arr[i] - min] - 1] = Arr[i]; + Count[Arr[i] - min]--; + } + + return Sorted_Arr; +} + +int main() { + int Arr[] = {47, 65, 20, 66, 25, 53, 64, 69, 72, 22, + 74, 25, 53, 15, 42, 36, 4, 69, 86, 19}, + N = 20; + int *Sorted_Arr; + + cout << "\n\tOrignal Array = "; + Print(Arr, N); + Sorted_Arr = Counting_Sort(Arr, N); + cout << "\n\t Sorted Array = "; + Print(Sorted_Arr, N); + cout << endl; + + return 0; +} diff --git a/sorting/CountingSortString.cpp b/sorting/counting_sort_string.cpp similarity index 50% rename from sorting/CountingSortString.cpp rename to sorting/counting_sort_string.cpp index 6179e5d1111..69d80c18a32 100644 --- a/sorting/CountingSortString.cpp +++ b/sorting/counting_sort_string.cpp @@ -3,35 +3,27 @@ using namespace std; -void countSort(string arr) -{ - +void countSort(string arr) { string output; int count[256], i; - for (int i = 0; i < 256; i++) - count[i] = 0; + for (int i = 0; i < 256; i++) count[i] = 0; - for (i = 0; arr[i]; ++i) - ++count[arr[i]]; + for (i = 0; arr[i]; ++i) ++count[arr[i]]; - for (i = 1; i <= 256; ++i) - count[i] += count[i - 1]; + for (i = 1; i < 256; ++i) count[i] += count[i - 1]; - for (i = 0; arr[i]; ++i) - { + for (i = 0; arr[i]; ++i) { output[count[arr[i]] - 1] = arr[i]; --count[arr[i]]; } - for (i = 0; arr[i]; ++i) - arr[i] = output[i]; + for (i = 0; arr[i]; ++i) arr[i] = output[i]; cout << "Sorted character array is " << arr; } -int main() -{ +int main() { string arr; cin >> arr; diff --git a/sorting/doxy.txt b/sorting/doxy.txt deleted file mode 100644 index 68079276e7b..00000000000 --- a/sorting/doxy.txt +++ /dev/null @@ -1,374 +0,0 @@ -# Doxyfile 1.8.13 -#This configuration file has been generated from Doxygen template. -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- -DOXYFILE_ENCODING = UTF-8 -PROJECT_NAME = "My Project" -PROJECT_NUMBER = -PROJECT_BRIEF = -PROJECT_LOGO = -OUTPUT_DIRECTORY = -CREATE_SUBDIRS = NO -ALLOW_UNICODE_NAMES = NO -OUTPUT_LANGUAGE = English -BRIEF_MEMBER_DESC = YES -REPEAT_BRIEF = YES -ABBREVIATE_BRIEF = "The $name class" \ - "The $name widget" \ - "The $name file" \ - is \ - provides \ - specifies \ - contains \ - represents \ - a \ - an \ - the -ALWAYS_DETAILED_SEC = NO -INLINE_INHERITED_MEMB = NO -FULL_PATH_NAMES = YES -STRIP_FROM_PATH = -STRIP_FROM_INC_PATH = -SHORT_NAMES = NO -JAVADOC_AUTOBRIEF = NO -QT_AUTOBRIEF = NO -MULTILINE_CPP_IS_BRIEF = NO -INHERIT_DOCS = YES -SEPARATE_MEMBER_PAGES = NO -TAB_SIZE = 4 -ALIASES = -TCL_SUBST = -OPTIMIZE_OUTPUT_FOR_C = NO -OPTIMIZE_OUTPUT_JAVA = NO -OPTIMIZE_FOR_FORTRAN = NO -OPTIMIZE_OUTPUT_VHDL = NO -EXTENSION_MAPPING = -MARKDOWN_SUPPORT = YES -TOC_INCLUDE_HEADINGS = 0 -AUTOLINK_SUPPORT = YES -BUILTIN_STL_SUPPORT = NO -CPP_CLI_SUPPORT = NO -SIP_SUPPORT = NO -IDL_PROPERTY_SUPPORT = YES -DISTRIBUTE_GROUP_DOC = NO -GROUP_NESTED_COMPOUNDS = NO -SUBGROUPING = YES -INLINE_GROUPED_CLASSES = NO -INLINE_SIMPLE_STRUCTS = NO -TYPEDEF_HIDES_STRUCT = NO -LOOKUP_CACHE_SIZE = 0 -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- -EXTRACT_ALL = NO -EXTRACT_PRIVATE = NO -EXTRACT_PACKAGE = NO -EXTRACT_STATIC = NO -EXTRACT_LOCAL_CLASSES = YES -EXTRACT_LOCAL_METHODS = NO -EXTRACT_ANON_NSPACES = NO -HIDE_UNDOC_MEMBERS = NO -HIDE_UNDOC_CLASSES = NO -HIDE_FRIEND_COMPOUNDS = NO -HIDE_IN_BODY_DOCS = NO -INTERNAL_DOCS = NO -CASE_SENSE_NAMES = YES -HIDE_SCOPE_NAMES = NO -HIDE_COMPOUND_REFERENCE= NO -SHOW_INCLUDE_FILES = YES -SHOW_GROUPED_MEMB_INC = NO -FORCE_LOCAL_INCLUDES = NO -INLINE_INFO = YES -SORT_MEMBER_DOCS = YES -SORT_BRIEF_DOCS = NO -SORT_MEMBERS_CTORS_1ST = NO -SORT_GROUP_NAMES = NO -SORT_BY_SCOPE_NAME = NO -STRICT_PROTO_MATCHING = NO -GENERATE_TODOLIST = YES -GENERATE_TESTLIST = YES -GENERATE_BUGLIST = YES -GENERATE_DEPRECATEDLIST= YES -ENABLED_SECTIONS = -MAX_INITIALIZER_LINES = 30 -SHOW_USED_FILES = YES -SHOW_FILES = YES -SHOW_NAMESPACES = YES -FILE_VERSION_FILTER = -LAYOUT_FILE = -CITE_BIB_FILES = -#--------------------------------------------------------------------------- -# Configuration options related to warning and progress messages -#--------------------------------------------------------------------------- -QUIET = NO -WARNINGS = YES -WARN_IF_UNDOCUMENTED = YES -WARN_IF_DOC_ERROR = YES -WARN_NO_PARAMDOC = NO -WARN_AS_ERROR = NO -WARN_FORMAT = "$file:$line: $text" -WARN_LOGFILE = -#--------------------------------------------------------------------------- -# Configuration options related to the input files -#--------------------------------------------------------------------------- -INPUT = -INPUT_ENCODING = UTF-8 -FILE_PATTERNS = *.c \ - *.cc \ - *.cxx \ - *.cpp \ - *.c++ \ - *.java \ - *.ii \ - *.ixx \ - *.ipp \ - *.i++ \ - *.inl \ - *.idl \ - *.ddl \ - *.odl \ - *.h \ - *.hh \ - *.hxx \ - *.hpp \ - *.h++ \ - *.cs \ - *.d \ - *.php \ - *.php4 \ - *.php5 \ - *.phtml \ - *.inc \ - *.m \ - *.markdown \ - *.md \ - *.mm \ - *.dox \ - *.py \ - *.pyw \ - *.f90 \ - *.f95 \ - *.f03 \ - *.f08 \ - *.f \ - *.for \ - *.tcl \ - *.vhd \ - *.vhdl \ - *.ucf \ - *.qsf -RECURSIVE = NO -EXCLUDE = -EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = -EXCLUDE_SYMBOLS = -EXAMPLE_PATH = -EXAMPLE_PATTERNS = * -EXAMPLE_RECURSIVE = NO -IMAGE_PATH = -INPUT_FILTER = -FILTER_PATTERNS = -FILTER_SOURCE_FILES = NO -FILTER_SOURCE_PATTERNS = -USE_MDFILE_AS_MAINPAGE = -#--------------------------------------------------------------------------- -# Configuration options related to source browsing -#--------------------------------------------------------------------------- -SOURCE_BROWSER = NO -INLINE_SOURCES = NO -STRIP_CODE_COMMENTS = YES -REFERENCED_BY_RELATION = NO -REFERENCES_RELATION = NO -REFERENCES_LINK_SOURCE = YES -SOURCE_TOOLTIPS = YES -USE_HTAGS = NO -VERBATIM_HEADERS = YES -CLANG_ASSISTED_PARSING = NO -CLANG_OPTIONS = -#--------------------------------------------------------------------------- -# Configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- -ALPHABETICAL_INDEX = YES -COLS_IN_ALPHA_INDEX = 5 -IGNORE_PREFIX = -#--------------------------------------------------------------------------- -# Configuration options related to the HTML output -#--------------------------------------------------------------------------- -GENERATE_HTML = YES -HTML_OUTPUT = html -HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = -HTML_STYLESHEET = -HTML_EXTRA_STYLESHEET = -HTML_EXTRA_FILES = -HTML_COLORSTYLE_HUE = 220 -HTML_COLORSTYLE_SAT = 100 -HTML_COLORSTYLE_GAMMA = 80 -HTML_TIMESTAMP = NO -HTML_DYNAMIC_SECTIONS = NO -HTML_INDEX_NUM_ENTRIES = 100 -GENERATE_DOCSET = NO -DOCSET_FEEDNAME = "Doxygen generated docs" -DOCSET_BUNDLE_ID = org.doxygen.Project -DOCSET_PUBLISHER_ID = org.doxygen.Publisher -DOCSET_PUBLISHER_NAME = Publisher -GENERATE_HTMLHELP = NO -CHM_FILE = -HHC_LOCATION = -GENERATE_CHI = NO -CHM_INDEX_ENCODING = -BINARY_TOC = NO -TOC_EXPAND = NO -GENERATE_QHP = NO -QCH_FILE = -QHP_NAMESPACE = org.doxygen.Project -QHP_VIRTUAL_FOLDER = doc -QHP_CUST_FILTER_NAME = -QHP_CUST_FILTER_ATTRS = -QHP_SECT_FILTER_ATTRS = -QHG_LOCATION = -GENERATE_ECLIPSEHELP = NO -ECLIPSE_DOC_ID = org.doxygen.Project -DISABLE_INDEX = NO -GENERATE_TREEVIEW = NO -ENUM_VALUES_PER_LINE = 4 -TREEVIEW_WIDTH = 250 -EXT_LINKS_IN_WINDOW = NO -FORMULA_FONTSIZE = 10 -FORMULA_TRANSPARENT = YES -USE_MATHJAX = NO -MATHJAX_FORMAT = HTML-CSS -MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest -MATHJAX_EXTENSIONS = -MATHJAX_CODEFILE = -SEARCHENGINE = YES -SERVER_BASED_SEARCH = NO -EXTERNAL_SEARCH = NO -SEARCHENGINE_URL = -SEARCHDATA_FILE = searchdata.xml -EXTERNAL_SEARCH_ID = -EXTRA_SEARCH_MAPPINGS = -#--------------------------------------------------------------------------- -# Configuration options related to the LaTeX output -#--------------------------------------------------------------------------- -GENERATE_LATEX = NO -LATEX_OUTPUT = latex -LATEX_CMD_NAME = latex -MAKEINDEX_CMD_NAME = makeindex -COMPACT_LATEX = NO -PAPER_TYPE = a4 -EXTRA_PACKAGES = -LATEX_HEADER = -LATEX_FOOTER = -LATEX_EXTRA_STYLESHEET = -LATEX_EXTRA_FILES = -PDF_HYPERLINKS = YES -USE_PDFLATEX = YES -LATEX_BATCHMODE = NO -LATEX_HIDE_INDICES = NO -LATEX_SOURCE_CODE = NO -LATEX_BIB_STYLE = plain -LATEX_TIMESTAMP = NO -#--------------------------------------------------------------------------- -# Configuration options related to the RTF output -#--------------------------------------------------------------------------- -GENERATE_RTF = NO -RTF_OUTPUT = rtf -COMPACT_RTF = NO -RTF_HYPERLINKS = NO -RTF_STYLESHEET_FILE = -RTF_EXTENSIONS_FILE = -RTF_SOURCE_CODE = NO -#--------------------------------------------------------------------------- -# Configuration options related to the man page output -#--------------------------------------------------------------------------- -GENERATE_MAN = NO -MAN_OUTPUT = man -MAN_EXTENSION = .3 -MAN_SUBDIR = -MAN_LINKS = NO -#--------------------------------------------------------------------------- -# Configuration options related to the XML output -#--------------------------------------------------------------------------- -GENERATE_XML = NO -XML_OUTPUT = xml -XML_PROGRAMLISTING = YES -#--------------------------------------------------------------------------- -# Configuration options related to the DOCBOOK output -#--------------------------------------------------------------------------- -GENERATE_DOCBOOK = NO -DOCBOOK_OUTPUT = docbook -DOCBOOK_PROGRAMLISTING = NO -#--------------------------------------------------------------------------- -# Configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- -GENERATE_AUTOGEN_DEF = NO -#--------------------------------------------------------------------------- -# Configuration options related to the Perl module output -#--------------------------------------------------------------------------- -GENERATE_PERLMOD = NO -PERLMOD_LATEX = NO -PERLMOD_PRETTY = YES -PERLMOD_MAKEVAR_PREFIX = -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- -ENABLE_PREPROCESSING = YES -MACRO_EXPANSION = NO -EXPAND_ONLY_PREDEF = NO -SEARCH_INCLUDES = YES -INCLUDE_PATH = -INCLUDE_FILE_PATTERNS = -PREDEFINED = -EXPAND_AS_DEFINED = -SKIP_FUNCTION_MACROS = YES -#--------------------------------------------------------------------------- -# Configuration options related to external references -#--------------------------------------------------------------------------- -TAGFILES = -GENERATE_TAGFILE = -ALLEXTERNALS = NO -EXTERNAL_GROUPS = YES -EXTERNAL_PAGES = YES -PERL_PATH = /usr/bin/perl -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- -CLASS_DIAGRAMS = YES -MSCGEN_PATH = -DIA_PATH = -HIDE_UNDOC_RELATIONS = YES -HAVE_DOT = YES -DOT_NUM_THREADS = 0 -DOT_FONTNAME = Helvetica -DOT_FONTSIZE = 10 -DOT_FONTPATH = -CLASS_GRAPH = YES -COLLABORATION_GRAPH = YES -GROUP_GRAPHS = YES -UML_LOOK = NO -UML_LIMIT_NUM_FIELDS = 10 -TEMPLATE_RELATIONS = NO -INCLUDE_GRAPH = YES -INCLUDED_BY_GRAPH = YES -CALL_GRAPH = NO -CALLER_GRAPH = NO -GRAPHICAL_HIERARCHY = YES -DIRECTORY_GRAPH = YES -DOT_IMAGE_FORMAT = png -INTERACTIVE_SVG = NO -DOT_PATH = -DOTFILE_DIRS = -MSCFILE_DIRS = -DIAFILE_DIRS = -PLANTUML_JAR_PATH = -PLANTUML_CFG_FILE = -PLANTUML_INCLUDE_PATH = -DOT_GRAPH_MAX_NODES = 50 -MAX_DOT_GRAPH_DEPTH = 0 -DOT_TRANSPARENT = NO -DOT_MULTI_TARGETS = NO -GENERATE_LEGEND = YES -DOT_CLEANUP = YES diff --git a/sorting/insertion_sort.cpp b/sorting/insertion_sort.cpp new file mode 100644 index 00000000000..fe920ca5913 --- /dev/null +++ b/sorting/insertion_sort.cpp @@ -0,0 +1,36 @@ +// Insertion Sort + +#include + +int main() { + int n; + std::cout << "\nEnter the length of your array : "; + std::cin >> n; + int *Array = new int[n]; + std::cout << "\nEnter any " << n << " Numbers for Unsorted Array : "; + + // Input + for (int i = 0; i < n; i++) { + std::cin >> Array[i]; + } + + // Sorting + for (int i = 1; i < n; i++) { + int temp = Array[i]; + int j = i - 1; + while (j >= 0 && temp < Array[j]) { + Array[j + 1] = Array[j]; + j--; + } + Array[j + 1] = temp; + } + + // Output + std::cout << "\nSorted Array : "; + for (int i = 0; i < n; i++) { + std::cout << Array[i] << "\t"; + } + + delete[] Array; + return 0; +} diff --git a/sorting/library_sort.cpp b/sorting/library_sort.cpp index 6f1ab6245aa..c9cba88d8c4 100644 --- a/sorting/library_sort.cpp +++ b/sorting/library_sort.cpp @@ -8,8 +8,7 @@ void librarySort(int *index, int n) { bool target_lib, *numbered; - for (int i = 0; i < 2; i++) - library[i] = new int[n]; + for (int i = 0; i < 2; i++) library[i] = new int[n]; gaps = new int[n + 1]; numbered = new bool[n + 1]; @@ -79,8 +78,7 @@ int main() { librarySort(index_ex, n_ex); std::cout << "sorted array :" << std::endl; - for (int i = 0; i < n_ex; i++) - std::cout << index_ex[i] << " "; + for (int i = 0; i < n_ex; i++) std::cout << index_ex[i] << " "; std::cout << std::endl; /* --output-- diff --git a/sorting/makefile b/sorting/makefile deleted file mode 100644 index 21d3186c698..00000000000 --- a/sorting/makefile +++ /dev/null @@ -1,11 +0,0 @@ -non_recursive_merge_sort: non_recursive_merge_sort.cpp - g++ -std=c++17 -o non_recursive_merge_sort non_recursive_merge_sort.cpp -.PHONY: test -.PHONY: doc -.PHONY: clean -test: non_recursive_merge_sort - ./non_recursive_merge_sort -doc: doxy.txt - doxygen doxy.txt -clean: - rm -fr non_recursive_merge_sort html diff --git a/sorting/merge_sort.cpp b/sorting/merge_sort.cpp new file mode 100644 index 00000000000..82ab869cd2c --- /dev/null +++ b/sorting/merge_sort.cpp @@ -0,0 +1,81 @@ +#include + +void merge(int arr[], int l, int m, int r) { + int i, j, k; + int n1 = m - l + 1; + int n2 = r - m; + + int *L = new int[n1], *R = new int[n2]; + + for (i = 0; i < n1; i++) L[i] = arr[l + i]; + for (j = 0; j < n2; j++) R[j] = arr[m + 1 + j]; + + i = 0; + j = 0; + k = l; + while (i < n1 && j < n2) { + if (L[i] <= R[j]) { + arr[k] = L[i]; + i++; + } else { + arr[k] = R[j]; + j++; + } + k++; + } + + while (i < n1) { + arr[k] = L[i]; + i++; + k++; + } + + while (j < n2) { + arr[k] = R[j]; + j++; + k++; + } + + delete[] L; + delete[] R; +} + +void mergeSort(int arr[], int l, int r) { + if (l < r) { + int m = l + (r - l) / 2; + + mergeSort(arr, l, m); + mergeSort(arr, m + 1, r); + + merge(arr, l, m, r); + } +} + +void show(int A[], int size) { + int i; + for (i = 0; i < size; i++) std::cout << A[i] << "\n"; +} + +int main() { + int size; + std::cout << "\nEnter the number of elements : "; + + std::cin >> size; + + int *arr = new int[size]; + + std::cout << "\nEnter the unsorted elements : "; + + for (int i = 0; i < size; ++i) { + std::cout << "\n"; + std::cin >> arr[i]; + } + + mergeSort(arr, 0, size); + + std::cout << "Sorted array\n"; + show(arr, size); + + delete[] arr; + return 0; +} diff --git a/sorting/non_recursive_merge_sort.cpp b/sorting/non_recursive_merge_sort.cpp index c6ca56376df..b99b931080b 100644 --- a/sorting/non_recursive_merge_sort.cpp +++ b/sorting/non_recursive_merge_sort.cpp @@ -5,28 +5,31 @@ * A generic implementation of non-recursive merge sort. */ #include // for size_t +#include #include // for std::move & std::remove_reference_t -template + +namespace sorting { +template void merge(Iterator, Iterator, const Iterator, char[]); /// bottom-up merge sort which sorts elements in a non-decreasing order /** - * sorts elements non-recursively by breaking them into small segments, merging - * adjacent segments into larger sorted segments, then increasing the sizes of - * segments by factors of 2 and repeating the same process. + * sorts elements non-recursively by breaking them into small segments, + * merging adjacent segments into larger sorted segments, then increasing + * the sizes of segments by factors of 2 and repeating the same process. * best-case = worst-case = O(n log(n)) * @param first points to the first element * @param last points to 1-step past the last element * @param n the number of elements -*/ -template + */ +template void non_recursive_merge_sort(const Iterator first, const Iterator last, const size_t n) { // create a buffer large enough to store all elements // dynamically allocated to comply with cpplint - char * buffer = new char[n * sizeof(*first)]; - // buffer size can be optimized to largest power of 2 less than n elements - // divide the container into equally-sized segments whose length start at 1 - // and keeps increasing by factors of 2 + char* buffer = new char[n * sizeof(*first)]; + // buffer size can be optimized to largest power of 2 less than n + // elements divide the container into equally-sized segments whose + // length start at 1 and keeps increasing by factors of 2 for (size_t length(1); length < n; length <<= 1) { // merge adjacent segments whose number is n / (length * 2) Iterator left(first); @@ -49,32 +52,28 @@ void non_recursive_merge_sort(const Iterator first, const Iterator last, * @param r points to the right part, end of left part * @param e points to end of right part * @param b points at the buffer -*/ -template + */ +template void merge(Iterator l, Iterator r, const Iterator e, char b[]) { // create 2 pointers to point at the buffer auto p(reinterpret_cast*>(b)), c(p); // move the left part of the segment - for (Iterator t(l); r != t; ++t) - *p++ = std::move(*t); + for (Iterator t(l); r != t; ++t) *p++ = std::move(*t); // while neither the buffer nor the right part has been exhausted // move the smallest element of the two back to the container - while (e != r && c != p) - *l++ = std::move(*r < *c ? *r++ : *c++); + while (e != r && c != p) *l++ = std::move(*r < *c ? *r++ : *c++); // notice only one of the two following loops will be executed // while the right part hasn't bee exhausted, move it back - while (e != r) - *l++ = std::move(*r++); + while (e != r) *l++ = std::move(*r++); // while the buffer hasn't bee exhausted, move it back - while (c != p) - *l++ = std::move(*c++); + while (c != p) *l++ = std::move(*c++); } /// bottom-up merge sort which sorts elements in a non-decreasing order /** * @param first points to the first element * @param n the number of elements -*/ -template + */ +template void non_recursive_merge_sort(const Iterator first, const size_t n) { non_recursive_merge_sort(first, first + n, n); } @@ -82,25 +81,21 @@ void non_recursive_merge_sort(const Iterator first, const size_t n) { /** * @param first points to the first element * @param last points to 1-step past the last element -*/ -template + */ +template void non_recursive_merge_sort(const Iterator first, const Iterator last) { non_recursive_merge_sort(first, last, last - first); } -/** - * @mainpage A demonstration of auto-generated documentation using Doxygen. - * Currently, it only creates output for non_recursive_merge_sort.cpp, but if - * it has proven its efficacy it can be expanded to other files. - * The configuration file is named doxy.txt and has been auto-generated too. -*/ -// the remaining of this file is only for testing. It can erased to to convert -// it into a header file for later re-use. -#include -int main(int argc, char ** argv) { + +} // namespace sorting + +using sorting::non_recursive_merge_sort; + +int main(int argc, char** argv) { int size; std::cout << "Enter the number of elements : "; std::cin >> size; - int * arr = new int[size]; + int* arr = new int[size]; for (int i = 0; i < size; ++i) { std::cout << "arr[" << i << "] = "; std::cin >> arr[i]; diff --git a/sorting/numeric_string_sort.cpp b/sorting/numeric_string_sort.cpp new file mode 100644 index 00000000000..04a12e71af4 --- /dev/null +++ b/sorting/numeric_string_sort.cpp @@ -0,0 +1,55 @@ +// 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, +// even though we know the correct sorting order is 1,2,3,10,20,30,100,200,300 + +// This Programme uses a comparator to sort the array in Numerical order instead +// of Alphanumeric order + +#include +#include +#include +#include + +bool NumericSort(std::string a, std::string b) { + while (a[0] == '0') { + a.erase(a.begin()); + } + while (b[0] == '0') { + b.erase(b.begin()); + } + int n = a.length(); + int m = b.length(); + if (n == m) + return a < b; + return n < m; +} + +int main() { + int n; + std::cout << "Enter number of elements to be sorted Numerically\n"; + std::cin >> n; + + std::vector v(n); + std::cout << "Enter the string of Numbers\n"; + for (int i = 0; i < n; i++) { + std::cin >> v[i]; + } + + sort(v.begin(), v.end()); + std::cout << "Elements sorted normally \n"; + for (int i = 0; i < n; i++) { + std::cout << v[i] << " "; + } + std::cout << "\n"; + + std::sort(v.begin(), v.end(), NumericSort); + std::cout << "Elements sorted Numerically \n"; + for (int i = 0; i < n; i++) { + std::cout << v[i] << " "; + } + + return 0; +} diff --git a/sorting/odd_even_sort.cpp b/sorting/odd_even_sort.cpp new file mode 100644 index 00000000000..25f2a371228 --- /dev/null +++ b/sorting/odd_even_sort.cpp @@ -0,0 +1,53 @@ +/* C++ implementation Odd Even Sort */ +#include +#include + +using namespace std; + +void oddEven(vector &arr, int size) { + bool sorted = false; + while (!sorted) { + sorted = true; + for (int i = 1; i < size - 1; i += 2) // Odd + { + if (arr[i] > arr[i + 1]) { + swap(arr[i], arr[i + 1]); + sorted = false; + } + } + + for (int i = 0; i < size - 1; i += 2) // Even + { + if (arr[i] > arr[i + 1]) { + swap(arr[i], arr[i + 1]); + sorted = false; + } + } + } +} + +void show(vector A, int size) { + int i; + for (i = 0; i < size; i++) cout << A[i] << "\n"; +} + +int main() { + int size, temp; + cout << "\nEnter the number of elements : "; + cin >> size; + + vector arr; + + cout << "\nEnter the unsorted elements : \n"; + + for (int i = 0; i < size; ++i) { + cin >> temp; + arr.push_back(temp); + } + + oddEven(arr, size); + + cout << "Sorted array\n"; + show(arr, size); + return 0; +} diff --git a/sorting/quick_sort.cpp b/sorting/quick_sort.cpp index d067fa068e8..5d102dc8842 100644 --- a/sorting/quick_sort.cpp +++ b/sorting/quick_sort.cpp @@ -1,8 +1,6 @@ /** - * - * copyright The Algorithms - * Author - - * Correction - ayaankhan98 + * @file + * @brief Quick sort algorithm * * Implementation Details - * Quick Sort is a divide and conquer algorithm. It picks and element as @@ -26,24 +24,25 @@ #include #include +namespace sorting { /** - * This function takes last element as pivot, places - * the pivot element at its correct position in sorted - * array, and places all smaller (smaller than pivot) - * to left of pivot and all greater elements to right - * of pivot + * This function takes last element as pivot, places + * the pivot element at its correct position in sorted + * array, and places all smaller (smaller than pivot) + * to left of pivot and all greater elements to right + * of pivot * */ int partition(int arr[], int low, int high) { - int pivot = arr[high]; // taking the last element as pivot - int i = (low - 1); // Index of smaller element + int pivot = arr[high]; // taking the last element as pivot + int i = (low - 1); // Index of smaller element for (int j = low; j < high; j++) { // If current element is smaller than or // equal to pivot if (arr[j] <= pivot) { - i++; // increment index of smaller element + i++; // increment index of smaller element int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; @@ -55,12 +54,12 @@ int partition(int arr[], int low, int high) { return (i + 1); } -/** - * The main function that implements QuickSort - * arr[] --> Array to be sorted, - * low --> Starting index, - * high --> Ending index -*/ +/** + * The main function that implements QuickSort + * arr[] --> Array to be sorted, + * low --> Starting index, + * high --> Ending index + */ void quickSort(int arr[], int low, int high) { if (low < high) { int p = partition(arr, low, high); @@ -69,25 +68,35 @@ void quickSort(int arr[], int low, int high) { } } +} // namespace sorting + +using sorting::quickSort; + // prints the array after sorting void show(int arr[], int size) { - for (int i = 0; i < size; i++) - std::cout << arr[i] << " "; + for (int i = 0; i < size; i++) std::cout << arr[i] << " "; std::cout << "\n"; } -// Driver program to test above functions +/** Driver program to test above functions */ int main() { int size; std::cout << "\nEnter the number of elements : "; + std::cin >> size; + int *arr = new int[size]; + std::cout << "\nEnter the unsorted elements : "; + for (int i = 0; i < size; ++i) { - std::cin >> arr[i]; + std::cout << "\n"; + std::cin >> arr[i]; } - quickSort(arr, 0, size-1); - std::cout << "Sorted array : "; + quickSort(arr, 0, size); + std::cout << "Sorted array\n"; show(arr, size); + + delete[] arr; return 0; } diff --git a/sorting/radix_sort.cpp b/sorting/radix_sort.cpp new file mode 100644 index 00000000000..a0fbfe99ee5 --- /dev/null +++ b/sorting/radix_sort.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +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) { + if (a[i] > max) { + max = a[i]; + } + } + int maxdigits = 0; + while (max) { + maxdigits++; + max /= 10; + } + for (int j = 0; j < maxdigits; j++) { + for (int i = 0; i < n; i++) { + int t = std::pow(10, j); + count[(a[i] % (10 * t)) / t]++; + } + int k = 0; + for (int p = 0; p < 10; p++) { + for (int i = 0; i < n; i++) { + int t = std::pow(10, j); + if ((a[i] % (10 * t)) / t == p) { + output[k] = a[i]; + k++; + } + } + } + memset(count, 0, sizeof(count)); + for (int i = 0; i < n; ++i) { + a[i] = output[i]; + } + } + delete[] output; +} + +void print(int a[], int n) { + for (int i = 0; i < n; ++i) { + std::cout << a[i] << " "; + } + std::cout << std::endl; +} + +int main(int argc, char const* argv[]) { + int a[] = {170, 45, 75, 90, 802, 24, 2, 66}; + int n = sizeof(a) / sizeof(a[0]); + radixsort(a, n); + print(a, n); + return 0; +} diff --git a/sorting/selection_sort.cpp b/sorting/selection_sort.cpp new file mode 100644 index 00000000000..3854f52e6c4 --- /dev/null +++ b/sorting/selection_sort.cpp @@ -0,0 +1,33 @@ +// Selection Sort + +#include +using namespace std; + +int main() { + int Array[6]; + cout << "\nEnter any 6 Numbers for Unsorted Array : "; + + // Input + for (int i = 0; i < 6; i++) { + cin >> Array[i]; + } + + // Selection Sorting + for (int i = 0; i < 6; i++) { + int min = i; + for (int j = i + 1; j < 6; j++) { + if (Array[j] < Array[min]) { + min = j; // Finding the smallest number in Array + } + } + int temp = Array[i]; + Array[i] = Array[min]; + Array[min] = temp; + } + + // Output + cout << "\nSorted Array : "; + for (int i = 0; i < 6; i++) { + cout << Array[i] << "\t"; + } +} diff --git a/sorting/shell_sort.cpp b/sorting/shell_sort.cpp new file mode 100644 index 00000000000..eb701478d4e --- /dev/null +++ b/sorting/shell_sort.cpp @@ -0,0 +1,37 @@ +#include + +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; i++) { + std::cin >> array[i]; + } + + // Sorting + for (int i = size / 2; i > 0; i = i / 2) { + for (int j = i; j < size; j++) { + for (int k = j - i; k >= 0; k = k - i) { + if (array[k] < array[k + i]) { + break; + } else { + int temp = array[k + i]; + array[k + i] = array[k]; + array[k] = temp; + } + } + } + } + + // Output + std::cout << "\nSorted array : "; + for (int i = 0; i < size; ++i) { + std::cout << array[i] << "\t"; + } + + delete[] array; + return 0; +} diff --git a/sorting/shell_sort2.cpp b/sorting/shell_sort2.cpp new file mode 100644 index 00000000000..5db773aca91 --- /dev/null +++ b/sorting/shell_sort2.cpp @@ -0,0 +1,234 @@ +/** + * \file + * \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 + +/** pretty print array + * \param[in] arr array to print + * \param[in] LEN length of array to print + */ +template +void show_data(T *arr, size_t LEN) { + size_t i; + + for (i = 0; i < LEN; i++) { + std::cout << arr[i] << ", "; + } + std::cout << std::endl; +} + +/** pretty print array + * \param[in] arr array to print + * \param[in] N length of array to print + */ +template +void show_data(T (&arr)[N]) { + show_data(arr, N); +} + +/** \namespace sorting + * \brief Sorting algorithms + */ +namespace sorting { +/** + * Optimized algorithm - takes half the time by utilizing + * Mar + **/ +template +void shell_sort(T *arr, size_t LEN) { + const unsigned int gaps[] = {701, 301, 132, 57, 23, 10, 4, 1}; + const unsigned int gap_len = 8; + size_t i, j, g; + + for (g = 0; g < gap_len; g++) { + unsigned int gap = gaps[g]; + for (i = gap; i < LEN; i++) { + T tmp = arr[i]; + + for (j = i; j >= gap && (arr[j - gap] - tmp) > 0; j -= gap) { + arr[j] = arr[j - gap]; + } + + arr[j] = tmp; + } + } +} + +/** function overload - when input array is of a known length array type + */ +template +void shell_sort(T (&arr)[N]) { + shell_sort(arr, N); +} + +/** function overload - when input array is of type std::vector, + * simply send the data content and the data length to the above function. + */ +template +void shell_sort(std::vector *arr) { + shell_sort(arr->data(), arr->size()); +} + +} // namespace sorting + +using sorting::shell_sort; + +/** + * function to compare sorting using cstdlib's qsort + **/ +template +int compare(const void *a, const void *b) { + T arg1 = *static_cast(a); + T arg2 = *static_cast(b); + + if (arg1 < arg2) + return -1; + if (arg1 > arg2) + return 1; + return 0; + + // return (arg1 > arg2) - (arg1 < arg2); // possible shortcut + // return arg1 - arg2; // erroneous shortcut (fails if INT_MIN is present) +} + +/** + * Test implementation of shell_sort on integer arrays by comparing results + * against std::qsort. + */ +void test_int(const int NUM_DATA) { + // int array = new int[NUM_DATA]; + int *data = new int[NUM_DATA]; + int *data2 = new int[NUM_DATA]; + // int array2 = new int[NUM_DATA]; + int range = 1800; + + for (int i = 0; i < NUM_DATA; i++) + data[i] = data2[i] = (std::rand() % range) - (range >> 1); + + /* sort using our implementation */ + std::clock_t start = std::clock(); + shell_sort(data, NUM_DATA); + std::clock_t end = std::clock(); + double elapsed_time = static_cast(end - start) / CLOCKS_PER_SEC; + std::cout << "Time spent sorting using shell_sort2: " << elapsed_time + << "s\n"; + + /* sort using std::qsort */ + start = std::clock(); + std::qsort(data2, NUM_DATA, sizeof(data2[0]), compare); + end = std::clock(); + + elapsed_time = static_cast(end - start) / CLOCKS_PER_SEC; + std::cout << "Time spent sorting using std::qsort: " << elapsed_time + << "s\n"; + + for (int i = 0; i < NUM_DATA; i++) { + assert(data[i] == data2[i]); // ensure that our sorting results match + // the standard results + } + + delete[] data; + delete[] data2; +} + +/** + * Test implementation of shell_sort on float arrays by comparing results + * against std::qsort. + */ +void test_f(const int NUM_DATA) { + // int array = new int[NUM_DATA]; + float *data = new float[NUM_DATA]; + float *data2 = new float[NUM_DATA]; + // int array2 = new int[NUM_DATA]; + int range = 1000; + + for (int i = 0; i < NUM_DATA; i++) { + data[i] = data2[i] = ((std::rand() % range) - (range >> 1)) / 100.; + } + + /* sort using our implementation */ + std::clock_t start = std::clock(); + shell_sort(data, NUM_DATA); + std::clock_t end = std::clock(); + double elapsed_time = static_cast(end - start) / CLOCKS_PER_SEC; + std::cout << "Time spent sorting using shell_sort2: " << elapsed_time + << "s\n"; + + /* sort using std::qsort */ + start = std::clock(); + std::qsort(data2, NUM_DATA, sizeof(data2[0]), compare); + end = std::clock(); + + elapsed_time = static_cast(end - start) / CLOCKS_PER_SEC; + std::cout << "Time spent sorting using std::qsort: " << elapsed_time + << "s\n"; + + for (int i = 0; i < NUM_DATA; i++) { + assert(data[i] == data2[i]); // ensure that our sorting results match + // the standard results + } + + delete[] data; + delete[] data2; +} + +/** Main function */ +int main(int argc, char *argv[]) { + // initialize random number generator - once per program + std::srand(std::time(NULL)); + + test_int(100); // test with sorting random array of 100 values + std::cout << "Test 1 - 100 int values - passed. \n"; + test_int(1000); // test with sorting random array of 1000 values + std::cout << "Test 2 - 1000 int values - passed.\n"; + test_int(10000); // test with sorting random array of 10000 values + std::cout << "Test 3 - 10000 int values - passed.\n"; + + test_f(100); // test with sorting random array of 100 values + std::cout << "Test 1 - 100 float values - passed. \n"; + test_f(1000); // test with sorting random array of 1000 values + std::cout << "Test 2 - 1000 float values - passed.\n"; + test_f(10000); // test with sorting random array of 10000 values + std::cout << "Test 3 - 10000 float values - passed.\n"; + + int i, NUM_DATA; + + if (argc == 2) + NUM_DATA = atoi(argv[1]); + else + NUM_DATA = 200; + + // int array = new int[NUM_DATA]; + int *data = new int[NUM_DATA]; + // int array2 = new int[NUM_DATA]; + int range = 1800; + + std::srand(time(NULL)); + for (i = 0; i < NUM_DATA; i++) { + // allocate random numbers in the given range + data[i] = (std::rand() % range) - (range >> 1); + } + + std::cout << "Unsorted original data: " << std::endl; + show_data(data, NUM_DATA); + std::clock_t start = std::clock(); + shell_sort(data, NUM_DATA); // perform sorting + std::clock_t end = std::clock(); + + std::cout << std::endl + << "Data Sorted using custom implementation: " << std::endl; + show_data(data, NUM_DATA); + + double elapsed_time = (end - start) * 1.f / CLOCKS_PER_SEC; + std::cout << "Time spent sorting: " << elapsed_time << "s\n" << std::endl; + + delete[] data; + return 0; +} diff --git a/sorting/slow_sort.cpp b/sorting/slow_sort.cpp new file mode 100644 index 00000000000..a3e64dba03c --- /dev/null +++ b/sorting/slow_sort.cpp @@ -0,0 +1,56 @@ +// 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 +// Stolfi in their paper Pessimal Algorithms and Simplexity Analysis. This +// algorithm multiplies a single problem into multiple subproblems It is +// interesting because it is provably the least efficient sorting algorithm that +// can be built asymptotically, and with the restriction that such an algorithm, +// while being slow, must still all the time be working towards a result. + +#include + +void SlowSort(int a[], int i, int j) { + if (i >= j) + return; + int m = i + (j - i) / 2; // midpoint, implemented this way to avoid + // overflow + int temp; + SlowSort(a, i, m); + SlowSort(a, m + 1, j); + if (a[j] < a[m]) { + temp = a[j]; // swapping a[j] & a[m] + a[j] = a[m]; + a[m] = temp; + } + SlowSort(a, i, j - 1); +} + +// Sample Main function + +int main() { + int size; + std::cout << "\nEnter the number of elements : "; + + std::cin >> size; + + int *arr = new int[size]; + + std::cout << "\nEnter the unsorted elements : "; + + for (int i = 0; i < size; ++i) { + std::cout << "\n"; + std::cin >> arr[i]; + } + + SlowSort(arr, 0, size); + + std::cout << "Sorted array\n"; + + for (int i = 0; i < size; ++i) { + std::cout << arr[i] << " "; + } + + delete[] arr; + return 0; +} diff --git a/sorting/swap_sort.cpp b/sorting/swap_sort.cpp index a4ab1e57b66..4cdaa57b348 100644 --- a/sorting/swap_sort.cpp +++ b/sorting/swap_sort.cpp @@ -10,7 +10,7 @@ int minSwaps(int arr[], int n) { // Create an array of pairs where first // element is array element and second element // is position of first element - std::pair arrPos[n]; + std::pair *arrPos = new std::pair[n]; for (int i = 0; i < n; i++) { arrPos[i].first = arr[i]; arrPos[i].second = i; @@ -53,6 +53,8 @@ int minSwaps(int arr[], int n) { } } + delete[] arrPos; + // Return result return ans; } diff --git a/sorting/Tim Sort.cpp b/sorting/tim_sort.cpp similarity index 55% rename from sorting/Tim Sort.cpp rename to sorting/tim_sort.cpp index 14d3a04d049..94f5aa230b3 100644 --- a/sorting/Tim Sort.cpp +++ b/sorting/tim_sort.cpp @@ -1,115 +1,103 @@ // C++ program to perform TimSort. +#include #include -using namespace std; + 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) -{ - for (int i = left + 1; i <= right; i++) - { + +// 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) { + for (int i = left + 1; i <= right; i++) { int temp = arr[i]; int j = i - 1; - while (arr[j] > temp && j >= left) - { - arr[j+1] = arr[j]; + while (arr[j] > temp && j >= left) { + arr[j + 1] = arr[j]; j--; } - arr[j+1] = temp; + arr[j + 1] = temp; } } - + // merge function merges the sorted runs -void merge(int arr[], int l, int m, int r) -{ +void merge(int arr[], int l, int m, int r) { // original array is broken in two parts, left and right array int len1 = m - l + 1, len2 = r - m; - int left[len1], right[len2]; - for (int i = 0; i < len1; i++) - left[i] = arr[l + i]; - for (int i = 0; i < len2; i++) - right[i] = arr[m + 1 + i]; - + int *left = new int[len1], *right = new int[len2]; + for (int i = 0; i < len1; i++) left[i] = arr[l + i]; + for (int i = 0; i < len2; i++) right[i] = arr[m + 1 + i]; + int i = 0; int j = 0; int k = l; - + // after comparing, we merge those two array in larger sub array - while (i < len1 && j < len2) - { - if (left[i] <= right[j]) - { + while (i < len1 && j < len2) { + if (left[i] <= right[j]) { arr[k] = left[i]; i++; - } - else - { + } else { arr[k] = right[j]; j++; } k++; } - + // copy remaining elements of left, if any - while (i < len1) - { + while (i < len1) { arr[k] = left[i]; k++; i++; } - + // copy remaining element of right, if any - while (j < len2) - { + while (j < len2) { arr[k] = right[j]; k++; j++; } + delete[] left; + delete[] right; } - + // iterative Timsort function to sort the array[0...n-1] (similar to merge sort) -void timSort(int arr[], int n) -{ +void timSort(int arr[], int n) { // Sort individual subarrays of size RUN - for (int i = 0; i < n; i+=RUN) - insertionSort(arr, i, min((i+31), (n-1))); - - // start merging from size RUN (or 32). It will merge to form size 64, then 128, 256 and so on .... - for (int size = RUN; size < n; size = 2*size) - { - // pick starting point of left sub array. We are going to merge arr[left..left+size-1] and arr[left+size, left+2*size-1] - // After every merge, we increase left by 2*size - for (int left = 0; left < n; left += 2*size) - { + for (int i = 0; i < n; i += RUN) + insertionSort(arr, i, std::min((i + 31), (n - 1))); + + // start merging from size RUN (or 32). It will merge to form size 64, then + // 128, 256 and so on .... + for (int size = RUN; size < n; size = 2 * size) { + // pick starting point of left sub array. We are going to merge + // arr[left..left+size-1] and arr[left+size, left+2*size-1] After every + // merge, we increase left by 2*size + for (int left = 0; left < n; left += 2 * size) { // find ending point of left sub array // mid+1 is starting point of right sub array int mid = left + size - 1; - int right = min((left + 2*size - 1), (n-1)); - + int right = std::min((left + 2 * size - 1), (n - 1)); + // merge sub array arr[left.....mid] & arr[mid+1....right] merge(arr, left, mid, right); } } } - + // utility function to print the Array -void printArray(int arr[], int n) -{ - for (int i = 0; i < n; i++) - printf("%d ", arr[i]); - printf("\n"); +void printArray(int arr[], int n) { + for (int i = 0; i < n; i++) printf("%d ", arr[i]); + std::cout << std::endl; } - + // Driver program to test above function -int main() -{ +int main() { int arr[] = {5, 21, 7, 23, 19}; - int n = sizeof(arr)/sizeof(arr[0]); + int n = sizeof(arr) / sizeof(arr[0]); printf("Given Array is\n"); printArray(arr, n); - + timSort(arr, n); - + printf("After Sorting Array is\n"); printArray(arr, n); return 0; diff --git a/strings/CMakeLists.txt b/strings/CMakeLists.txt new file mode 100644 index 00000000000..3c15695cc6f --- /dev/null +++ b/strings/CMakeLists.txt @@ -0,0 +1,18 @@ +# If necessary, use the RELATIVE flag, otherwise each source file may be listed +# with full pathname. RELATIVE may makes it easier to extract an executable name +# automatically. +file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp ) +# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) +# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) +foreach( testsourcefile ${APP_SOURCES} ) + # I used a simple string replace, to cut off .cpp. + string( REPLACE ".cpp" "" testname ${testsourcefile} ) + add_executable( ${testname} ${testsourcefile} ) + + set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX) + if(OpenMP_CXX_FOUND) + target_link_libraries(${testname} OpenMP::OpenMP_CXX) + endif() + install(TARGETS ${testname} DESTINATION "bin/strings") + +endforeach( testsourcefile ${APP_SOURCES} ) diff --git a/strings/brute_force_string_searching.cpp b/strings/brute_force_string_searching.cpp index 3288b36b0a9..fd5244b3795 100644 --- a/strings/brute_force_string_searching.cpp +++ b/strings/brute_force_string_searching.cpp @@ -1,52 +1,57 @@ -#include -#include -#include +/** + * @file + * @brief String pattern search - brute force + */ +#include +#ifdef _MSC_VER +#include // use this for MS Visucal C++ +#else +#include +#endif +#include + +namespace string_search { +/** + * Find a pattern in a string by comparing the pattern to every substring. + * @param text Any string that might contain the pattern. + * @param pattern String that we are searching for. + * @return Index where the pattern starts in the text + * @return -1 if the pattern was not found. + */ +int brute_force(const std::string &text, const std::string &pattern) { + size_t pat_l = pattern.length(); + size_t txt_l = text.length(); + int index = -1; + if (pat_l <= txt_l) { + for (size_t i = 0; i < txt_l - pat_l + 1; i++) { + std::string s = text.substr(i, pat_l); + if (s == pattern) { + index = i; + break; + } + } + } + return index; +} +} // namespace string_search -using std::string; +using string_search::brute_force; -int brute_force(string text, string pattern); -std::vector> test_set = { +/** set of test cases */ +const std::vector> test_set = { // {text, pattern, expected output} - {"a", "aa", "-1"}, - {"a", "a", "0"}, - {"ba", "b", "0"}, - {"bba", "bb", "0"}, - {"bbca", "c", "2"}, - {"ab", "b", "1"} -}; + {"a", "aa", "-1"}, {"a", "a", "0"}, {"ba", "b", "0"}, + {"bba", "bb", "0"}, {"bbca", "c", "2"}, {"ab", "b", "1"}}; +/** Main function */ int main() { - for (size_t i = 0 ; i < test_set.size(); i++) { - int output = brute_force(test_set[i][0], test_set[i][1]); - if (std::to_string(output) == test_set[i][2]) - std::cout << "success\n"; + for (size_t i = 0; i < test_set.size(); i++) { + int output = brute_force(test_set[i][0], test_set[i][1]); + + if (std::to_string(output) == test_set[i][2]) + std::cout << "success\n"; else - std::cout << "failure\n"; + std::cout << "failure\n"; } return 0; } - -/* - *@description Find a pattern in a string by comparing the pattern - * to every substring. - *@param text Any string that might contain the pattern. - *@param pattern String that we are searching for. - *@return Index where the pattern starts in the text or - * -1 if the pattern was not found. - */ - -int brute_force(string text, string pattern) { - size_t pat_l = pattern.length(); - size_t txt_l = text.length(); - int index = -1; - if (pat_l <= txt_l) { - for (size_t i = 0; i < txt_l-pat_l+1; i++) { - string s = text.substr(i, pat_l); - if (s == pattern) { - index = i; - break; - } - } - } - return index; -} diff --git a/strings/knuth_morris_pratt.cpp b/strings/knuth_morris_pratt.cpp index f6f1169d30b..d53948d98d1 100644 --- a/strings/knuth_morris_pratt.cpp +++ b/strings/knuth_morris_pratt.cpp @@ -1,64 +1,95 @@ -/* - The Knuth-Morris-Pratt Algorithm for finding a pattern within a piece of text - with complexity O(n + m) - 1) Preprocess pattern to identify any suffixes that are identical to prefixes - This tells us where to continue from if we get a mismatch between a character in our pattern - and the text. - 2) Step through the text one character at a time and compare it to a character in the pattern - updating our location within the pattern if necessary -*/ +/** + * \file + * \brief The [Knuth-Morris-Pratt + * Algorithm](https://en.wikipedia.org/wiki/Knuth–Morris–Pratt_algorithm) for + * finding a pattern within a piece of text with complexity O(n + m) + * + * 1. Preprocess pattern to identify any suffixes that are identical to + * prefixes. This tells us where to continue from if we get a mismatch between a + * character in our pattern and the text. + * 2. Step through the text one character at a time and compare it to a + * character in the pattern updating our location within the pattern if + * necessary + */ -#include -#include -#include -using namespace std; -vector getFailureArray(string pattern){ - int pattern_length=pattern.size(); - vectorfailure(pattern_length+1); - failure[0]=-1; - int j=-1; - for(int i=0; i +#ifdef _MSC_VER +#include // use this for MS Visucal C++ +#else +#include +#endif +#include + +/** \namespace string_search + * \brief String search algorithms + */ +namespace string_search { +/** + * Generate the partial match table aka failure function for a pattern to + * search. + * \param[in] pattern text for which to create the partial match table + * \returns the partial match table as a vector array + */ +std::vector getFailureArray(const std::string &pattern) { + int pattern_length = pattern.size(); + std::vector failure(pattern_length + 1); + failure[0] = -1; + int j = -1; + + for (int i = 0; i < pattern_length; i++) { + while (j != -1 && pattern[j] != pattern[i]) { + j = failure[j]; } j++; - failure[i+1]=j; + failure[i + 1] = j; } return failure; } -bool kmp(string pattern,string text){ - int text_length=text.size(),pattern_length=pattern.size(); - vectorfailure=getFailureArray(pattern); - int k=0; - for(int j=0; j failure = getFailureArray(pattern); + + int k = 0; + for (int j = 0; j < text_length; j++) { + while (k != -1 && pattern[k] != text[j]) { + k = failure[k]; } k++; - if(k==pattern_length)return true; + if (k == pattern_length) + return true; } return false; } +} // namespace string_search -int main() -{ - - string text="alskfjaldsabc1abc1abc12k23adsfabcabc"; - string pattern="abc1abc12l"; - if(kmp(pattern,text)==true){ - cout<<"Found"< -#include -#include -#include +#include +#include +#include +#ifdef _MSC_VER +#include // use this for MS Visucal C++ +#else +#include +#endif -using std::string; -using std::pow; +#define PRIME 5 ///< Prime modulus for hash functions -#define PRIME 5 - -int64_t create_hash(string s , int n) { +namespace string_search { +/** + * convert a string to an intger - called as hashing function + * \param[in] s source of string to hash + * \param[in] n length of substring to hash + * \returns hash integer + */ +int64_t create_hash(const std::string& s, int n) { int64_t result = 0; - for ( int i = 0; i < n; ++i ) { - result += (int64_t)(s[i] * (int64_t)pow(PRIME , i)); + for (int i = 0; i < n; ++i) { + result += (int64_t)(s[i] * (int64_t)pow(PRIME, i)); } return result; } -int64_t recalculate_hash(string s , int old_index , - int new_index , int64_t old_hash , int patLength) { +/** + * re-hash a string using known existing hash + * \param[in] s source of string to hash + * \param[in] old_index previous index of string + * \param[in] new_index new index of string + * \param[in] old_hash previous hash of substring + * \param[in] patLength length of substring to hash + * \returns new hash integer + */ +int64_t recalculate_hash(const std::string& s, int old_index, int new_index, + int64_t old_hash, int patLength) { int64_t new_hash = old_hash - s[old_index]; new_hash /= PRIME; - new_hash += (int64_t)(s[new_index]*(int64_t)pow(PRIME, patLength-1)); + new_hash += (int64_t)(s[new_index] * (int64_t)pow(PRIME, patLength - 1)); return new_hash; } -bool check_if_equal(string str1 , string str2 , - int start1 , int end1 , - int start2 , int end2) { - if (end1-start1 != end2-start2) { +/** + * compare if two sub-strings are equal + * \param[in] str1 string pattern to search + * \param[in] str2 text in which to search + * \param[in] start1,end1 start and end indices for substring in str1 + * \param[in] start2,end2 start and end indices for substring in str2 + * \returns `true` if pattern was found + * \returns `false` if pattern was not found + * @note can this be replaced by std::string::compare? + */ +bool check_if_equal(const std::string& str1, const std::string& str2, + int start1, int end1, int start2, int end2) { + if (end1 - start1 != end2 - start2) { return false; } while (start1 <= end1 && start2 <= end2) { @@ -46,33 +72,40 @@ bool check_if_equal(string str1 , string str2 , return true; } -/* - * @description : search pattern in the given text - * @param : string str - * @param : string pat - * @return index of first occurrence of pattern or -1 if pattern not found +/** + * Perform string pattern search using Rabin-Karp algorithm + * @param[in] str string to search in + * @param[in] pat pattern to search for + * @return index of first occurrence of pattern + * @return -1 if pattern not found */ -int rabin_karp(const string &str , const string& pat) { - int64_t pat_hash = create_hash(pat , pat.size()); - int64_t str_hash = create_hash(str , pat.size()); - for (int i=0; i <= str.size()-pat.size(); ++i) { +int rabin_karp(const std::string& str, const std::string& pat) { + int64_t pat_hash = create_hash(pat, pat.size()); + int64_t str_hash = create_hash(str, pat.size()); + for (int i = 0; i <= str.size() - pat.size(); ++i) { if (pat_hash == str_hash && - check_if_equal(str , pat , i , i+pat.size()-1 , 0 , pat.size()-1)) { - return i; + check_if_equal(str, pat, i, i + pat.size() - 1, 0, + pat.size() - 1)) { + return i; } - if (i < str.size()-pat.size()) { + if (i < str.size() - pat.size()) { str_hash = - recalculate_hash(str, i, i+pat.size(), str_hash, pat.size()); + recalculate_hash(str, i, i + pat.size(), str_hash, pat.size()); } } return -1; // return -1 if given pattern not found } +} // namespace string_search + +using string_search::rabin_karp; + +/** Main function */ int main(void) { - assert(rabin_karp("helloWorld", "world") == -1); - assert(rabin_karp("helloWorld", "World") == 5); - assert(rabin_karp("this_is_c++" , "c++") == 8); - assert(rabin_karp("happy_coding", "happy") == 0); + assert(rabin_karp("helloWorld", "world") == -1); + assert(rabin_karp("helloWorld", "World") == 5); + assert(rabin_karp("this_is_c++", "c++") == 8); + assert(rabin_karp("happy_coding", "happy") == 0); return 0; }