摘要: #include #include using namespace std; class String { public: String(const char* str = NULL);//通用构造函数,String("abc") String(const String &str);//拷贝构造 ~String(); String& operator=... 阅读全文
posted @ 2019-05-23 20:20 前进的code 阅读(11777) 评论(1) 推荐(0) 编辑
摘要: 图-邻接矩阵转邻接表+DFS递归非递归+BFS非递归 图-最短路径-dijkstra、bellmanford、spfa、floyd 图-最小生成树prim+kruskal 阅读全文
posted @ 2019-05-23 20:19 前进的code 阅读(257) 评论(0) 推荐(0) 编辑
摘要: template class SharedPtr { public: SharedPtr():ptr(new T()),count(new int(1)){}//无参构造 explicit SharedPtr(T *src):ptr(str),count(new int(1)){}//有参构造 explicit SharedPtr(T value):ptr(new ... 阅读全文
posted @ 2019-05-23 20:19 前进的code 阅读(167) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; struct BiThrNode { int data; BiThrNode *left; BiThrNode *right; bool ltag;//0表示left指向左子,1表示left指向直接前驱 bool rtag; //BiThrNode(int va... 阅读全文
posted @ 2019-05-23 20:18 前进的code 阅读(2115) 评论(0) 推荐(0) 编辑
摘要: #include #include #include using namespace std; /* 二叉树遍历算法递归+非递归: 前序遍历:根->左->右 中序遍历:左->根->右 后序遍历:左->右->根 层次遍历 */ struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNod... 阅读全文
posted @ 2019-05-23 20:17 前进的code 阅读(291) 评论(0) 推荐(0) 编辑
摘要: /* 二叉查找树 插入 查找前驱、后继 删除 https://www.cnblogs.com/skywang12345/p/3576373.html*/ #include #include using namespace std; struct BSTNode { int val; BSTNode *left; BSTNode *right; BSTNo... 阅读全文
posted @ 2019-05-23 20:16 前进的code 阅读(846) 评论(0) 推荐(0) 编辑
摘要: #include #include #include using namespace std; /* 1、顺序查找 On */ int sequence_search(vector data, int val) { if (data.empty()) return -1; for (int i = 0; i data, int val) { if... 阅读全文
posted @ 2019-05-23 20:16 前进的code 阅读(475) 评论(0) 推荐(0) 编辑
摘要: #include #include #include using namespace std; /* 1、插入排序。稳定 (1)原理:逐个处理待排序记录,每个记录与前面已排序子序列进行比较,将其插入子序列中正确位置 (2)复杂度:O(n)-》O(n^2),O(n^2) 最佳:升序。时间复杂度为O(n) 最差:降序。时间复杂度为O(n^2) 平均:对于每个元素,前面有一半元素比它大。时间... 阅读全文
posted @ 2019-05-23 20:15 前进的code 阅读(396) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #include using namespace std; void addstr(const string s, int i, int j, vector &result) {//从i到分割点j部分子串加入到result,需判断子串是否全为空,有一个不为空则可以 bool allempty = true; f... 阅读全文
posted @ 2019-05-23 20:15 前进的code 阅读(473) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; /* strlen 返回字符串不包含结束符\0的长度 */ int mystrlen(const char *str) {//非递归strlen assert(str);//必须不为空 int len = 0; while (*str++) len++; r... 阅读全文
posted @ 2019-05-23 20:14 前进的code 阅读(284) 评论(0) 推荐(0) 编辑