id int64 0 755k | file_name stringlengths 3 109 | file_path stringlengths 13 185 | content stringlengths 31 9.38M | size int64 31 9.38M | language stringclasses 1
value | extension stringclasses 11
values | total_lines int64 1 340k | avg_line_length float64 2.18 149k | max_line_length int64 7 2.22M | alphanum_fraction float64 0 1 | repo_name stringlengths 6 65 | repo_stars int64 100 47.3k | repo_forks int64 0 12k | repo_open_issues int64 0 3.4k | repo_license stringclasses 9
values | repo_extraction_date stringclasses 92
values | exact_duplicates_redpajama bool 2
classes | near_duplicates_redpajama bool 2
classes | exact_duplicates_githubcode bool 2
classes | exact_duplicates_stackv2 bool 1
class | exact_duplicates_stackv1 bool 2
classes | near_duplicates_githubcode bool 2
classes | near_duplicates_stackv1 bool 2
classes | near_duplicates_stackv2 bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
10,095 | problem_026.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_026/problem_026.cpp | #include <iostream>
#include <vector>
int main()
{
int remainder, value, position, sequenceLength = 0;
for (int i = 1000; i > 0; --i)
{
std::vector<int> cycleCheckArray;
for (int j = 0; j < i; ++j)
cycleCheckArray.push_back(0);
remainder = 1, value = 1, position = 0;
... | 772 | C++ | .cpp | 28 | 18.607143 | 71 | 0.497965 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,096 | problem_017.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_017/problem_017.cpp | #include <bits/stdc++.h>
using namespace std;
int num_letters_func(int n)
{
int num_letters[91];
num_letters[1] = 3;
num_letters[2] = 3;
num_letters[3] = 5;
num_letters[4] = 4;
num_letters[5] = 4;
num_letters[6] = 3;
num_letters[7] = 5;
num_letters[8] = 5;
num_letters[9] = 4;
... | 1,530 | C++ | .cpp | 75 | 14.493333 | 55 | 0.475568 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,098 | problem_037.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_037/problem_037.cpp | #include <array>
#include <cmath>
#include <iostream>
template<std::size_t N>
std::array<bool, N> primesUpto() // Function that implements the Sieve of Eratosthenes
{
std::array<bool, N> primesList;
std::fill(primesList.begin(), primesList.end(), true);
primesList[0] = primesList[1] = false;
std::si... | 1,931 | C++ | .cpp | 45 | 36.955556 | 109 | 0.6512 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,099 | problem_028.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_028/problem_028.cpp | #include <iostream>
#include <cmath>
bool isPerfectSquare(int num)
{
int sqrtNum = static_cast<int>(std::sqrt(num));
return sqrtNum * sqrtNum == num;
}
int main()
{
int limit = 1001 * 1001;
int incrementRate = 0;
int diagonalNumberSum = 0;
for (int i = 1; i <= limit; i += incrementRate) // Ite... | 715 | C++ | .cpp | 22 | 26.318182 | 89 | 0.588406 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,100 | problem_027.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_027/problem_027.cpp | #include <bits/stdc++.h>
using namespace std;
bool isPrime(int n)
{
bool ans = true;
for(int i = 2; i * i <= n; i++)
{
if(n % i == 0)
{
ans = false;
break;
}
}
return ans;
}
int main()
{
int max_primes = 0;
int prod;
for(int a = -999; a <... | 691 | C++ | .cpp | 37 | 10.918919 | 70 | 0.340491 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,102 | problem_002.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_002/problem_002.cpp | #include <iostream>
int main()
{
// Variables to keep track of Fibonacci numbers
int p2 = 0;
int p1 = 0;
int current = 1;
int sum = 0;
while (current <= 4000000)
{
// Add even fibonacci numbers
sum += (current % 2 == 0) ? current : 0;
// Update fibonacci numbers
... | 424 | C++ | .cpp | 19 | 16.631579 | 51 | 0.5225 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,105 | problem_005.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_005/problem_005.cpp | #include <iostream>
int main()
{
int d = 1;
while (!(
(d % 11 == 0) &&
(d % 12 == 0) &&
(d % 13 == 0) &&
(d % 14 == 0) &&
(d % 15 == 0) &&
(d % 16 == 0) &&
(d % 17 == 0) &&
(d % 18 == 0) &&
... | 443 | C++ | .cpp | 19 | 12.421053 | 31 | 0.194774 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,106 | problem_003.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_003/problem_003.cpp | #include <iostream>
#include <vector>
#include <cmath>
int main()
{
long long int n = 600851475143;
long long int h = 0;
long long int c = 2;
while (n != 1)
{
if ((n % c == 0) && (c > h))
{
h = c;
n /= c;
}
++c;
}
std::cout << h << "\... | 326 | C++ | .cpp | 19 | 11.631579 | 36 | 0.409836 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,107 | problem_034.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_034/problem_034.cpp | #include <iostream>
#include <vector>
int factorial (std::size_t n)
{
int fact = 1;
for (std::size_t i = 1; i <= n; ++i)
fact *= i;
return fact;
}
int main()
{
std::vector<int> factorials(10);
constexpr std::size_t maxDigitFactorial = 2540162;
for (int i = 0; i < 10; ++i)
facto... | 643 | C++ | .cpp | 27 | 18.444444 | 54 | 0.509772 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,108 | problem_025.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_025/problem_025.cpp | #include <iostream>
#include <vector>
int main()
{
std::vector<int> prevFibonacci, currFibonacci;
prevFibonacci.reserve(1000);
currFibonacci.reserve(1000);
int count = 2;
prevFibonacci.push_back(1);
currFibonacci.push_back(1);
while (currFibonacci.size() < 1000)
{
std::vector<i... | 994 | C++ | .cpp | 33 | 22.848485 | 79 | 0.562893 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,109 | test_list.cpp | OpenGenus_cosmos/code/data_structures/test/list/test_list.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*
* test lists for std::list-like
*/
#define CATCH_CONFIG_MAIN
#ifndef XOR_LINKED_LIST_TEST_CPP
#define XOR_LINKED_LIST_TEST_CPP
#include "../../../../test/c++/catch.hpp"
#include "../../src/list/xor_linked_list/xor_linked_list.cpp"
#include <iostream>
#include <list>
#... | 81,597 | C++ | .cpp | 1,828 | 28.765864 | 100 | 0.489983 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,110 | test_bag.cpp | OpenGenus_cosmos/code/data_structures/test/bag/test_bag.cpp | //Needed for random and vector
#include <vector>
#include <string>
#include <cstdlib>
#include <iostream>
using std::cout;
using std::endl;
using std::string;
using std::vector;
//Bag Class Declaration
class Bag
{
private:
vector<string> items;
int bagSize;
public:
Bag();
void add(string);... | 2,159 | C++ | .cpp | 93 | 20.11828 | 61 | 0.606686 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,111 | test_generic_segment_tree.cpp | OpenGenus_cosmos/code/data_structures/test/tree/segment_tree/test_generic_segment_tree.cpp | #include <algorithm>
#include <iostream>
#include <vector>
// Note that the below line includes a translation unit and not header file
#include "../../../src/tree/segment_tree/generic_segment_tree.cpp"
#define ASSERT(value, expected_value, message) \
{ ... | 5,506 | C++ | .cpp | 102 | 50.137255 | 117 | 0.660216 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,112 | test_union_find.cpp | OpenGenus_cosmos/code/data_structures/test/tree/multiway_tree/union_find/test_union_find.cpp | #include <iostream>
#include <cassert>
#include "../../../../src/tree/multiway_tree/union_find/union_find_dynamic.cpp"
int main()
{
UnionFind<int> unionFind;
unionFind.merge(3, 4);
unionFind.merge(3, 8);
unionFind.merge(0, 8);
unionFind.merge(1, 3);
unionFind.merge(7, 9);
unionFind.merge(5... | 1,513 | C++ | .cpp | 45 | 29.044444 | 79 | 0.662338 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,113 | test_is_same.cpp | OpenGenus_cosmos/code/data_structures/test/tree/binary_tree/binary_tree/is_same/test_is_same.cpp | #define CATCH_CONFIG_MAIN
#ifndef TEST_TREE_COMPARER
#define TEST_TREE_COMPARER
#include <memory>
#include <functional>
#include <utility>
#include "../../../../../../../test/c++/catch.hpp"
#include "../../../../../src/tree/binary_tree/binary_tree/is_same/is_same.cpp"
#include "../../../../../src/tree/binary_tree/bina... | 4,291 | C++ | .cpp | 90 | 40.133333 | 84 | 0.595363 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,114 | test_path_sum_for_sum_of_whole_paths.cpp | OpenGenus_cosmos/code/data_structures/test/tree/binary_tree/binary_tree/path_sum/test_path_sum_for_sum_of_whole_paths.cpp | #define CATCH_CONFIG_MAIN
#include "../../../../../../../test/c++/catch.hpp"
#include <vector>
#include <memory>
#include <queue>
#include "../../../../../src/tree/binary_tree/binary_tree/node/node.cpp"
#include "../../../../../src/tree/binary_tree/binary_tree/serializer/serializer.cpp"
#include "../../../../../src/tre... | 5,643 | C++ | .cpp | 179 | 18.681564 | 84 | 0.3277 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,115 | test_path_sum_for_whole_paths.cpp | OpenGenus_cosmos/code/data_structures/test/tree/binary_tree/binary_tree/path_sum/test_path_sum_for_whole_paths.cpp | #define CATCH_CONFIG_MAIN
#include "../../../../../../../test/c++/catch.hpp"
#include <vector>
#include <memory>
#include <queue>
#include "../../../../../src/tree/binary_tree/binary_tree/node/node.cpp"
#include "../../../../../src/tree/binary_tree/binary_tree/serializer/serializer.cpp"
#include "../../../../../src/tre... | 12,284 | C++ | .cpp | 360 | 23.691667 | 98 | 0.427695 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,116 | test_path_sum_for_sum_of_part_paths.cpp | OpenGenus_cosmos/code/data_structures/test/tree/binary_tree/binary_tree/path_sum/test_path_sum_for_sum_of_part_paths.cpp | #define CATCH_CONFIG_MAIN
#include "../../../../../../../test/c++/catch.hpp"
#include <vector>
#include <memory>
#include <queue>
#include "../../../../../src/tree/binary_tree/binary_tree/node/node.cpp"
#include "../../../../../src/tree/binary_tree/binary_tree/serializer/serializer.cpp"
#include "../../../../../src/tre... | 8,833 | C++ | .cpp | 261 | 23.436782 | 84 | 0.392276 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,117 | test_diameter.cpp | OpenGenus_cosmos/code/data_structures/test/tree/binary_tree/binary_tree/diameter/test_diameter.cpp | #define CATCH_CONFIG_MAIN
#include "../../../../../../../test/c++/catch.hpp"
#include "../../../../../src/tree/binary_tree/binary_tree/serializer/serializer.cpp"
#include "../../../../../src/tree/binary_tree/binary_tree/node/node.cpp"
#include "../../../../../src/tree/binary_tree/binary_tree/diameter/diameter.cpp"
#inc... | 1,840 | C++ | .cpp | 63 | 21.47619 | 84 | 0.370977 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,118 | maxHeap.cpp | OpenGenus_cosmos/code/data_structures/src/maxHeap/maxHeap.cpp |
#include "maxHeap.h"
using namespace std;
void maxHeap::heapifyAdd(int idx)
{
int root = (idx-1)/2;
if(heap[idx]>heap[root])
{
int temp = heap[root];
heap[root] = heap[idx];
heap[idx] = temp;
heapifyAdd(root);
}
}
void maxHeap::heapifyRemove(int idx)
{
int max = id... | 1,211 | C++ | .cpp | 64 | 14.3125 | 52 | 0.576049 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,119 | minqueue.cpp | OpenGenus_cosmos/code/data_structures/src/minqueue/minqueue.cpp | #include <deque>
#include <iostream>
using namespace std;
//this is so the minqueue can be used with different types
//check out the templeting documentation for more info about this
//This version of minqueue is built upon the deque data structure
template <typename T>
class MinQueue {
public:
MinQueue() {}
... | 1,988 | C++ | .cpp | 71 | 21.492958 | 99 | 0.556609 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,120 | doublylinkedlist.cpp | OpenGenus_cosmos/code/data_structures/src/DoubleLinkedList/src_cpp/doublylinkedlist.cpp | #include <iostream>
class Node {
public:
int data;
Node* next;
Node* prev;
Node(int val) {
data = val;
next = prev = nullptr;
}
};
class DoublyLinkedList {
private:
Node* head;
Node* tail;
public:
DoublyLinkedList() {
head = tail = nullptr;
}
// I... | 2,082 | C++ | .cpp | 83 | 16.26506 | 56 | 0.469789 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,121 | Doubly_LL.cpp | OpenGenus_cosmos/code/data_structures/src/DoubleLinkedList/src_c++/Doubly_LL.cpp | #include <iostream>
using namespace std;
struct Node {
int data;
Node* prev;
Node* next;
Node(int value) : data(value), prev(nullptr), next(nullptr) {}
};
class DoublyLinkedList {
private:
Node* head;
Node* tail;
public:
DoublyLinkedList() : head(nullptr), tail(nul... | 1,934 | C++ | .cpp | 73 | 18.109589 | 67 | 0.489303 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,122 | DisjointSet(DS).cpp | OpenGenus_cosmos/code/data_structures/src/disjoint_set/DisjointSet(DS).cpp | #include <iostream>
using namespace std;
int f[100];
int find(int node)
{
if(f[node] == node){
return node;
}
return f[node] = find(f[node]); //path compression
}
int union_set(int x,int y)
{
return f[find(x)]=find(y);
}
int main()
{
int arr[10];
for(int i=1;i<=10;i++){
arr[i - 1] = i;
f[i] = i;
}
... | 555 | C++ | .cpp | 35 | 13.828571 | 51 | 0.58317 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,123 | sparse_table.cpp | OpenGenus_cosmos/code/data_structures/src/sparse_table/sparse_table.cpp | /* Part of Cosmos by OpenGenus Foundation */
#include <iostream>
#include <cassert>
#include <functional>
#include <iomanip>
#include <cmath>
template<typename T, std::size_t S>
class SparseTable
{
public:
/*!
* \brief Builds a sparse table from a set of static data. It is the user responsibility to delete a... | 4,022 | C++ | .cpp | 114 | 28.114035 | 136 | 0.552482 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,124 | circularLinkedList.cpp | OpenGenus_cosmos/code/data_structures/src/CircularLinkedList/circularLinkedList.cpp | #include <iostream>
using namespace std;
/**
* A node will be consist of a int data &
* a reference to the next node.
* The node object will be used in making linked list
*/
class Node
{
public:
int data;
Node *next;
};
/**
* Using nodes for creating a circular linked list.
*
*/
class CircularList
{
pu... | 4,663 | C++ | .cpp | 212 | 13.811321 | 61 | 0.462616 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,125 | infix_to_postfix2.cpp | OpenGenus_cosmos/code/data_structures/src/stack/infix_to_postfix/infix_to_postfix2.cpp | #include <iostream>
#include <stack>
class InfixToPostfix
{
public:
InfixToPostfix(const std::string &expression) : expression_(expression) {}
int getPrecedenceOfOperators(char);
std::string convertInfixToPostfix();
private:
std::string expression_;
};
int InfixToPostfix::getPrecedenceOfOperators(... | 3,860 | C++ | .cpp | 113 | 23.59292 | 139 | 0.504418 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,127 | balanced_expression.cpp | OpenGenus_cosmos/code/data_structures/src/stack/balanced_expression/balanced_expression.cpp | // Stack | Balance paraenthesis | C++
// Part of Cosmos by OpenGenus Foundation
#include <iostream>
#include <stack>
bool checkBalanced(string s)
{
// if not in pairs, then not balanced
if (s.length() % 2 != 0)
return false;
std::stack <char> st;
for (const char: s)
{
//adding open... | 1,149 | C++ | .cpp | 42 | 20 | 89 | 0.488225 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,128 | stack_using_queue.cpp | OpenGenus_cosmos/code/data_structures/src/stack/stack_using_queue/stack_using_queue.cpp | /**
* @brief Stack Data Structure Using the Queue Data Structure
* @details
* Using 2 Queues inside the Stack class, we can easily implement Stack
* data structure with heavy computation in push function.
*
* Part of Cosmos by OpenGenus Foundation
*/
#include <iostream>
#include <queue>
#include <cassert>
u... | 2,379 | C++ | .cpp | 87 | 23.724138 | 94 | 0.660009 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,130 | array_stack.cpp | OpenGenus_cosmos/code/data_structures/src/stack/abstract_stack/cpp/array_stack/array_stack.cpp |
#include <iostream>
#include "../istack.h"
#include "arraystack.h"
int main()
{
int s;
IStack<int> *stack = new ArrayStack<int>();
try {
stack->peek();
} catch (char const *e)
{
std::cout << e << std::endl << std::endl;
}
stack->push(20);
std::cout << "Added 20" << s... | 953 | C++ | .cpp | 31 | 25.870968 | 87 | 0.532967 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,132 | infix_to_prefix.cpp | OpenGenus_cosmos/code/data_structures/src/stack/infix_to_prefix/infix_to_prefix.cpp | // Including Library
#include <iostream>
#include <ctype.h>
#include <string.h>
#include <stack>
/** Function to check if given character is
an operator or not. **/
bool isOperator(char c)
{
return (!isalpha(c) && !isdigit(c));
}
/** Function to find priority of given
operator.**/
int getPriority(char c)
... | 3,645 | C++ | .cpp | 121 | 21.099174 | 97 | 0.514115 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,133 | quick_sort.cpp | OpenGenus_cosmos/code/data_structures/src/stack/Quick_sort_usingSack/quick_sort.cpp | #include <iostream>
#include <stack>
using namespace std;
int arr[] = {4, 1, 5, 3, 50, 30, 70, 80, 28, 22};
stack<int> higherStack, lowerStack;
void displayArray();
void quick_sort(int lower, int higher);
void partition(int lower, int higher);
int main()
{
lowerStack.push(0);
higherStack.push(9);
quick_s... | 1,250 | C++ | .cpp | 60 | 15.883333 | 56 | 0.548688 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,137 | sort_stack.cpp | OpenGenus_cosmos/code/data_structures/src/stack/sort_stack/sort_stack.cpp | /* Part of Cosmos by OpenGenus Foundation */
/* Sort a stack */
#include <iostream>
#include <stack>
using namespace std;
void InputElements(stack<int> &s) //////////// Function to insert the elements in stack
{ //no. of elements to be inserted
int size;
cin >> size;
while (size--)
{
... | 1,356 | C++ | .cpp | 59 | 18.745763 | 118 | 0.566461 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,139 | xor_linked_list.cpp | OpenGenus_cosmos/code/data_structures/src/list/xor_linked_list/xor_linked_list.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*
* xor linked list synopsis
*
*** incomplete ***
***
***Begin *** Iterator invalidation rules are NOT applicable. ***
***[x] Insertion: all iterators and references unaffected.
***[x] Erasure: only the iterators and references to the erased element is invalidated.
... | 18,775 | C++ | .cpp | 738 | 21.276423 | 92 | 0.672438 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,140 | doubly_linked_list.cpp | OpenGenus_cosmos/code/data_structures/src/list/doubly_linked_list/doubly_linked_list.cpp | /* Part of Cosmos by OpenGenus Foundation */
/* Contributed by Vaibhav Jain (vaibhav29498) */
#include <iostream>
#include <cstdlib>
using namespace std;
template <typename T>
struct node
{
T info;
node* pre; // Holds the pointer to the previous node
node* next; // Holds the pointer to the next node
n... | 6,109 | C++ | .cpp | 232 | 19.125 | 105 | 0.525947 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | true | false | false |
10,142 | singly_linked_list.cpp | OpenGenus_cosmos/code/data_structures/src/list/singly_linked_list/singly_linked_list.cpp | #include "singly_linked_list.h"
int main()
{
Linkedlist<int> link;
for (int i = 10; i > 0; --i)
link.rearAdd(i);
link.print();
std::cout << link.size() << std::endl;
Linkedlist<int> link1(link);
link1 = link1;
link1.print();
link1.deletePos(100);
link1.modify(5, 100);
li... | 633 | C++ | .cpp | 25 | 20.68 | 56 | 0.593388 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,143 | singly_linked_list_with_classes.cpp | OpenGenus_cosmos/code/data_structures/src/list/singly_linked_list/singly_linked_list_with_classes.cpp | #include <iostream>
class Node {
private:
int _data;
Node *_next;
public:
Node()
{
}
void setData(int Data)
{
_data = Data;
}
void setNext(Node *Next)
{
if (Next == NULL)
_next = NULL;
else
_next = Next;
}
int Data()
{
... | 2,217 | C++ | .cpp | 110 | 15.090909 | 74 | 0.558683 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,144 | rotate.cpp | OpenGenus_cosmos/code/data_structures/src/list/singly_linked_list/operations/rotate/rotate.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*/
#include <iostream>
//Definition for singly-linked list.
struct ListNode
{
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL)
{
}
};
ListNode* rotate(ListNode* A, int B)
{
int t = 0;
ListNode* temp = A;
ListNode* prev2 = NULL... | 1,433 | C++ | .cpp | 62 | 18.048387 | 110 | 0.512088 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,150 | linked_list_operations.cpp | OpenGenus_cosmos/code/data_structures/src/list/singly_linked_list/operations/unclassified/linked_list_operations.cpp |
#include <iostream>
using namespace std;
//built node .... node = (data and pointer)
struct node
{
int data; //data item
node* next; //pointer to next node
};
//built linked list
class linkedlist
{
private:
node* head; //pointer to the first node
public:
linkedlist() //constructor
... | 5,091 | C++ | .cpp | 164 | 25.640244 | 133 | 0.572014 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,151 | rotate_a_linked_list_by_k_nodes.cpp | OpenGenus_cosmos/code/data_structures/src/list/singly_linked_list/operations/rotate_a_linked_list_by_k_nodes/rotate_a_linked_list_by_k_nodes.cpp | // C++ program to rotate a linked list counter clock wise by k Nodes
// where k can be greater than length of linked list
#include <iostream>
class Node {
public:
int data;
Node *next;
Node(int d): next(nullptr),data(d) {
}
};
Node *insert() {
// no. of values to insert
std::... | 2,742 | C++ | .cpp | 102 | 20.490196 | 84 | 0.52144 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,152 | detect_cycle.cpp | OpenGenus_cosmos/code/data_structures/src/list/singly_linked_list/operations/detect_cycle/detect_cycle.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*/
#include <iostream>
using namespace std;
// Singly-Linked List Defined
struct Node
{
int data;
Node* next;
Node(int val)
{
data = val;
next = NULL;
}
};
//Function to add nodes to the linked list
Node* TakeInput(int n)
{
Node* hea... | 2,265 | C++ | .cpp | 93 | 19.053763 | 97 | 0.57308 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,153 | nth_node_linked_list.cpp | OpenGenus_cosmos/code/data_structures/src/list/singly_linked_list/operations/nth_node_linked_list/nth_node_linked_list.cpp | ///
/// Part of Cosmos by OpenGenus Foundation
/// Contributed by: Pranav Gupta (foobar98)
/// Print Nth node of a singly linked list in the reverse manner
///
#include <iostream>
using namespace std;
// Linked list node
struct Node
{
public:
int data;
Node *next;
Node(int data)
{
this->data... | 1,629 | C++ | .cpp | 78 | 15.846154 | 64 | 0.548177 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,154 | merge_sorted.cpp | OpenGenus_cosmos/code/data_structures/src/list/singly_linked_list/operations/merge_sorted/merge_sorted.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*/
#include <iostream>
using namespace std;
//Definition for singly-linked list.
struct ListNode
{
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL)
{
}
};
//Merge Function for linkedlist
ListNode* merge(ListNode* head1, ListNode* hea... | 2,323 | C++ | .cpp | 107 | 15.280374 | 72 | 0.516129 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,157 | skip_list.cpp | OpenGenus_cosmos/code/data_structures/src/list/skip_list/skip_list.cpp | /**
* skip list C++ implementation
*
* Average Worst-case
* Space O(n) O(n log n)
* Search O(log n) 0(n)
* Insert O(log n) 0(n)
* Delete O(log n) 0(n)
* Part of Cosmos by OpenGenus Foundation
*/
#include <algorithm> // std::less, std::max
#include <cassert> // ass... | 5,299 | C++ | .cpp | 206 | 18.320388 | 73 | 0.468849 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,159 | is_circular_linked_list.cpp | OpenGenus_cosmos/code/data_structures/src/list/circular_linked_list/operations/is_circular_linked_list.cpp | #include <iostream>
using namespace std;
//node structure
struct node{
int data;
struct node* next;
};
//function to find the circular linked list.
bool isCircular(node *head){
node *temp=head;
while(temp!=NULL)
{ //if temp points to head then it has completed a circle,thus a circular linked list.
... | 1,029 | C++ | .cpp | 44 | 18.704545 | 90 | 0.629213 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,160 | FloydAlgo_circular_ll.cpp | OpenGenus_cosmos/code/data_structures/src/list/circular_linked_list/operations/FloydAlgo_circular_ll.cpp | #include <iostream>
using namespace std;
struct node{
int data;
struct node* next;
};
bool isCircular(node *head)
{ //fast ptr is ahead of slow pointer
node* slow,*fast;
slow=head;
fast=head->next;
//if linked list is empty it returns true as its entirely null.
if(head==NULL)
return... | 1,550 | C++ | .cpp | 59 | 20.050847 | 92 | 0.597176 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,161 | bloom_filter.cpp | OpenGenus_cosmos/code/data_structures/src/hashs/bloom_filter/bloom_filter.cpp | #include <iostream>
using namespace std;
class BloomFilter
{
public:
BloomFilter(int size)
{
size_ = size;
bits_ = new char[size_ / 8 + 1];
}
~BloomFilter()
{
delete [] bits_;
}
void Add(int value)
{
int hash = value % size_;
bits_[hash / 8] |= 1... | 1,047 | C++ | .cpp | 44 | 18.5 | 80 | 0.574447 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,162 | hash_table.cpp | OpenGenus_cosmos/code/data_structures/src/hashs/hash_table/hash_table.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*
* hash_table synopsis
*
* template<typename _Tp, typename _HashFunc = std::hash<_Tp> >
* class hash_table {
* public:
* typedef _Tp value_type;
* typedef decltype (_HashFunc ().operator()(_Tp())) key_type;
* typedef s... | 5,711 | C++ | .cpp | 207 | 23.942029 | 96 | 0.590917 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,163 | rotate_matrix.cpp | OpenGenus_cosmos/code/data_structures/src/2d_array/rotate_matrix.cpp | //#rotate square matrix by 90 degrees
#include <bits/stdc++.h>
#define n 5
using namespace std;
void displayimage(
int arr[n][n]);
/* A function to
* rotate a n x n matrix
* by 90 degrees in
* anti-clockwise direction */
void rotateimage(int arr[][n])
{ // Performing Transpose
for (int i = 0; i < n; i++)
... | 1,601 | C++ | .cpp | 64 | 21.03125 | 177 | 0.383706 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,164 | SpiralMatrix.cpp | OpenGenus_cosmos/code/data_structures/src/2d_array/SpiralMatrix.cpp | #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> generateSpiralMatrix(int n) {
vector<vector<int>> matrix(n, vector<int>(n));
int left = 0;
int right = n - 1;
int top = 0;
int bottom = n - 1;
int direction = 0;
int value = 1;
while (left <= right && top ... | 1,323 | C++ | .cpp | 49 | 18.571429 | 63 | 0.435229 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,165 | set_matrix_zero.cpp | OpenGenus_cosmos/code/data_structures/src/2d_array/set_matrix_zero.cpp | #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <unordered_map>
#include <numeric>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int int64_t
int gcd(int a, int b)
{
if (b == 0)
return a;
... | 1,888 | C++ | .cpp | 82 | 14.963415 | 58 | 0.4132 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,167 | bag.cpp | OpenGenus_cosmos/code/data_structures/src/bag/bag.cpp | //Needed for random and vector
#include <vector>
#include <string>
#include <cstdlib>
using std::string;
using std::vector;
//Bag Class Declaration
class Bag
{
private:
vector<string> items;
int bagSize;
public:
Bag();
void add(string);
bool isEmpty();
int sizeOfBag();
string remove();
... | 2,210 | C++ | .cpp | 75 | 26.533333 | 81 | 0.414657 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,170 | queue_vector.cpp | OpenGenus_cosmos/code/data_structures/src/queue/queue/queue_vector.cpp | #include <iostream>
#include <vector>
using namespace std;
// Part of Cosmos by OpenGenus Foundation
class Queue
{
private:
// Vector for storing all of the values
vector<int> _vec;
public:
void enqueue(int & p_put_obj); // Puts object at the end of the queue
void dequeue(int & p_ret_obj); // Returns obje... | 2,075 | C++ | .cpp | 64 | 29.1875 | 104 | 0.65 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,171 | queue.cpp | OpenGenus_cosmos/code/data_structures/src/queue/queue/queue.cpp | /* Part of Cosmos by OpenGenus Foundation */
#include <iostream>
#include <cassert>
template <typename T>
class Queue {
private:
int m_f;
int m_r;
std::size_t m_size;
T * m_data;
public:
/*! \brief Constructs queue object with size.
* \param sz Size of the queue.
*/
Queue( std::size_t sz = 10... | 3,076 | C++ | .cpp | 130 | 17.138462 | 73 | 0.486644 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,172 | queue_using_stack.cpp | OpenGenus_cosmos/code/data_structures/src/queue/queue_using_stack/queue_using_stack.cpp | #include <iostream>
#include <stack>
using namespace std;
// Part of Cosmos by OpenGenus Foundation
// queue data structure using two stacks
class queue {
private:
stack<int> s1, s2;
public:
void enqueue(int element);
int dequeue();
void displayQueue();
};
// enqueue an element to the queue
void queue ... | 1,731 | C++ | .cpp | 85 | 14.835294 | 81 | 0.52474 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,173 | deque_library_function.cpp | OpenGenus_cosmos/code/data_structures/src/queue/double_ended_queue/deque_library_function.cpp | #include <iostream>
#include <deque>
using namespace std;
void showdq (deque <int> g)
{
deque <int> :: iterator it; // Iterator to iterate over the deque .
for (it = g.begin(); it != g.end(); ++it)
cout << '\t' << *it;
cout << "\n";
}
int main ()
{
deque <int... | 1,132 | C++ | .cpp | 44 | 18.068182 | 103 | 0.443721 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,177 | LazySegmentTree.cpp | OpenGenus_cosmos/code/data_structures/src/tree/segment_tree/LazySegmentTree.cpp | // There are generally three main function for lazy propagation in segment tree
// Lazy propagation is used when we have range update query too, without it only point
// update is possible.
// Build function
// THE SEGMENT TREE WRITTEN HERE IS FOR GETTING SUM , FOR MINIMUM, MAXIMUM, XOR AND DISTINCT ELEMENT COUNT RE... | 3,653 | C++ | .cpp | 107 | 30.542056 | 150 | 0.627457 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,178 | generic_segment_tree.cpp | OpenGenus_cosmos/code/data_structures/src/tree/segment_tree/generic_segment_tree.cpp | /**
* @file generic_segment_tree.cpp
* @author Aryan V S (https://github.com/a-r-r-o-w)
* @brief Implementation of a Generic Segment Tree
*/
namespace arrow {
/**
* @brief Support for two tree memory layouts is provided
*
* Binary:
* - creates the segment tree as a full Binary tree
... | 15,299 | C++ | .cpp | 346 | 33.083815 | 120 | 0.568173 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,179 | segment_tree_optimized.cpp | OpenGenus_cosmos/code/data_structures/src/tree/segment_tree/segment_tree_optimized.cpp | // Program to show optimised segment tree operations like construction, sum query and update
#include <iostream>
using namespace std;
/*Parameters for understanding code easily:
N = size of the array for which we are making the segment tree
arr= Given array, it can be of any size
tree=Array for the segment tree repres... | 2,487 | C++ | .cpp | 78 | 26.846154 | 98 | 0.601166 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,180 | union_find_dynamic.cpp | OpenGenus_cosmos/code/data_structures/src/tree/multiway_tree/union_find/union_find_dynamic.cpp | /* Part of Cosmos by OpenGenus Foundation */
// Union-find stores a graph, and allows two operations in amortized constant time:
// * Add a new edge between two vertices.
// * Check if two vertices belong to same component.
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
// dynamic union find ... | 2,324 | C++ | .cpp | 80 | 21.3625 | 83 | 0.541573 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,181 | union_find.cpp | OpenGenus_cosmos/code/data_structures/src/tree/multiway_tree/union_find/union_find.cpp | #include <iostream>
#include <vector>
/* Part of Cosmos by OpenGenus Foundation */
// Union-find stores a graph, and allows two operations in amortized constant time:
// * Add a new edge between two vertices.
// * Check if two vertices belong to same component.
class UnionFind {
std::vector<size_t> parent;
st... | 1,901 | C++ | .cpp | 75 | 18.813333 | 92 | 0.521212 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,182 | splay_tree.cpp | OpenGenus_cosmos/code/data_structures/src/tree/multiway_tree/splay_tree/splay_tree.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*
* splay tree synopsis
*
* template<typename _Type, class _Derivative>
* class Node
* {
* protected:
* using SPNodeType = std::shared_ptr<_Derivative>;
* using ValueType = _Type;
*
* public:
* Node(ValueType v, SPNodeType l = nullptr, SPNodeType r = nullptr);... | 11,729 | C++ | .cpp | 485 | 17.529897 | 96 | 0.512823 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,183 | fenwick_tree.cpp | OpenGenus_cosmos/code/data_structures/src/tree/multiway_tree/fenwick_tree/fenwick_tree.cpp | /* Part of Cosmos by OpenGenus Foundation */
#include <iostream>
#include <vector>
using namespace std;
// Fenwick Tree (also known as Binary Indexed Tree or BIT)
class BIT
{
public:
int n;
vector<int> arr;
// constructor: initializes variables
BIT(int n)
{
this->n = n;
arr.resize(n +... | 1,362 | C++ | .cpp | 57 | 18.421053 | 72 | 0.542504 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,184 | fenwick_tree_inversion_count.cpp | OpenGenus_cosmos/code/data_structures/src/tree/multiway_tree/fenwick_tree/fenwick_tree_inversion_count.cpp | #include <iostream>
#include <cstring>
using namespace std;
int BIT[101000], A[101000], n;
int query(int i)
{
int ans = 0;
for (; i > 0; i -= i & (-i))
ans += BIT[i];
return ans;
}
void update(int i)
{
for (; i <= n; i += i & (-i))
BIT[i]++;
}
int main()
{
int ans, i;
while (ci... | 637 | C++ | .cpp | 34 | 13.441176 | 48 | 0.414309 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,185 | red_black_tree.test.cpp | OpenGenus_cosmos/code/data_structures/src/tree/multiway_tree/red_black_tree/red_black_tree.test.cpp | #include "red_black_tree.cpp"
void
test()
{
std::shared_ptr<RBTree<int>> rbt;
rbt = make_shared<RBTree<int>>();
rbt->find(3);
assert(rbt->preOrder() == "");
assert(rbt->find(32) == nullptr);
rbt->insert(1);
rbt->insert(4);
rbt->insert(7);
rbt->insert(10);
rbt->insert(2);
rbt... | 17,301 | C++ | .cpp | 515 | 25.363107 | 94 | 0.504712 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,186 | red_black_tree.cpp | OpenGenus_cosmos/code/data_structures/src/tree/multiway_tree/red_black_tree/red_black_tree.cpp | #include <iostream>
#include <memory>
#include <cassert>
#include <string>
#include <stack>
using namespace std;
template<typename _Type, class _Derivative>
class BaseNode
{
protected:
using ValueType = _Type;
using SPNodeType = std::shared_ptr<_Derivative>;
public:
BaseNode(ValueType v, SPNodeType l = nu... | 16,092 | C++ | .cpp | 588 | 20.003401 | 97 | 0.533545 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,187 | van_emde_boas.cpp | OpenGenus_cosmos/code/data_structures/src/tree/multiway_tree/van_emde_boas_tree/van_emde_boas.cpp | #include <iostream>
#include <math.h>
using namespace std;
typedef struct VEB
{
int u;
int min, max;
int count;
struct VEB *summary, **cluster;
} VEB;
int high(int x, int u)
{
return (int)(x / (int) sqrt(u));
}
int low(int x, int u)
{
return x % (int) sqrt(u);
}
int VEBmin(VEB*V)
{
retu... | 3,557 | C++ | .cpp | 155 | 15.187097 | 87 | 0.419669 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,188 | treap.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/treap/treap.cpp | #include <iostream>
#define ll long long
#define MOD 1000000007
using namespace std;
// Part of Cosmos by OpenGenus Foundation
// structure representing a treap node
struct node
{
ll key;
ll priority;
node* left;
node* right;
node* parent;
node(ll data)
{
key = data;
priorit... | 2,935 | C++ | .cpp | 135 | 16.044444 | 66 | 0.52369 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,189 | is_same.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/is_same/is_same.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*
* tree comparer synopsis
*
* template<typename _Tp, typename _Comp = std::equal_to<_Tp> >
* class TreeComparer
* {
* public:
* using NodeType = TreeNode<_Tp>;
* using PNodeType = std::shared_ptr<NodeType>;
*
* bool isSameTree(PNodeType p, PNodeType q) const;
... | 2,176 | C++ | .cpp | 74 | 20.756757 | 97 | 0.511239 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,190 | path_sum.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/path_sum/path_sum.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*/
#ifndef path_sum_cpp
#define path_sum_cpp
#include "path_sum.hpp"
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <memory>
#include <algorithm>
#include <utility>
#include <functional>
// public
template<typename _Ty, typename _Compare, cla... | 2,234 | C++ | .cpp | 72 | 23.041667 | 87 | 0.544015 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,192 | maximum_height2.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/maximum_height/maximum_height2.cpp | #include <iostream>
using namespace std;
class node {
private:
int value;
node* left, *right;
public:
node()
{
};
~node()
{
};
node* create_node(int& val);
void create_tree(int& val);
int height_tree(node* tmp);
void cleanup_tree(node* tmp);
inline int maximum(int le... | 2,113 | C++ | .cpp | 99 | 14 | 55 | 0.474078 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,193 | right_threaded.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/traversal/inorder/right_threaded/right_threaded.cpp | /* Part of Cosmos by OpenGenus Foundation */
/*
* Right-Threaded Binary Tree implementation in C++
*/
//Author: Arpan Konar
#include <iostream>
using namespace std;
typedef long long ll;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, a, b) for (long long i = (a); i <= (b); i++)
#define FORD(i, a... | 3,576 | C++ | .cpp | 157 | 16.88535 | 59 | 0.518876 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,195 | zigzag.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/traversal/zigzag/zigzag.cpp | #include <iostream>
#include <stack>
class Node
{
public:
int info;
Node* left_child;
Node* right_child;
Node (int info) : info{info}, left_child{nullptr}, right_child{nullptr}
{
}
};
class BinaryTree
{
public:
Node* root;
BinaryTree() : root{nullptr}
{
}
void zigzag_traver... | 1,581 | C++ | .cpp | 62 | 19.016129 | 75 | 0.543894 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,196 | convert_to_doubly_linked_list.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/convert_to_doubly_linked_list/convert_to_doubly_linked_list.cpp | /* Structure for tree and linked list
*
* struct Node
* {
* int data;
* Node *left, *right;
* };
*
*/
// root --> Root of Binary Tree
// head_ref --> Pointer to head node of created doubly linked list
template<typename Node>
void BToDLL(Node *root, Node **head_ref)
{
if (!root)
return;
BToD... | 489 | C++ | .cpp | 23 | 17.956522 | 66 | 0.613883 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,197 | minimum_height.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/minimum_height/minimum_height.cpp | #include <iostream>
using namespace std;
typedef struct tree_node
{
int value;
struct tree_node *left, *right;
}node;
// create a new node
node *getNewNode(int value)
{
node *new_node = new node;
new_node->value = value;
new_node->left = NULL;
new_node->right = NULL;
return new_node;
}
//... | 992 | C++ | .cpp | 48 | 16.875 | 46 | 0.608137 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,198 | subtreesum_recursive.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/Subtree_sum/subtreesum_recursive.cpp | #include<iostream>
using namespace std;
//Binary tree structure
struct node
{
int data;
struct node* left;
struct node* right;
};
//for inserting a new node
node *newNode(int data){
node *temp=new node;
temp->data=data;
temp->right=NULL;
temp->left=NULL;
return (temp);
}
//helper functi... | 1,575 | C++ | .cpp | 60 | 23.95 | 92 | 0.72505 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,199 | diameter2.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/diameter/diameter2.cpp | /*
* Data Structures : Finding Diameter of a binary tree
*
* Description : Diameter of tree is defined as the longest path or route between any two nodes in a tree.
* This path may or may not be through the root. The below algorithm computes the height of
* the tree and uses it recursivley in... | 1,932 | C++ | .cpp | 73 | 23.150685 | 106 | 0.659263 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,200 | diameter.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/diameter/diameter.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*
* diameter of tree synopsis
*
* template<typename _TreeNode>
* size_t
* diameter(_TreeNode node);
*
* template<typename _TreeNode>
* void
* diameterIterative(_TreeNode const &node, size_t &maximum);
*
* template<typename _TreeNode>
* size_t
* getDiameter(_T... | 2,910 | C++ | .cpp | 106 | 21.433962 | 92 | 0.590323 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,202 | node.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/node/node.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*
* tree node synopsis
*
* // for normal binary tree
* template<typename _Type>
* class TreeNode
* {
* protected:
* using SPNodeType = std::shared_ptr<TreeNode>;
* using ValueType = _Type;
*
* public:
* TreeNode(ValueType v, SPNodeType l = nullptr, SPNodeType... | 4,114 | C++ | .cpp | 199 | 17.281407 | 84 | 0.611768 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,203 | serializer.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/serializer/serializer.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*
* tree serializer synopsis
*
* class TreeSerializer
* {
* public:
* using NodeType = TreeNode<int>;
* using PNodeType = std::shared_ptr<NodeType>;
*
* // Encodes a tree to a single string.
* std::string serialize(PNodeType root);
*
* // Decodes your encod... | 3,608 | C++ | .cpp | 128 | 17.992188 | 80 | 0.452841 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,205 | make_tree_from_inorder_and_preorder.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/make_binary_tree/from_inorder_and_preorder/make_tree_from_inorder_and_preorder.cpp | #include <iostream>
#include <cmath>
#include <queue>
#include <cmath>
using namespace std;
template<typename T>
class Binarytreenode {
public:
T data;
Binarytreenode<T> * left;
Binarytreenode<T> * right;
Binarytreenode(T data)
{
this->data = data;
left = NULL;
right = NU... | 1,397 | C++ | .cpp | 56 | 19.910714 | 88 | 0.572184 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,206 | is_binary_tree.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/is_binary_tree/is_binary_tree.cpp | /* A binary tree node has data, pointer to left child
* and a pointer to right child
*
* struct Node {
* int data;
* Node* left, * right;
* };
*
*/
/* Should return true if tree represented by root is BST.
* For example, return value should be 1 for following tree.
* 20
* / \
* 10 3... | 1,508 | C++ | .cpp | 62 | 20.370968 | 94 | 0.611501 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,207 | balance_bst_dsw.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_tree/balance_binary_tree/balance_bst_dsw.cpp | #include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
struct node
{
int key;
struct node *left, *right;
};
struct node *newNode(int value)
{
struct node *temp = new node;
temp->key = value;
temp->left = temp->right = NULL;
return temp;
}
struct node* insert(struct n... | 4,218 | C++ | .cpp | 188 | 17.776596 | 63 | 0.560994 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,211 | avl_tree.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/avl_tree/avl_tree.cpp | /*
* Part of Cosmos by OpenGenus Foundation
* avl tree synopsis
*
* template<typename _Tp, typename _Comp = std::less<_Tp> >
* class avl_tree {
* private:
* struct AVLNode {
* _Tp data;
* std::shared_ptr<AVLNode> left;
* std::shared_ptr<AVLNode> right;
* int height;
* };
*
* typedef... | 9,900 | C++ | .cpp | 344 | 21.90407 | 86 | 0.52163 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,212 | BST_Operations.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/binary_search_tree/BST_Operations.cpp | #include<iostream>
#include<algorithm>
using namespace std;
class BST{
private:
int data;
BST *left,*right;
public:
//Constructors:
BST(){
data=0;
left=right=NULL;
}
BST(int val){
data=val;
left=right=NULL;
}
//Inserting a Node into BST:
BST* InsertNod... | 4,554 | C++ | .cpp | 177 | 17.920904 | 71 | 0.510979 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,213 | aa_tree.cpp | OpenGenus_cosmos/code/data_structures/src/tree/binary_tree/aa_tree/aa_tree.cpp | /*
* Part of Cosmos by OpenGenus Foundation
* arne andersson tree synopsis
*
* template<typename _Derive, typename _Tp, typename _Comp = std::less<_Tp> >
* struct BinaryTreeNode {
* _Tp value;
* std::shared_ptr<_Derive> left, right;
* BinaryTreeNode(_Tp v,
* std::shared_ptr<_Derive> l = null... | 15,340 | C++ | .cpp | 577 | 21.372617 | 93 | 0.524625 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,214 | segment_tree_rmq_with_update.cpp | OpenGenus_cosmos/code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_rmq_with_update.cpp | /* Part of Cosmos by OpenGenus Foundation */
/*
* Processes range minimum query.
* Query function returns index of minimum element in given interval.
* Code assumes that length of array can be contained into integer.
*/
#include <iostream>
#include <utility>
#include <vector>
struct Node
{
// store the data ... | 3,957 | C++ | .cpp | 133 | 22.654135 | 86 | 0.540776 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,216 | persistent_segment_tree_sum.cpp | OpenGenus_cosmos/code/data_structures/src/tree/space_partitioning_tree/segment_tree/persistent_segment_tree_sum.cpp | // Fully persistent Segment tree with spaces. Allows to find sum in O(log size) time in any version. Uses O(n log size) memory.
#include <iostream>
#include <string>
const int size = 1000000000;
const int versionCount = 100000;
struct node
{
int leftBound, rightBound;
node *leftChild, *rightChild;
int val... | 3,100 | C++ | .cpp | 93 | 25.72043 | 127 | 0.58861 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,217 | segment_tree_kth_statistics_on_segment.cpp | OpenGenus_cosmos/code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_kth_statistics_on_segment.cpp | #include <cassert>
#include <iostream>
#include <vector>
using namespace std;
const int lb = -1e9, rb = 1e9;
struct node
{
int val;
node *l, *r;
node()
{
val = 0;
l = r = nullptr;
}
node(int x)
{
val = x;
l = r = nullptr;
}
node(node* vl, node* vr)
... | 2,687 | C++ | .cpp | 115 | 17.434783 | 80 | 0.43196 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,218 | segment_tree_rmq.cpp | OpenGenus_cosmos/code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_rmq.cpp | /* Name: Mohit Khare
* B.Tech 2nd Year
* Computer Science and Engineering
* MNNIT Allahabad
*/
#include <cstdio>
#include <climits>
#define min(a, b) ((a) < (b) ? (a) : (b))
using namespace std;
typedef long long int ll;
#define mod 1000000007
const int maxn = 1e5 + 1;
void build(ll segtree[], ll arr[], int low,... | 1,678 | C++ | .cpp | 66 | 21.469697 | 76 | 0.541381 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,219 | segment_tree_sum.cpp | OpenGenus_cosmos/code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_sum.cpp | // Segment tree with spaces. Allows to find sum in O(log size) time. Uses O(n log size) memory.
#include <iostream>
#include <string>
const int size = 1000000000;
struct node
{
int leftBound, rightBound;
node *leftChild, *rightChild;
int value;
node (int LeftBound, int RightBound)
{
leftB... | 2,376 | C++ | .cpp | 77 | 23.454545 | 95 | 0.568232 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,223 | min_heap.cpp | OpenGenus_cosmos/code/data_structures/src/tree/heap/min_heap/min_heap.cpp | /* Part of Cosmos by OpenGenus Foundation */
#include <iostream>
#include <vector>
using namespace std;
class minHeap {
vector<int> v;
void heapify(size_t i)
{
size_t l = 2 * i;
size_t r = 2 * i + 1;
size_t min = i;
if (l < v.size() && v[l] < v[min])
min = l;
... | 1,396 | C++ | .cpp | 73 | 12.30137 | 46 | 0.40916 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,224 | soft_heap.cpp | OpenGenus_cosmos/code/data_structures/src/tree/heap/soft_heap/soft_heap.cpp | /**
* Soft Heap
* Author: JonNRb
*
* Original paper: https://www.cs.princeton.edu/~chazelle/pubs/sheap.pdf
* Binary heap version by Kaplan and Zwick
*/
#include <functional>
#include <iterator>
#include <limits>
#include <list>
#include <memory>
#include <stdexcept>
using namespace std;
#if __cplusplus <= 2011... | 7,073 | C++ | .cpp | 231 | 22.294372 | 86 | 0.508011 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,225 | binomial_heap.cpp | OpenGenus_cosmos/code/data_structures/src/tree/heap/binomial_heap/binomial_heap.cpp | #include <iostream>
#include <queue>
#include <vector>
/* Part of Cosmos by OpenGenus Foundation */
using namespace std;
class Node {
public:
int value;
int degree;
Node* parent;
Node* child;
Node* sibling;
Node() : value(0), degree(0), parent(0), child(0), sibling(0)
{
};
~Node()
... | 8,789 | C++ | .cpp | 311 | 18.29582 | 149 | 0.418145 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,226 | leftist_priority_queue.cpp | OpenGenus_cosmos/code/data_structures/src/tree/heap/priority_queue/leftist_tree/leftist_priority_queue.cpp | #include <iostream>
#include <algorithm>
struct Leftist
{
Leftist *left, *right;
// dis is the distance to the right-bottom side of the tree
int dis, value, size;
Leftist(int val = 0)
{
left = NULL, right = NULL;
dis = 0, value = val, size = 1;
}
~Leftist()
{
del... | 2,217 | C++ | .cpp | 75 | 24.64 | 94 | 0.594366 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | true | false |
10,227 | van_emde_boas_tree.cpp | OpenGenus_cosmos/code/data_structures/src/tree/van_emde_boas_tree/van_emde_boas_tree.cpp | #include <bits/stdc++.h>
using namespace std;
class veb
{
int u;
int *min;
int *max;
veb *summary;
veb **cluster;
public:
veb(int u);
void insert(int x);
void remove(int x);
int* pred(int x);
int minimum();
int maximum();
};
veb :: veb(int u)
{
this->u = u;
this-... | 6,472 | C++ | .cpp | 292 | 12.582192 | 65 | 0.382449 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,229 | suffix_array.cpp | OpenGenus_cosmos/code/data_structures/src/tree/tree/suffix_array/suffix_array.cpp | #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll size_t
using namespace std;
struct ranking
{
ll index;
ll first;
ll second;
};
bool comp(ranking a, ranking b)
{
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}
vector<l... | 1,625 | C++ | .cpp | 61 | 21.04918 | 100 | 0.503551 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,231 | KadaneAlgorithm.cpp | OpenGenus_cosmos/code/data_structures/src/maxSubArray(KadaneAlgorithm)/KadaneAlgorithm.cpp | #include <iostream>
#include <vector>
using namespace std;
int Kadane(vector<int>& arr) {
int max_so_far = INT_MIN;
int max_ending_here = 0;
for (int i = 0; i < arr.size(); i++) {
max_ending_here = max_ending_here + arr[i];
if (max_ending_here < 0) {
max_ending_here = 0;
... | 712 | C++ | .cpp | 25 | 23.44 | 96 | 0.57478 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,232 | Add_one_to_LL.cpp | OpenGenus_cosmos/code/data_structures/src/Linked_List/Add_one_to_LL.cpp | class Solution
{
public:
Node* reverse( Node *head)
{
// code here
// return head of reversed list
Node *prevNode=NULL,*currNode=head,*nextNode=head;
while(currNode!=NULL){
nextNode=currNode->next;
currNode->next=prevNode;
prevNode=currNode... | 963 | C++ | .cpp | 35 | 17.171429 | 58 | 0.530023 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,234 | Intersection_of_two_sorted_lists.cpp | OpenGenus_cosmos/code/data_structures/src/Linked_List/Intersection_of_two_sorted_lists.cpp | Node* findIntersection(Node* head1, Node* head2)
{
if(head1==NULL or head2==NULL) return NULL;
if(head1->data==head2->data)
{
head1->next=findIntersection(head1->next,head2->next);
return head1;
}
else if(head1->data>head2->data)
return findIntersection(head1,hea... | 391 | C++ | .cpp | 12 | 26.083333 | 62 | 0.679666 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.