首页 > 其他 > 详细

list数据存取

时间:2020-06-20 18:16:03      阅读:52      评论:0      收藏:0      [点我收藏+]
#include <list>
#include <iostream>

using namespace std;

//list数据存取 
void printList(const list<int>&L){
	for (list<int>::const_iterator it = L.begin(); it != L.end(); it ++){
		cout << *it << ‘ ‘;
	}
	cout << endl;
}
void test01(){
	list<int>L1;
	
	L1.push_back(10);
	L1.push_back(20);
	L1.push_back(30);
	L1.push_back(40);
	
	//l1[0]不可以用[]方式访问list容器中的元素
	//l1.at(0) 不可以用at方式访问list容器的元素
	
	cout << "第一个元素为:" << L1.front() << endl;
	cout << "最后一个元素:" << L1.back() << endl;
	
	//迭代器不支持随机访问的。
	list<int>::iterator it = L1.begin();
	it ++;
	it --;
	//it = it + 1 //错误,不支持随机访问 
	 
}

int main(){
	test01();
	
	return 0;
}

  

list数据存取

原文:https://www.cnblogs.com/Iamcookieandyou/p/13169781.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!