09 2013 档案

交差方向遍历bfs 树
摘要:import java.util.ArrayList;import java.util.LinkedList;import java.util.List;import java.util.Queue;import java.util.Stack;enum Dirction {left , right} public class Tree { private BinaryTreeNode root; private List list = new ArrayList(); Dirction current = Dirction.right; ... 阅读全文

posted @ 2013-09-20 05:40 brave_bo 阅读(221) 评论(0) 推荐(0)

linkedlist 最难题 Insert into a Cyclic Sorted List
摘要:Given a node from a cyclic linked list which has been sorted, write a function to insert a value into the list such that it remains a cyclic sorted li... 阅读全文

posted @ 2013-09-09 05:38 brave_bo 阅读(362) 评论(0) 推荐(0)

洗牌 算法
摘要:1. for i:=1 to n do swap(a[i], a[random(1,n)]); // 凑合,但不是真正随机2. for i:=1 to n do swap(a[i], a[random(i,n)]); // 真正的随机算法其中,random(a,b)函数用于返回一个从a到b(包括a和b)的随机整数。2)的时间复杂度O(n), 空间复杂度O(1); 阅读全文

posted @ 2013-09-09 05:02 brave_bo 阅读(161) 评论(0) 推荐(0)

Maximum Depth of Binary Tree
摘要:Maximum Depth of Binary TreeMaximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Solution - RecursionThe recursion algorithm is easy to come up:Perform a DFS (depth-fi 阅读全文

posted @ 2013-09-09 03:45 brave_bo 阅读(157) 评论(0) 推荐(0)

Exceptions Interview Questions
摘要:Exceptions Interview QuestionsQ1) What is an Exception?Ans) The exception is said to be thrown whenever an exceptional event occurs in java which signals that something is not correct with the code written and may give unexpected result. An exceptional event is a occurrence of condition which alters 阅读全文

posted @ 2013-09-08 14:40 brave_bo 阅读(328) 评论(0) 推荐(0)

死锁问题详解
摘要:synchronized 关键字,代表这个方法加锁,相当于不管哪一个线程A每次运行到这个方法时,都要检查有没有其它正在用这个方法的线程B(或者C D等),有的话要等正在使用这个方法的线程B(或者C D)运行完这个方法后再运行此线程A,没有的话,直接运行它包括两种用法:synchronized 方法和 synchronized 块。 1. synchronized 方法: 通过在方法声明中加入 synchronized关键字来声明 synchronized 方法。如: publicsynchronizedvoid accessVal(int newVal); synchronized ... 阅读全文

posted @ 2013-09-08 14:29 brave_bo 阅读(261) 评论(0) 推荐(0)

implement singleton
摘要:Two way to implement singleton patternpostedSep 12, 2011, 1:35 PMby Akrem AYADI [updatedSep 12, 2011, 2:00 PM]You find bellow the two ways to implemen... 阅读全文

posted @ 2013-09-08 14:29 brave_bo 阅读(315) 评论(0) 推荐(0)

OOP parking slot
摘要:public interface Permission{ float getFee(Calendar start, Calendar end);}class ParkingLot{ private list freeRegularSpace; private list freeCompactSpace; private list freeHandicappedSpace;public ParkingLot(); public ParkingSpace allocateFreeSpace(ParkingSpaceType pspaceType) { ... 阅读全文

posted @ 2013-09-06 14:00 brave_bo 阅读(373) 评论(0) 推荐(0)

导航