aboutsummaryrefslogtreecommitdiff
path: root/my_snippets
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2021-10-30 22:53:39 +0800
committerjdhao <jdhao@hotmail.com>2021-10-30 22:53:39 +0800
commit80893e7e4adbe77e8f78f57c1921e486109838d7 (patch)
tree021bf1a2ed17d5bfc39843e8babdd7f467430e60 /my_snippets
parent5bf969e327c2734fbdfe82d4d3c8d7b40742d1db (diff)
update cpp snippets
Diffstat (limited to 'my_snippets')
-rw-r--r--my_snippets/cpp.snippets54
1 files changed, 33 insertions, 21 deletions
diff --git a/my_snippets/cpp.snippets b/my_snippets/cpp.snippets
index 6fe8acb..3e2f196 100644
--- a/my_snippets/cpp.snippets
+++ b/my_snippets/cpp.snippets
@@ -2,18 +2,30 @@ snippet bare "barebone code template"
#include <iostream>
#include <vector>
#include <string>
+#include <map>
+#inlcude <unordered_map>
+#include <set>
+#inlucde <unordered_set>
+#include <stack>
+#include <queue>
using std::cout;
using std::endl;
using std::vector;
using std::string;
+using std::map;
+using std::unordered_map;
+using std::set;
+using std::unordered_set;
+using std::stack;
+using std::queue;
int main()
{
- return 0;
+ return 0;
}
endsnippet
@@ -25,25 +37,25 @@ endsnippet
snippet plist "print vector" w
template <class T>
void printList(const T& arr, const string& desc){
- std::cout << desc << ": [";
+ std::cout << desc << ": [";
- for (auto it = arr.begin(); it != arr.end(); it++){
- std::cout << *it << ((std::next(it) != arr.end()) ? ", " : "]\n");
- }
+ for (auto it = arr.begin(); it != arr.end(); it++){
+ std::cout << *it << ((std::next(it) != arr.end()) ? ", " : "]\n");
+ }
}
endsnippet
snippet pmat "print list of list" w
template <class T>
void printMat(const vector<vector<T>>& mat, const string& desc){
- cout << desc << ": " << endl;
-
- for (auto it1 = mat.begin(); it1 != mat.end(); it1++){
- auto cur_vec = *it1;
- for (auto it2 = cur_vec.begin(); it2 != cur_vec.end(); it2++){
- cout << *it2 << ((std::next(it2) != cur_vec.end()) ? ", " : "\n");
- }
- }
+ cout << desc << ": " << endl;
+
+ for (auto it1 = mat.begin(); it1 != mat.end(); it1++){
+ auto cur_vec = *it1;
+ for (auto it2 = cur_vec.begin(); it2 != cur_vec.end(); it2++){
+ cout << *it2 << ((std::next(it2) != cur_vec.end()) ? ", " : "\n");
+ }
+ }
}
endsnippet
@@ -55,16 +67,16 @@ snippet random "Generate a random list" b
// Generate a random sequence of length len, in range(low, high) (inclusive).
// need to #include<random>
vector<int> genRandom(int low, int high, int len){
- std::random_device rd;
- std::mt19937 gen(rd());
- std::uniform_int_distribution<int> distribution(low, high);
+ std::random_device rd;
+ std::mt19937 gen(rd());
+ std::uniform_int_distribution<int> distribution(low, high);
- vector<int> arr(len, 0);
- for (int i = 0; i != len; ++i){
- arr[i] = distribution(gen);
- }
+ vector<int> arr(len, 0);
+ for (int i = 0; i != len; ++i){
+ arr[i] = distribution(gen);
+ }
- return arr;
+ return arr;
}
endsnippet