摘要:Implement a firewallprototype:bool firewall(string url, list<string> IncludedList, List<string> ExcludedList)Return true if the url is in included listReturn false if the url is in exclude... 阅读全文
print a complete binary tree anti-clockwise
2010-10-01 20:46 by wansishuang, 299 阅读, 0 推荐, 收藏, 编辑
摘要:Print all edge nodes of a complete binary tree anti-clockwise. That is all the left most nodes starting at root, then the leaves left to right and finally all the rightmost nodes.In other words, print... 阅读全文
Check whether string is interleaved
2010-10-01 09:59 by wansishuang, 154 阅读, 0 推荐, 收藏, 编辑
摘要:Three strings say A,B,C are given to you. Check whether 3rd string is interleaved from string A and B. Ex: A="abcd" B="xyz" C="axybczd". answer is yes.如果元素不相同的话,可以类似归并排序在0(N)时间内解决。如果不想同的话,可以递归的解决f(a, ... 阅读全文
Represent all the dates with tow cubes
2010-09-26 19:44 by wansishuang, 122 阅读, 0 推荐, 收藏, 编辑
摘要:Given two cubes, how will you represent all the dates in a month by using numbers 0 to 9? You can exchange the cubes and rotate them as you wish!!!1: 01 2 3 4 5 2: 0 1 26 7 8 阅读全文
筛选法求素数
2010-09-26 19:28 by wansishuang, 173 阅读, 0 推荐, 收藏, 编辑
摘要:#include #include #include #include #include //#include int main() { int num; printf("Find primes up to: "); scanf("%d", &num); clock_t start, stop; assert((start = clock... 阅读全文
寻找单链表中的环
2010-09-26 19:21 by wansishuang, 322 阅读, 0 推荐, 收藏, 编辑
摘要:ZZ: http://ostermiller.org/find_loop_singly_linked_list.htmlFinding a Loop in a Singly Linked ListMotivationA singly linked list is a common data structure familiar to all computer scientists. A singl... 阅读全文
assignment operator:对class中const成员变量赋值
2010-09-26 19:19 by wansishuang, 276 阅读, 0 推荐, 收藏, 编辑
摘要:#include using namespace std; class Test { public: Test(int _a):a(_a) { } Test& operator=(const Test& ra) { if(&ra != this) { const_cast(a) = ra.a; ... 阅读全文
String, StringBuffer, StringBuilder区别
2010-09-25 23:26 by wansishuang, 641 阅读, 0 推荐, 收藏, 编辑
摘要:String是非可变类,其对象为字符串常量,不适合频繁改变,如插入(insert),删除(delete),添加(append)等。StringBuffer是可变类,其对象为可修改的字符序列,比较适合用来频繁的修改字符串,比如常用的是添加(append);而且是线程安全的。当需要多次修改时,尽量用这个类。具体地说,当你使用Stringb = b+"aa";这样的语句的时候b实际上已经不是以前的那个对... 阅读全文
hibernate的锁机制
2010-09-25 23:06 by wansishuang, 889 阅读, 0 推荐, 收藏, 编辑
摘要:hibernate锁机制包括悲观锁和乐观锁1.悲观锁:它指的是对数据被外界修改持保守态度。假定任何时刻存取数据时,都可能有另一个客户也正在存取同一笔数据,为了保持数据被操作的一致性,于是对数据采取了数据库层次的锁定状态,依靠数据库提供的锁机制来实现。基于jdbc实现的数据库加锁如下:select*fromaccountwherename="Erica"forupdate.在更新的过程中,数据库处于... 阅读全文
Find min elements in the Stack
2010-09-25 19:46 by wansishuang, 244 阅读, 0 推荐, 收藏, 编辑
摘要:Implement a stack which supports FindMin(),push() and pop(). The probability of the occurrence is equal.Maintain two stacks. In 1st, maintain the values in order of their push event. while in 2nd stac... 阅读全文