Skip to content

harsh0620/snippetsCpp-VsCode

Repository files navigation

snippetsCpp README

A collection of code snippets for competitive programmers, written in C++ for vscode.

Many times this happens in competitive programming competitions that you've figured out an algorithm for the solution of the problem, which happens to be a standard algorithm. How helpful would it be to have snippets for commonly used concepts/algorithms in competitive programming in that situation, to provide you an edge over fellow competitors as using snippets will improve your accuracy, speed and hence rank!

This repository provides extension for vscode editor which enables vscode users to use c++ coding snippets of algorithms while doing competitive programming.


Author

Harsh Chandravanshi: Portfolio


Supported languages (file extensions)

  • C++ (.cpp, .c++)
  • C (.c)

Snippets info

Every space inside { } and ( ) means that this is pushed into next line :) $ represent each step after tab.


Starter Template

Prefix Uses/Method
cpp CP Starter Template
c++ C++ Starter Template
dsa DSA Specific Starter Template
kickstart Google KickStart C++ Template

Common Codes

Prefix Uses/Method
forn For loop with n size
whilen While loop with n size
couta Print elements of array of n size
coutv Print elements of vector
autov Print element of vector with auto

Input Taking Template

Prefix Uses/Method
inai Taking input in n size int array
inal Taking input in n size long long int array
invi Taking input in n size int vector
invl Taking input in n size long long int vector

Basic Algo + Mathematics

Prefix Uses/Method
gcd Greatest Common Divisor
maxll Maximum Function with long long int
minll Minimum Function with long long int
isPowerOfTwo Check number is power of two
isPrime Check number is prime
primeFactors return all prime factors
countDivisors count of all divisors
divisorFunction sum of all divisors
nFactorial return n!
nFactorialMOD return n!%mod
nextPowerOfTwo next power of two
prevPowerOfTwo prev power of two
xpowery x^y
xpoweryMOD (x^y)%mod
sieve sieve of eratosthenes
lcm Least Common Multiple
combinatorics Combinatorics

Graph

Prefix Uses/Method
adjMatrix Adjacency Matrix in Graph
adjList Adjacency List in Graph
bfs BFS in Graph
dfs DFS in Graph
topoBfs Topological BFS in Graph
topoDfs Topological DFS in Graph
isCycleDfs Is Cycle is Present in Graph using DFS
isCycleBfs Is Cycle is Present in Graph using BFS
shortesPathDAG Shortest Path Direct Acyclic Graph
dijkstra Dijkstra shortest path algorithm
bellmanFord Bellman Ford shortest path algorithm

Tree

Prefix Uses/Method
tstruct Tree Structure
inorder Tree Inorder
preorder Tree Preorder
postorder Tree Postorder
levelOrder Level Order Traversal Tree
treeSize Tree Size
treeHeight Tree Height
treeDiaSimple Tree Diameter Simple
treeDiaOpt Tree Diameter Optimized
treeSum Tree Node Sum
treeMax Tree Node Maximum
treeLeftView Tree Left View
treeRightView Tree Right View
isBalancedSimple Tree Balanced or Not Simple
isBalancedOpt Tree Balanced or Not Optimized
flatten Flatten Binary Tree

BST

Prefix Uses/Method
insBst Insert in BST
delBst Delete in BST
searchBst Search in BST
constructBst Construct BST
isBst Check the given tree is BST or not
sortArrToBst Sorted array to Bst
isIdentical Is Bst identical or nor
zigzagTraversal zigzagTraversal Bst

String

Prefix Uses/Method
palindrome palindrome-String
pangram pangram-string
anagram anagram-strings
strtodec stringtodecimal
dectostr decimaltostring
kmp occurences of pattern in a string
distict_characters count of unique characters in a string
lc_subsequence longest common subsequence of two strings
lc_substring longest common substring of two strings

Sorting

Prefix Uses/Method
insort Insertion Sort
bubsort Bubble Sort
selsort Selection Sort
mersort Merge Sort
qsort Quick Sort

Saerching

Prefix Uses/Method
bsearch Binary Search

Features

alt text alt text alt text alt text


Known Issues

No Issues


Release Notes

1.0.0

Initial release with the snippets on above topics with their prefixes.


Enjoy!