美文网首页
STL forward_list容器成员函数

STL forward_list容器成员函数

作者: coolTigers | 来源:发表于2020-05-10 00:13 被阅读0次

通过示例学习单向链表的几个函数

#include "monotonicallyStack.h"
#include<iostream>
#include <vector>
#include <forward_list>
using namespace std;

int main()
{
    forward_list<std::string> my_words{ "three","six","eight" };
    auto count = std::distance(std::begin(my_words), std::end(my_words));
    cout << count << endl; // 3
    cout << "====================" << endl;

    std::forward_list<int> data{ 10,21,43,87,175,351 };
    auto iter = std::begin(data);
    size_t n{ 3 };
    std::advance(iter, n);
    cout << "The " << n + 1 << "th element is " << *iter << endl; // 87
    cout << "====================" << endl;

    forward_list<string> your_words{"seven", "four", "nine"};
    my_words.splice_after(my_words.before_begin(), your_words);
    cout << "your_words: " << endl;
    for (auto iter : your_words)
    {
        cout << iter << endl;
    }
    cout << "my_words: " << endl;
    for (auto iter : my_words)
    {
        cout << iter << endl;
    }
    cout << "====================" << endl;

    forward_list<int> iflst= { 1,2,3,4,5,6 };

    auto pre = iflst.before_begin();
    auto curr = iflst.begin();

    while (curr != iflst.end()) {
        if (*curr & 1) {
            curr = iflst.erase_after(pre);
        } else {
            pre = curr;
            ++curr;
        }
    }

    for (auto iter : iflst) {
        cout << iter << endl;
    }
    return 0;
}

打印结果如下:


image.png

相关文章

  • STL forward_list容器成员函数

    通过示例学习单向链表的几个函数 打印结果如下:

  • C++ STL 之 forward_list

    本节我们将介绍 STL 中的 forward_list 容器使用。 forward_list 容器以单链表的形式存...

  • C++ STL 之 array(二)

    今天我们继续更新 C++ STL 中 array 容器的使用 array迭代器 array 容器定义了成员函数 b...

  • C++11——顺序容器

    forward_list和array容器 新标准添加了forward_list和array容器。array容器是内...

  • 容器是否带find()函数

    array、vector、deque、list、forward_list不带find()成员函数,如需使用,可使用...

  • 容器是否带count函数

    array、vector、deque、list、forward_list不带count成员函数,如需使用,可使用全...

  • 22. C++ STL pair类模板

    在C++关联容器的基础是pair 类模板,我们先了解 STL 中的 pair 类模板,因为关联容器的一些成员函数的...

  • 2019-10-13 STL模板

    STL共有六大组件 1、容器 2、算法 3、迭代器 4、仿函数 6、适配器 STL容器的实现原理 STL来管理数据...

  • C++ STL是什么

    STL 组件主要包括容器,迭代器、算法和仿函数。STL 基本结构和 STL 组件对应。 STL 主要由迭代器、算法...

  • 第十六章 string类和标准模板库(6)算法

    (六)算法 STL包含了许多处理容器的非成员函数,它们都使用迭代器来标识要处理的数据区间和结果存放的位置,有些函数...

网友评论

      本文标题:STL forward_list容器成员函数

      本文链接:https://www.haomeiwen.com/subject/oibrnhtx.html