A comprehensive collection of C++ code snippets and algorithms for competitive programming. This VSCode extension provides quick access to commonly used algorithms, data structures, and mathematical functions that are essential for competitive programming contests.
Features
Instant Code Snippets: Type prefixes and get complete algorithm implementations
Optimized for Competitive Programming: All code is optimized for speed and efficiency
Comprehensive Coverage: Includes graph algorithms, mathematical functions, and data structures
Ready-to-Use: Copy-paste friendly code that compiles and runs immediately
Modern C++ Standards: Uses modern C++ features and best practices
Installation
From VSCode Marketplace
Open VSCode
Go to Extensions (Ctrl+Shift+X)
Search for "CPToolkit"
Click Install
Available Algorithms & Data Structures
Graph Algorithms
BFS (Breadth-First Search) - bfs
DFS (Depth-First Search) - dfs
Dijkstra's Shortest Path - dijkstra
Topological Sort (Kahn's Algorithm) - toposort
Kruskal's MST - kruskal
Prim's MST - prim
Bellman-Ford Algorithm - bellmanford
Floyd-Warshall Algorithm - floydwarshall
Disjoint Set Union (DSU) - dsu
Mathematical Functions
Modular Arithmetic
Modular Addition - mod_add
Modular Subtraction - mod_sub
Modular Multiplication - mod_mul
Modular Exponentiation - mod_pow
Modular Inverse - mod_inv
Modular Division - mod_div
Combinatorics
Factorial - factorial
nPr (Permutations) - npr
nCr (Combinations) - ncr
Multinomial Coefficient - multinomial
Catalan Numbers - catalan
Number Theory
GCD (Greatest Common Divisor) - gcd
LCM (Least Common Multiple) - lcm
Array GCD - gcdarray
Array LCM - lcmarray
Prime Check - isprime
Prime Factorization - primefactors
Get All Factors - getfactors
Coprime Check - iscoprime
Fraction Reduction - reducefraction
Common Factors - commonfactors
Usage
Open a C++ file in VSCode
Type any of the snippet prefixes (e.g., dijkstra, mod_add, bfs)
Press Tab or Enter to insert the complete code
Customize the parameters as needed
Example Usage
// Type 'dijkstra' and press Tab
vector<long long> dijkstra(int n, vector<vector<pair<int,int>>> &adj, int src) {
const long long INF = 1e18;
vector<long long> dist(n, INF);
priority_queue<pair<long long,int>, vector<pair<long long,int>>, greater<>> pq;
dist[src] = 0;
pq.push({0, src});
while (!pq.empty()) {
auto [d, u] = pq.top(); pq.pop();
if (d != dist[u]) continue;
for (auto [v, w] : adj[u]) {
if (dist[v] > d + w) {
dist[v] = d + w;
pq.push({dist[v], v});
}
}
}
return dist;
}
Adding New Snippets
Add your C++ implementation to the appropriate file in algos/ or math/
Create corresponding VSCode snippets in the snippets/ directory
Update the package.json to include the new snippet file