摘要: 普通类的成员函数模板 不管是普通类还是类模板,它的成员函数可以是一个函数模板(成为成员函数模板)。不可以是虚函数,否则编译器会报错。 //普通类的成员函数模板 class A { public: template<typename T> void my_ft(T tmp) //成员函数模板 { co 阅读全文
posted @ 2020-11-28 15:07 NaughtyCoder 阅读(418) 评论(0) 推荐(0)
摘要: typename的使用场合 模板定义中,表明其后的模板参数是类型参数 template<typename T, int a, int b> //typename后跟的是一个类型 int funcadd(T c){...} template<typename T> //typename可以写为clas 阅读全文
posted @ 2020-11-28 15:02 NaughtyCoder 阅读(127) 评论(0) 推荐(0)
摘要: 邻接矩阵 #include <iostream> #include <queue> #include <algorithm> #include <set> using namespace std; int n, m; vector<int> topsort(vector<int>& inDegree 阅读全文
posted @ 2020-09-01 16:05 NaughtyCoder 阅读(100) 评论(0) 推荐(0)
摘要: 字符串解码 题目链接:https://leetcode-cn.com/problems/decode-string/ class Solution { public: string decodeString(string s) { //用一个数字栈 保存数字 //一个string栈 保存str // 阅读全文
posted @ 2020-08-27 17:32 NaughtyCoder 阅读(139) 评论(0) 推荐(0)
摘要: 每日温度 题目链接:https://leetcode-cn.com/problems/daily-temperatures/ class Solution { public: //每个元素找到它右边第一个比它大的元素的位置,求它们的距离 vector<int> dailyTemperatures(v 阅读全文
posted @ 2020-08-26 22:14 NaughtyCoder 阅读(184) 评论(0) 推荐(0)
摘要: 空类 空类 #include <iostream> using namespace std; class Base { void f(){}; }; int main() { cout << sizeof(Base) << endl; //1 return 0; } 虚继承空类的类大小 #inclu 阅读全文
posted @ 2020-08-25 17:20 NaughtyCoder 阅读(236) 评论(0) 推荐(0)
摘要: 单调栈 找每个数左边离它最近的比它大/小的数 模板 stack<int> st; for(int i = 1; i <= n; i++) { while(st.size() > 0 && x <= st.top()) st.pop(); st.push(arr[i]); } 单调栈 题目链接:htt 阅读全文
posted @ 2020-08-24 21:51 NaughtyCoder 阅读(167) 评论(0) 推荐(0)
摘要: strcpy #include <iostream> #include <assert.h> using namespace std; char * my_strcpy(char* str1,const char* str2) { char* p = str1; assert(str1 != NUL 阅读全文
posted @ 2020-08-24 09:39 NaughtyCoder 阅读(167) 评论(0) 推荐(0)
摘要: 字母异位词分组 题目链接:https://leetcode-cn.com/problems/group-anagrams/ class Solution { public: vector<vector<string>> groupAnagrams(vector<string>& strs) { un 阅读全文
posted @ 2020-08-24 07:58 NaughtyCoder 阅读(136) 评论(0) 推荐(0)
摘要: 压缩字符串 题目链接:https://leetcode-cn.com/problems/string-compression/ class Solution { public: int compress(vector<char>& chars) { int n = chars.size(); int 阅读全文
posted @ 2020-08-23 18:49 NaughtyCoder 阅读(149) 评论(0) 推荐(0)