2012年12月14日
摘要: #include <iostream>#include <stack>#include <string>using namespace std;//merge a b两个排序过的数组,a的size是m,b的size是n,a具有足够大的空间存放merge后的元素们//思想是从后往前merge,因为后面都是没有存放数的空间,所以可以避免数组的平移void Merge(int a[], int b[], int m, int n){ int mWalker = m-1; int nWalker = n-1; for (int i = m+n-1 ; i > 阅读全文
posted @ 2012-12-14 16:29 kkmm 阅读(294) 评论(0) 推荐(0) 编辑
摘要: Imagine a (literal) stack of plates If the stack gets too high, it might topple There-fore, in real life, we would likely start a new stack when the previous stack exceeds some threshold Implement a data structure SetOfStacks that mimics this SetOf-Stacks should be composed of several stacks, and sh 阅读全文
posted @ 2012-12-14 16:14 kkmm 阅读(716) 评论(0) 推荐(0) 编辑
摘要: 本方法借鉴自glibc,可以过滤如下情况:前缀空格非法输入正负号16进制8进制溢出1234L#include <iostream>using namespace std;#define LONG_MAX 2147483647L#define LONG_MIN -2147483648Llong StrToInt(const string &str){ unsigned long result = 0;//如果不用unsigned long,那么后面无法判断溢出(当发生溢出时,总是负数) int radix = 0; int sign = 1; string::const_.. 阅读全文
posted @ 2012-12-14 14:46 kkmm 阅读(244) 评论(0) 推荐(0) 编辑