C++的list-map链表与映射表

C++ list-map链表与映射表的简单使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值。

list 链表

链表是由节点之间通过指针连接而成的链式结构存储结构体,对于链表,C++标准库中已经提供了封装好的链表了。

require:

#include   //1.包含头文件
using namespace std;  //2.打开标准命名空间

定义链表,并在首、尾添加、删除元素

list lst;  //定义链表对象,list后<>中指定节点元素类型
lst.push_front(0);  //链表头添加
lst.push_back(1);   //链表尾添加
lst.pop_front();  //删除头节点
lst.pop_back();   //删除尾节点

迭代器遍历链表

//begin() : 返回头节点
//end()   : 返回无效的尾节点
list::iterator ite = lst.begin();  //定义迭代器指向头节点
while(ite != lst.end()) {   //不等于链表的尾节点
    cout << *ite << "  ";   //operator*
    ite++;                  

你可能感兴趣的:(C++语法,嵌入式开发应用案例,c++,list,链表)