随笔分类 -  C/C++

摘要:代码中存在bug,暂时无法修复 阅读全文
posted @ 2017-08-21 23:22 wxquare 阅读(619) 评论(0) 推荐(0) 编辑
摘要:转:http://www.cnblogs.com/woshizyl/archive/2012/09/16/2800320.html 参考:http://www.cnblogs.com/suncoolcat/p/3339624.html 前段时间专心面过腾讯,经过了N轮的技术面,结果还是挂了,但没挂在 阅读全文
posted @ 2017-08-16 09:24 wxquare 阅读(2008) 评论(0) 推荐(0) 编辑
摘要:1.windows/linux,多线程/多进程 IBM测试,切换线程context的时候,windows比linux快一倍多。进出最快的锁(windows2k的 critical section和linux的pthread_mutex),windows比linux的要快五倍左右。可见多线程这个具体的 阅读全文
posted @ 2017-08-11 11:37 wxquare 阅读(1105) 评论(0) 推荐(0) 编辑
摘要:阿里内推二面编程题:实现一个生成者消费者模型 要求:1、多线程生产者、多线程消费者2、当队列超过>100时,生产者停止生产,队列<20,消费者停止消费3、适当加一些print来验证你的程序,不然整个程序跑起来,你是不知道程序是什么情况的 阅读全文
posted @ 2017-08-10 15:54 wxquare 阅读(1409) 评论(0) 推荐(0) 编辑
摘要:参考:深入应用C++11,访问者模式 阅读全文
posted @ 2017-08-08 10:21 wxquare 阅读(435) 评论(0) 推荐(0) 编辑
摘要:面试中可能遇到让设计一个无法被继承的类。最简单的实现是将该类的构造函数设置为私有的,然后通过静态成员函数调用私有构造函数实例化对象,这样的类确实不可继承,但是使用起来非常不方便,必须使用静态成员实例化对象,而且对象存储在堆中,无法像一个普通的类一样的被使用。最佳的设计是结合私有构造函、友元、虚拟继承 阅读全文
posted @ 2017-08-06 17:25 wxquare 阅读(939) 评论(0) 推荐(0) 编辑
摘要:1 #include 2 #include 3 4 std::mutex mtx; 5 class Singleton { 6 private: 7 Singleton() {} 8 Singleton(const Singleton& a); 9 Singleton& operator=(const Singleton&); 10 sta... 阅读全文
posted @ 2017-08-06 17:24 wxquare 阅读(325) 评论(0) 推荐(0) 编辑
摘要:1 #include 2 3 enum CTYPE {PRODUCTA,PRODUCTB}; 4 class Product{ 5 public: 6 virtual void func() = 0; 7 virtual ~Product(){}; 8 }; 9 10 class ProductA : public Product{ 11 public: ... 阅读全文
posted @ 2017-08-06 17:24 wxquare 阅读(500) 评论(0) 推荐(0) 编辑
摘要:1 #include 2 3 class Subject; 4 5 class Observer{ 6 public: 7 virtual ~Observer(){}; 8 virtual void update(Subject * sub){}; 9 protected: 10 Observer(){}; 11 12 }; 13 14 cla... 阅读全文
posted @ 2017-08-06 17:20 wxquare 阅读(526) 评论(0) 推荐(0) 编辑
摘要:1 #include 2 3 struct BSTNode { 4 int key; 5 BSTNode* left; 6 BSTNode* right; 7 BSTNode(int x) : key(x), left(nullptr), right(nullptr) { 8 } 9 }; 10 11 //re... 阅读全文
posted @ 2017-08-03 15:40 wxquare 阅读(417) 评论(0) 推荐(1) 编辑
摘要:最近在做笔试题,相比与leetcode,笔试题都是要自己写输入输出的,每次在这里都浪费了不少时间,这篇文章总结了一下在C++中怎么向数组中输入数据。 1. 先输入数组大小,然后输入数据数据,中间以空格或者'\n'字符隔开 2、输入以','字符分割的数据,思路将输入保存为字符串,然后转换为具体的数据 阅读全文
posted @ 2017-08-02 22:51 wxquare 阅读(1216) 评论(0) 推荐(0) 编辑
摘要:一、全排列 递归暴力DFS: 面试中,排列组合的实现是需要掌握的。一般最先想到的方法是暴力循环法,即对于每一位,遍历集合中可能的元素,如果在这一位之前出现过了该元素,跳过该元素。例如对于abc,第一位可以是 a 或 b 或 c 。当第一位为 a 时,第二位再遍历集合,发现 a 不行,因为前面已经出现 阅读全文
posted @ 2017-08-01 22:20 wxquare 阅读(855) 评论(0) 推荐(0) 编辑
摘要:1 #include 2 #include 3 using namespace std; 4 5 int selectKth(int a[],int start,int end,int k){ 6 assert(start = pivotVal) right--; 12 a[left] = a[right]; 13 while(left ... 阅读全文
posted @ 2017-08-01 15:14 wxquare 阅读(419) 评论(0) 推荐(0) 编辑
摘要:vector类的简单实现 阅读全文
posted @ 2017-07-27 23:13 wxquare 阅读(834) 评论(0) 推荐(2) 编辑
摘要:1.int atoi(const char* src) nullptr指针 空白字符' ','\t','\n' 符号位 避免值溢出 出错信息保存在全局变脸errnum中 2. char* itoa(int val,char* buf,size_t radix) 指针有效性判断 符号位 基数(10,1 阅读全文
posted @ 2017-07-27 17:11 wxquare 阅读(429) 评论(0) 推荐(0) 编辑
摘要:1 #include 2 #include 3 using namespace std; 4 5 6 class CString { 7 private: 8 char* m_pdata; 9 public: 10 CString(const char* ptr = nullptr) { 11 if (ptr == nullptr) m... 阅读全文
posted @ 2017-07-27 14:54 wxquare 阅读(737) 评论(0) 推荐(0) 编辑
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 7 struct TreeNode{ 8 int val; 9 TreeNode* left; 10 TreeNode* right; 11 TreeNode(int x):val(x),left... 阅读全文
posted @ 2017-07-27 10:45 wxquare 阅读(858) 评论(0) 推荐(0) 编辑
摘要:1 /* 2 * testmain.cpp 3 * 4 * Created on: 2017年7月16日 5 * Author: Administrator 6 */ 7 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14... 阅读全文
posted @ 2017-07-19 11:45 wxquare 阅读(313) 评论(0) 推荐(0) 编辑
摘要:1. void *mymemcpy(void *dest, const void* src, size_t n); 内存拷贝函数,memcpy函数的功能是从源src所指的内存地址的起始位置开始拷贝n个字节到目标dest所指的内存地址的起始位置中 2.void *memset(void *s, int 阅读全文
posted @ 2017-07-19 11:38 wxquare 阅读(761) 评论(0) 推荐(0) 编辑
摘要:1 //recursive 2 int binarySearch(int a[],int start,int end,int k){ 3 if(start > end) return -1; 4 int mid = start + (end -start) /2; 5 if(k == a[mid]) return mid; 6 else if(a[mi... 阅读全文
posted @ 2017-07-18 10:00 wxquare 编辑