min_element/max_element

void TestMaxElement()
{
    vector<int> vi{1,7,9,3,15,6,20};
    for (auto i:vi)
    {
        cout << i << std::endl;
    }
    auto begin = vi.begin()+2;
    std::cout << *begin << std::endl;

    //Returns an iterator pointing to the element with the smallest value in the range [first,last)
    //注意最后一个元素是闭区间
    std::cout << "The smallest element is " << *std::min_element(vi.begin(), vi.begin() + 2) << '\n';
    std::cout << "The largest element is " << *std::max_element(vi.begin(), vi.begin() + 2) << '\n';
}

 

posted @ 2021-02-26 23:33  Truman001  阅读(45)  评论(0编辑  收藏  举报