STL中unique函数的使用
摘要:STL中unique函数的使用 我们都知道unique的功能是去除相邻的重复元素(只保留一个),还有一个容易忽视的特性是它并不真正把重复的元素删除,不知道这个特性用起来就会出问题。比如下面这个例子,企图输出无重复的元素,中国自学编程网,www.zxbc.cn:#include<iostream>#include<vector>#include<algorithm>#include<iterator>usingnamespacestd;intmain()...{ vector<int>ivec; copy(istream_iterato
阅读全文
posted @
2012-10-03 00:08
cchun
阅读(271)
推荐(0)
pair与make_pair
摘要:【好记性不如烂笔头:在《C++ Templates》看到这个函数,发现正是前段时间写项目程序所要用到的,可惜当时还不知道有这个用法,当时是自己写了个结构体。。】Utilities <utility>由短小精干的类和函数构成,执行最一般性的工作。这些工具包括:general types一些重要的C函数numeric limitsPairsC++标准程序库中凡是“必须返回两个值”的函数, 也都会利用pair对象classpair可以将两个值视为一个单元。容器类别map和multimap就是使用pairs来管理其健值/实值(key/value)的成对元素。pair被定义为struct,因
阅读全文
posted @
2012-09-05 23:14
cchun
阅读(370)
推荐(0)
转_int ,long , long long, __int64类型的范围
摘要:unsigned int 0~4294967295 int 2147483648~2147483647unsigned long 0~4294967295long 2147483648~2147483647long long的最大值:9223372036854775807long long的最小值:-9223372036854775808unsigned long long的最大值:1844674407370955161__int64的最大值:9223372036854775807 (19位)__int64的最小值:-9223372036854775808unsigned __int64的最.
阅读全文
posted @
2012-07-30 17:47
cchun
阅读(1597)
推荐(0)
转:STL:string 大小(Size)和容量(Capacity)
摘要:strings存在三种“大小”:1、size()和length() 返回string中现在的字符个数。上述两个函数等效。成员函数empty()用来检验字符数是否为0,亦即字符串是否为空。你应该优先使用该函数,因为它比length()或size()来得快。也就是说,使用if(s.empty()==true)而不使用if(s.size()==0)(笔者注)2、max_size() 此函数返回一个string最多能够包含的字符数。一个string通常包含一块单独内存区块内的所有字符,所以可能跟PC机器本省的限制有关系。返回值一般而言是索引型别的最大值减1。之所以“减1”有两个原因:(a)最大值本身.
阅读全文
posted @
2012-06-27 01:04
cchun
阅读(385)
推荐(0)
STL中的equal函数
摘要:STL中的equal函数:template<class InputIterator1, class InputIterator2> bool equal( InputIterator1 _First1, InputIterator1 _Last1, InputIterator2 _First2 );template<class InputIterator1, class InputIterator2, class BinaryPredicate> bool equal( InputIterator1 _First1, I...
阅读全文
posted @
2012-06-10 15:06
cchun
阅读(2074)
推荐(0)
C++之lexicographical_compare
摘要:C++之lexicographical_comparelexicographical_compare: C++ STL 泛型算法函数:用于按字典序比较两个序列。函数申明:/**重载1如果[first1, last1)按字典序列小于[first2, last2),返回true,否则返回false。*/template <class InputIterator1, class InputIterator2 >bool lexicographical_compare( InputIterator1 first1, InputIterator1 last1, InputIterator2
阅读全文
posted @
2012-06-10 15:01
cchun
阅读(768)
推荐(0)
转:C++学习【原创】归并排序(inplace_merge函数的应用)
摘要:inplace_merge函数的作用和merge函数差不多,只不过是在一个容器中进行归并。函数参数:inplace_merge(first,mid,last,compare);//将[first,mid) 和 [mid,last)这两个区间进行归并成一个有序序列。注意:[first,mid)和[mid,last)都要呈升序或降序排列!还记得归并排序的写法么?归并排序利用了分治的思想,将一个容器分割,然后再将它们一个个合并起来,最后形成一个有序的序列。归并排序的核心代码就在于合并两个序列,不过STL的开发人员已经为我们完成了,我们直接调用就可以了。例题:给你n个学生的信息,根据它们的分数从小到大
阅读全文
posted @
2012-05-26 17:45
cchun
阅读(5401)
推荐(0)