- 博客(18)
- 收藏
- 关注
原创 深度探索C++模型
C++对象内存分配情况在面试中经常被问到,在《深度探索C++对象模型》一书中有详细介绍,本文将简单介绍C++对象在的内存分配情况。 参考:http://www.cnblogs.com/skynet/p/3343726.html
2017-10-15 21:57:05
390
原创 effective cpp24, 46需要类型转换时请为模板定义非成员函数
一般看来,令class支持隐式转换是不好的实现。但在混合运算中更适合支持混合运算。 class Rational { public: Rational(int numerator = 0, int denominator = 1); int numberator() const; int denominator() const; private : ..
2017-08-19 11:09:58
254
转载 网络协议
TCP是一个巨复杂的协议,因为他要解决很多问题,而这些问题又带出了很多子问题和阴暗面。所以学习TCP本身是个比较痛苦的过程,但对于学习的过程却能让人有很多收获。关于TCP这个协议的细节,我还是推荐你去看W.Richard Stevens的《TCP/IP 详解 卷1:协议》(当然,你也可以去读一下RFC793以及后面N多的RFC)。另外,本文我会使用英文术语,这样方便你通过这些英文关键词来查找相关的技
2017-08-01 20:45:48
337
原创 const优点全面总结
effective c++条款02中提到尽量以const替换#define。换句话理解,const保留了宏的好处,丢弃了宏的坏处。变量 宏的好处 1. 宏基本**不被编译器**看见,直接经过**预处理器**的处理基本就行了。 2. 不用分配内存空间,而是直接保存到**字符表**。 3. 保护不被改变的数
2017-07-05 19:26:01
679
原创 LeetCode
Longest Substring Without Repeating Characters 一开始的思路是使用set记录出现过的字符串,当向set添加字符串时,如果set中已经存在则说明出现了重复字符串,则将set中的当前字母出现的位置更新(这块是存在问题的,因为重复字母前面的字母没有被删除,所以计算出的结果偏大。) 而本题考察的是双指针的问题。
2017-06-29 09:07:35
298
原创 动态规划问题总结
动态规划在笔试中是经常遇到的,本文尝试总结基本类型 1. subSet 例子:背包问题、n个数中是否存在k个数的和等于m 递归: case1:包含当前项 case2:不包含当前项 两者是或的关系
2017-05-31 20:37:04
251
翻译 堆排序
堆排序过程 1. 建立堆 2. 对堆排序 统计大文件中数据单词次数前k的问题中需要应用。 注意 : 1. 堆的建立过程是从底自上; 2. 堆的排序过程是从上自下,其过程很好理解,在建立堆的过程中要从底部向上调整元素,保证底部子节点小于父节点,如果先从父节点开始,则不能保证此性质;排序过程则需要将最大元素(最小元素)排除出去,所以是堆顶开始,从上自下调
2017-05-31 13:08:03
177
原创 C++ 字符串处理
字符串中使用最多的是字符串分割,其中包括输入getline后,对输入数据进行分割,以及字符串间的查找和分割。下面补上极其有效的分割方法。string line = "1 2 3 4 56";size_t begin = 0;while (begin != string::npos) { begin = line.find_first_not_of(' ', begin); siz
2017-05-24 12:24:51
255
翻译 二叉树的垂直遍历
对一棵树的垂直遍历 http://www.geeksforgeeks.org/print-binary-tree-vertical-order/借助 hashMap实现#include <iostream>#include <map>#include <algorithm>#include <vector>using namespace std;// A node of binary
2017-05-19 16:27:26
1661
原创 sort/map/unordered_map自定义类型如何构造比较函数
sort: 定义比较函数 / 定义比较类,用比较类定义对象 map: 比较类 / 比较函数在自定义类中提供 unordered_map: hash类的定义、 ==运算符重载 注:/代表或, 、代表并 比较函数bool compare(const) const比较类的定义 struct cmp { bool operator()(const ) const };
2017-05-19 12:13:00
2657
原创 c++ sort cmp
bool myComp(const vector<int>& a, const vector<int>& b){ /*if (a.at(1) != b.at(1)) return a.at(1) < b.at(1); else if (a.at(2) != b.at(2)) return a.at(2) < b.at(2); return fa
2017-04-08 11:15:24
897
原创 通配符、正则表达式的回溯解法
bool recursion_util(string& text, string& pattern, int pos1, int pos2){ if (pos2 == pattern.size()) return pos1 == text.size(); if (pattern.at(pos2) != '*') { if (pos1 < text.s
2017-03-31 21:59:14
265
原创 正则表达式和通配符
正则表达式用于文本中查找 通配符则用于应用中Shell正则表达式:动态规划实现bool regular_regex(string text, string pattern){ string new_pattern; int index = 0; bool isFirst = true; for (int i = 0; i < pattern.size(); i++
2017-03-28 12:24:02
300
原创 Trie
struct Node { map<char, Node*> children; bool is_end_of_word; Node() : is_end_of_word(false) {} Node(char key, Node* next) : is_end_of_word(false) { children.insert(map<char, Node*>::va
2017-03-27 14:07:10
265
原创 MyString
#include <iostream>#include <assert.h>using namespace std;class MyString{public: MyString() { data = new char[1]; data[0] = '\0'; length = 0; } MyString(const MyS
2017-03-25 22:51:02
301
转载 KMP算法
http://jakeboxer.com/blog/2009/12/13/the-knuth-morris-pratt-algorithm-in-my-own-words/1.partial_match_table的建立 2.查找#include <iostream>#include <string>#include <vector>#include <assert.h>using name
2017-03-25 14:44:15
240
原创 Qt绘制坐标系
功能:绘制坐标系,并或许坐标系第一象限的点绘制X.h文件#ifndef QCSLABEL_H#define QCSLABEL_H#include <qlabel.h>#include <qpainter.h>#include <QMouseEvent>#include <qmessagebox.h>class QCSLabel : public QLabel{ Q_OBJECTpu
2017-03-24 13:55:27
9562
原创 两个栈实现队列、两个队列实现栈 C++
1.两个栈实现队列fir_stack_入栈;sec_stack_出栈。//队列实现栈template struct MyStack { queue fir_queue_; queue sec_queue_; void push(T value) { fir_queue_.push(value); } T pop() { while(fir_queu
2017-03-23 11:16:43
391
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人