STL中,堆为算法(需要#include<algorithm>),而非容器。许是因为堆的最大作用就是排序吧!堆是完全二叉树。堆的相关函数是:make_heap,pop_heap,push_heap(),sort_heap.堆排序算法sort_heap的使用是有限制的:sort_heap的输入比须是一个有效的堆。所以,驾驭sort_heap前最好做如下两点:1.调用sort_heap前,调用make_heap.2.sort_heap的基本排序算法(即sort_heap的第三个参数)要和make_heap的第三个参数一致。例如,有一个vector<int>v;首先调用mak Read More
posted @ 2011-08-03 01:27 iliveido Views(443) Comments(0) Diggs(0)
1.remove_if函数(算法)的原型: template < class ForwardIterator, class Predicate > ForwardIterator remove_if ( ForwardIterator first, ForwardIterator last,Predicate pred ); 其中ForwardIterator是前向迭代器类型,例如vector<int>::iterator,vector<float>::iterator。Predicate是一个二元函数。 二元函数是继承了binary_function类,并 Read More
posted @ 2011-08-01 21:19 iliveido Views(462) Comments(0) Diggs(0)
第一个仿函数的demo:仿函数,就是实现了operator()重载的类。“Generically, function objects are instances of a class with member function operator() defined. This member function allows the object to be used with the same syntax as a regular function call,and therefore it can be used in templates instead of a pointer to a f Read More
posted @ 2011-08-01 15:56 iliveido Views(540) Comments(2) Diggs(0)
c++文件的打开模式有六个:in,out,ate,app,trunc,binary。如果你输出它们cout<<ios_base::in<<endl;的话,会看到它们的值分别是1,2,4,8,16,32.但是,它们的值并不能说明什么,因为我不知道fstream类的构造函数是怎样通过它们的组合的值来决定文件打开时的状态的。问题:按照排列组合的知识,6个模式的组合数等于2^6-1,即63种组合。这其中哪些组合是无效的?我想说的是,其实这六种模式是互相影响的,所以我没有办法看到一种组合就判别出文件打开时的状态。最让我头痛的就是两个问题:如果文件不存在,会不会创建?如果文件存在, Read More
posted @ 2011-08-01 12:34 iliveido Views(475) Comments(2) Diggs(0)