Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>CPToolkitNew to Visual Studio Code? Get it now.
CPToolkit

CPToolkit

Nitesh Kumar & Mitali Laddha

|
6 installs
| (0) | Free
A collection of C++ snippets for competitive programming
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

CPToolkit

Version VSCode Language

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

  1. Open VSCode
  2. Go to Extensions (Ctrl+Shift+X)
  3. Search for "CPToolkit"
  4. 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

  1. Open a C++ file in VSCode
  2. Type any of the snippet prefixes (e.g., dijkstra, mod_add, bfs)
  3. Press Tab or Enter to insert the complete code
  4. 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

  1. Add your C++ implementation to the appropriate file in algos/ or math/
  2. Create corresponding VSCode snippets in the snippets/ directory
  3. Update the package.json to include the new snippet file
  4. Test the snippets in VSCode
  5. Update this README with the new algorithms

Contact

  • Repository: https://github.com/devniteshkumar/cptoolkit
  • Issues: Report issues here
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft