【C++】List容器的用法解析

本文详细介绍了C++中List容器的使用方法,包括插入、删除、遍历等操作,并通过实例展示了List的运行效果,是理解C++ List容器的重要参考资料。
摘要由CSDN通过智能技术生成

#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <List>
using namespace std;

template <class T>
void printList(const list<T>& l)
{
	for (class list<T> ::const_iterator it = l.begin(); it != l.end(); it++)
	{
		cout << *it << " ";
	}
	cout << endl;
}

void test01()
{
	//list的构造函数
	//list<T> lst;            //默认构造,list采用模板类实现
	//list(begin, end);        //构造函数,利用迭代器实现区间赋值
	//list(n, elem);           //构造函数,将n个elem赋值给本身
	//list(const list & lst);  //拷贝构造

	list<int> l1;
	l1.push_back(10);
	l1.push_back(20);
	l1.push_back(30);
	l1.push_back(40);
	l1.push_back(50);

	list<int> l2(l1.begin(), l1.end());
	list<float> l3(5, 100.00f);
	list<float> l4(l3);
	
	printList(l1);
	printList(l2);
	p
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值