2007-02-16から1日間の記事一覧

vector で 2次元配列

cxx

#include <vector> #include <iostream> using namespace std; int main() { vector<vector<double> > table(2, vector<double>(2)); table[0][0] = 0.1; table[0][1] = 0.2; table[1][0] = 0.3; table[1][1] = 0.4; for ( vector<vector<double> >::iterator i = table.begin(), e = table.end(); i != e; ++i ) { fo</vector<double></double></vector<double></iostream></vector>…

比較関数

http://d.hatena.ne.jp/odz/20070212/1171345311 これに気づかないのはけっこう危険ですね。 int cmp(const int *a, const int *b) { return *a - *b; }たとえば INT_MIN - INT_MIN はオーバーフローにより 0 でない値をとる。 Nearly All Binary Searches a…