文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C++类属算法count

C++类属算法count

时间:2011-06-03  来源:孤独的猫

count是一种非可变序列算法,其功能是在序列中查找等于某个给定值的元素的个数。示例如下:

// Illustrating the generic count algorithm
#include <iostream>
#include
<cassert>
#include
<algorithm>
#include
<functional>
using namespace std;

int main()
{
cout
<< "Illustrating the generic count algorithm." << endl;
int a[] = {0, 0, 0, 1, 1, 1, 2, 2, 2};

// Count the number of values in the array a
// that are equal to 1:
int final_count = count(&a[0], &a[9], 1);

assert (final_count
== 3);

// Determine the number of array elements that are not
// equal to 1:
final_count = count_if(&a[0], &a[9],
bind2nd(not_equal_to
<int>(), 1));

// There are 6 elements not equal to 1.
assert (final_count == 6);
cout
<< " --- Ok." << endl;
return 0;
}
相关阅读 更多 +
排行榜 更多 +
谷歌卫星地图免费版下载

谷歌卫星地图免费版下载

生活实用 下载
谷歌卫星地图免费版下载

谷歌卫星地图免费版下载

生活实用 下载
kingsofpool官方正版下载

kingsofpool官方正版下载

赛车竞速 下载