-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp code-snippets.json
More file actions
64 lines (62 loc) · 1.41 KB
/
cpp code-snippets.json
File metadata and controls
64 lines (62 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{
"for-0": {
"prefix": ["F0R", "f0r"],
"body": [
"for (int ${1:i}; ${1:i} < ${2:n}; ${1:i}++)$3"
],
"description": "for-loop starting from 0"
},
"for-N": {
"prefix": "FOR",
"body": [
"for (int ${1:i} = ${2:1}; ${1:i} < ${3:n}; ${1:i}++)$4"
],
"description": "for-loop starting from N"
},
"dfs": {
"prefix": "dfs",
"body": [
"${1:int} dfs(${1:int} ${2:node}){",
"\tstack<${1:int}> stk;",
"\tstk.push(${2:node});",
"\tunordered_set<${1:int}> visited;",
"\n\t${1:int} curr;",
"\twhile (!stk.empty()){ // while not empty",
"\t\tcurr = stk.top();",
"\t\tvisited.insert(curr);",
"\t\tstk.pop();",
"\t\t",
"\t\tfor (auto &e : edges[curr]){",
"\t\t\tif (visited.find(e) == visited.end()) stk.push(e);",
"\t\t}",
"\t}",
"\t$4",
"\treturn $3;",
"}"
],
"description": "dfs"
},
"bfs": {
"prefix": "bfs",
"body": [
"${1:int} bfs(${1:int} ${2:node}){",
"\tqueue<${1:int}> que;",
"\tque.push(${2:node});",
"\tunordered_set<${1:int}> visited;",
"\n\t${1:int} curr;",
"\twhile (!que.empty()){ // while not empty",
"\t\tcurr = stk.front();",
"\t\tvisited.insert(curr);",
"\t\tstk.pop();",
"\t\t",
"\t\tfor (auto &e : edges[curr]){",
"\t\t\tif (visited.find(e) == visited.end()) que.push(e);",
"\t\t}",
"\t}",
"\t$4",
"\treturn $3;",
"}"
],
"description": "bfs"
}
}