基本概念
文章平均质量分 59
benbenab
这个作者很懒,什么都没留下…
展开
-
Polymorphism
最讨厌这种基本概念的题,知道都知道,就是说不清楚 Polymorphism is a powerful feature of the objected oriented programming language C++.It is the ability to use an operator or method in different ways. Polymorphism giv转载 2012-11-12 12:34:24 · 292 阅读 · 0 评论 -
如何用private 构造函数生成instance
static function in class can only access the static data member in the class.private constructor is used to prevent creating instance directly through "new" or other class. 类似于singletonclass p转载 2012-12-14 02:24:53 · 531 阅读 · 0 评论 -
OOD之思路乱发散
每一个object都含有state和method,因此定义一个object的时候一定要说明他的含有什么data member,还有什么method。多用design pattern,少用inheritance;using interfaces1. 设计一个文本编辑器 a)composite pattern来分别管理只读文本和可读写文本 b)singl原创 2012-12-17 11:37:25 · 503 阅读 · 0 评论 -
reverse bit (!!!)
如果只是reverse一个integer 可以由两种方法1. 两个bit交换typedef unsigned int uint;uint swapBits(uint x, uint i, uint j) { uint lo = ((x >> i) & 1); uint hi = ((x >> j) & 1); if (lo ^ hi) { x ^= ((1U << i转载 2012-12-17 02:58:05 · 833 阅读 · 0 评论 -
几种sort的优劣势
quicksort有最好的实践效率。同时是in-place。配上random pivot/shuffle,median-of-K 和 少量元素转insertion sort是最实用的排序方法。O(n^2)复杂度是极其小概率事件,一般不会发生。同时因为其对硬件cache的应用效率较高,实践中Quicksort很难被beat, 因为cache的访问速度比内存寻址快两个数量级。递归不仅仅转载 2012-12-14 11:42:17 · 1356 阅读 · 0 评论 -
用multiset/priority_Queue来实现最大最小堆
面试题:实现KNN,给定各个点之间的距离,返回某个点的k个neighbor。思路: 考虑到A家喜欢问海量数据,所以用heap,复杂度O(nlogk)。 当时是自己实现的heap。后来发现可以直接调用STL中的set 或者multiset来实现。 Mulitiset: STL中 set 和multisetset的含义是集合,它是一个有序的容器,里原创 2012-11-25 04:23:49 · 3878 阅读 · 0 评论 -
composite VS. inheritance
原帖link:http://www.javaworld.com/jw-11-1998/jw-11-techniques.html?page=3Inheritance:When you establish an inheritance relationship between two classes, you get to take advantage of dynamic binding转载 2012-12-22 23:44:23 · 504 阅读 · 0 评论 -
c++ 指针的几个测试例子
有关内存的思考题void GetMemory(char *p) { p = (char *)malloc(100); } void Test(void) { char *str = NULL; GetMemory(str); strcpy(str, "hello world"); printf(str); } 请问运行Test 函数会有什么样的结果?转载 2012-11-26 11:29:33 · 329 阅读 · 0 评论 -
最大公约数 最小公倍数
给2个整数 相除,输出精确结果如果是非循环,输出所有数字, 如果是循环数,标注哪里开始循环用长除做 然后用表记下来之前的余数1. 先找到最大公约数2. a/b 只可能有 b-1种余数, 然后建一个 大小为 b的 hashtable或者数组,查找是不是有重复3. 如果 x/k 0Greatest common divisor 最大公约数least转载 2012-12-06 09:06:26 · 785 阅读 · 0 评论 -
快速排序思想的利用
1,输入一个数组,实现一个函数来调整数组中数字的位置,使得所有奇数位位于数组前半部分,所有偶数位于数组后半部分。2. 输入一个数组,实现一个函数来调整数组中数字的位置,所有负数位位于数组前半部分,所有正数位于数组后半部分。诸如此类,根据一个条件把一个数组分成前后两个部分,都可以用快速排序的思想!!!!转载 2012-11-22 09:38:45 · 347 阅读 · 0 评论 -
How do virtual functions work in C++?
A virtual function depends on a “vtable” or “Virtual Table.” If any function of a class is declared to be virtual, a vtable is constructed which stores addresses of the virtual functions of this class转载 2012-11-12 12:43:41 · 350 阅读 · 0 评论 -
deep copy 带有random的linklist
题目:有一个链表L,其每个节点有2个指针,一个指针next指向链表的下个节点,另一个random随机指向链表中的任一个节点,可能是自己或者为空,写一个程序,要求复制这个链表的结构并分析其复杂性解决方法一:O(n)的复杂度,扫面两边即可。缺点:修改了原始的链表转载 2012-12-20 23:48:58 · 496 阅读 · 0 评论