zoukankan      html  css  js  c++  java
  • STL——容器,算法和迭代器的基本概念

    容器:序列式容器;关联式容器。

    迭代器:是一个类,类中封装一个指针,可以当成指针来用。

    算法:解决某一个问题的有限步骤。

    算法与容器是分离的,迭代器起到了连接算法与迭代器的作用:

    #include <iostream>
    using namespace std;

    //算法
    int mycount(int* pBegin, int* pEnd, int val)
    {
    int num = 0;
    while (pBegin != pEnd)
    {
    if (*pBegin == val)
    {
    num++;
    }
    pBegin++;
    }
    return num;
    }

    int main()
    {
    //容器
    int arr[] = {0, 7, 5, 4, 9, 2, 0};

    //迭代器
    int* pBegin = arr;
    int* pEnd = &(arr[sizeof(arr) / sizeof(int)]);

    cout << 1 << "在数组中的个数为:" << mycount(pBegin, pEnd, 1) << endl;
    system("pause");
    return 0;
    }

  • 相关阅读:
    人月神话2
    cJson 常见用法
    Python C扩展
    动态链接--运行时加载dlopen
    mtrace 简介
    Linux coredump
    动态链接--so的搜索过程
    线程同步--条件变量
    编译过程学习
    Linux 信号
  • 原文地址:https://www.cnblogs.com/mengjuanjuan/p/9839107.html
Copyright © 2011-2022 走看看