C++STL
前导
#include<iostream>
#include<cstdlib>
using namespace std;
//算法 负责统计元素个数
int count_elements(int*start,int*end,int value)
{
int num = 0;
while (start!=end)
{
if (*start==value)
{
num++;
}
start++;
}
return num;
}
int main()
{
/*
STL:
容器(序列式容器,关联式容器)
迭代器(相当于指针 默认指向第一个元素)
算法:通过有限步骤解决问题
*/
//数组容器
int scores[] = {45,67,87,90,54,89,87,87};
int* pBegin = scores;//迭代器开始位置
int* pEnd =& (scores[sizeof(scores) / sizeof(int)]);
int num=count_elements(pBegin, pEnd, 87);
cout << "num:\t" <<num<< endl;
system("pause");
}
posted on 2019-04-29 15:54 Indian_Mysore 阅读(81) 评论(0) 收藏 举报
浙公网安备 33010602011771号