摘要: * Binary tree的资料~http://cslibrary.stanford.edu/110/BinaryTrees.html1. Print binary tree in level orderclass Node{public: Node(int v) { value = v; left = 0; right = 0; } int value; Node *left; Node *right;};//Print binary tree in level ordervoid BST::bfs(Node *p){ queue<Node *> q; q.push(p); q. 阅读全文
posted @ 2011-08-05 12:21 Sw_R 阅读(163) 评论(0) 推荐(0) 编辑
摘要: I have not figured out the parentheses and points yet.int infix(string exp){ stack<int> numStack; //for parsing the operand stack<int> operandStack; //for store the operands stack<char> operatorStack; // operators for(int i=0; i<exp.size(); i++) { if(exp[i] == ' ') { bre 阅读全文
posted @ 2011-08-01 01:23 Sw_R 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 1. use a hashmap.#include<unordered_map>#include<iostream>#include<fstream>using namespace std;int main(){ ifstream file("a.txt"); string line; unordered_map<char, int> hashmap; unordered_map<char, int>::iterator itr; while(file.good()) { char c = file.get(); 阅读全文
posted @ 2011-07-30 13:35 Sw_R 阅读(163) 评论(0) 推荐(0) 编辑
摘要: This is a typical technical interview question.First, we have to know what is a LRU cache. http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_UsedLeast Recently Used(LRU): discards the least recently used items first. This algorithm requires keeping track of what was used when, which is ex 阅读全文
posted @ 2011-07-29 15:30 Sw_R 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 1. Waterfall model:2. Extrem programming: 阅读全文
posted @ 2011-07-16 10:16 Sw_R 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 1.C实现atoi: string转成int,这个函数最基本的要考虑益处和符号。这里不太清楚怎么判断整数溢出了。。int myatoi(const char* str){ int i = 0; int sign = 1; if(*str == '-') { sign = 0; str++; } while(*str) { i = i*10 + *str - '0'; str++; } if(sign == 0) i *= -1; return i;}2.arraylist里面有乱序的数字,如何找出两个数字使得和为0, O(n), 如何找出三个数字和为0, O(n 阅读全文
posted @ 2011-07-14 08:15 Sw_R 阅读(402) 评论(0) 推荐(0) 编辑
摘要: 1. pass by reference or pointer:The difference is that a pointer can also point to nothing by pointing to null, where as a reference is always associated with an object. (对于c++的一些F&Q)http://www.parashift.com/c++-faq-lite/references.html2.Differentiate JVM JRE JDK JIT:Java Virtual Machine (JVM) i 阅读全文
posted @ 2011-06-27 15:29 Sw_R 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 1 #ifndef THREEMERGESORT_H 2 #define THREEMERGESORT_H 3 4 const int size = 100000; //The size of array 5 6 void ThreeMerge(int *, int, int); 7 void Merge(int *, int, int, int, int); 8 void Merge2(int *,int,int,int); 9 10 #endif 1 #include<iostream> 2 #include"ThreeMergeSort.h" 3 4 us 阅读全文
posted @ 2011-06-20 04:20 Sw_R 阅读(210) 评论(0) 推荐(0) 编辑