版本号是一个字符串,主要考虑以下三种用例,点分的个数一致还好,不一致需要注意
#include <boost/algorithm/string.hpp>
#include <algorithm>
#include <vector>
#include <string>
bool version_less_than(std::string str_version_a, std::string str_version_b)
{
std::vec…… 阅读全文
Tag Archives: STL
std::next_permutation
std 中有一个 next_permutation 的算法,见这里,http://en.cppreference.com/w/c…,这个页面上面有一个实现
template<class BidirIt>
bool next_permutation(BidirIt first, BidirIt last)
{
if (first == last) return false;
BidirIt i = last;
if (first == --i) return false;
…… 阅读全文
STL set 的一些实现差异
侯捷大师在 STL 源码剖析中说道,set 的迭代器的值是不可改变的,这个本来很好理解,但是我神奇的在 visual studio 2005 上发现,神奇的事情总是会发生
#include <stdio.h>
#include <map>
#include <string>
#include <set>
int main() {
std::set<int> setInt;
setIn…… 阅读全文
STL map 的一个问题
先看看这个代码
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
map<int, vector<int> > map_a, map_b;
map_a[0].push_back(0);
map_b[0] = map_a[0];
map_b[0].push_back(0);
cout<<map_a[0].size(…… 阅读全文
栈结构练习
今天从刘汝佳的书上看到一个简单的栈的题目
有n节车厢从A方向驶入车站,按进站顺序编号1~n。现让这些火车按照某种特定的顺序进入B方向的铁轨并驶出车站。为了重组车厢,可以借助中转站C。C是一个可以停放任意多节车厢的车站,但由于末端封顶,驶入C的车厢必须按照相反的顺序驶出C。对于每个车厢,一旦从A移入C,就不能再…… 阅读全文
二叉树的遍历
参考 http://blog.csdn.net/acdnjjjdj… 写了二叉树的遍历,(基本上就是照抄的,囧),抄的时候感慨,stl 真是个好东西啊,另外,在三种次序遍历的实现上,递归的精巧发挥的淋漓尽致啊,还有就是非递归的遍历,设计真的好巧妙
#include <iostream>
#include <queue>
#include <stack>
using n…… 阅读全文