摘要: 访问者模式 优点: 对扩展开放,对修改关闭。增加一种新的操作只需要增加一个Visitorn即可 一个Visitorn只负责一种操作,单一指责原则 缺点: 违反了最少知道原则,降低了封装度 违反了依赖倒置原则,依赖了具体类 不适合经常新增ElementX的情况 阅读全文
posted @ 2017-03-08 10:53 txlstars 阅读(98) 评论(0) 推荐(0) 编辑
摘要: C++实现单例模式 singleton.h singleton.cpp 编译: 刚刚学习单例模式,不足之处希望大家多多指教 阅读全文
posted @ 2017-02-04 21:18 txlstars 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 1、实现一个memcpy函数:memcpy(void *p, void *q, unsigned len); 思路:1、注意p、q是否为NULL 2、内存重叠的情况 3、每次copy字节数:32系统可以选择4字节如int,64系统可以选择8字节如long long 2、STL中vector的实现原理 阅读全文
posted @ 2016-09-05 11:03 txlstars 阅读(1148) 评论(0) 推荐(0) 编辑
摘要: 二维数组中的查找: 题目描述:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 两种思路各有优势: 1、行枚举列二分O(nlogm)(列二分行枚举O(mlogn)) 2、从左下角或右 阅读全文
posted @ 2016-07-27 18:23 txlstars 阅读(6305) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 3 template 4 struct rb_node 5 { 6 T key; 7 bool color;//true red | false black 8 std::shared_ptr lchild, rchild, parent; 9 10 rb_node(T key, boo... 阅读全文
posted @ 2016-07-10 19:17 txlstars 阅读(317) 评论(0) 推荐(0) 编辑
摘要: 1 #include //智能指针头文件 2 #include //随机数头文件 3 #include 4 #include 5 #include //time头文件 6 7 template 8 struct node 9 { 10 T key; 11 unsigned weight; 12 std::shared_ptr... 阅读全文
posted @ 2016-07-09 13:22 txlstars 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 1、位基本操作符: 与 & 或 | 非 异或 ^ 移位 >>、<< 2、应用: 1、判断一个数是不是4的次幂 ( (x & (x - 1)) == 0 ) && ( (x & 0x55555555) == x) 2、获取负数 -x = (~x + 1) 3、交换两个数 int a, b; a = a 阅读全文
posted @ 2016-05-11 20:41 txlstars 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 题目分析: Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome. Example 1... 阅读全文
posted @ 2016-05-07 09:27 txlstars 阅读(751) 评论(0) 推荐(0) 编辑
摘要: 摘要 本文解释如下几个问题: 1.-fpic和-fPIC的区别和联系 2.-shared和-fpic的共用问题 3.PIC解决了什么问题 阅读全文
posted @ 2016-05-04 16:55 txlstars 阅读(1923) 评论(0) 推荐(1) 编辑
摘要: 可重入函数 在实时系统的设计中,经常会出现多个任务调用同一个函数的情况。如果这个函数不幸被设计成为不可重入的函数的话,那么不同任务调用这个函数时可能修改其他任 务调用这个函数的数据,从而导致不可预料的后果。那么什么是可重入函数呢?所谓可重入是指一个可以被多个任务调用的过程,任务在调用时不必担心数据是 阅读全文
posted @ 2016-04-17 15:59 txlstars 阅读(264) 评论(0) 推荐(0) 编辑