第十四周项目:程序阅读(二)
来源:互联网 发布:淘宝app首页流量 编辑:程序博客网 时间:2024/05/16 07:26
/* *Copyright(c)2016.烟台大学计算机学院 *All right reserved. *文件名称:test.cpp *作者:黄金婵 *完成日期:2016年6月19日 *版本号:v1.0 * *问题描述:阅读并运行程序,解释程序执行得到的结果 *程序输入: *程序输出: */ #include <iostream>#include <vector>using namespace std;int main(){ vector<int> intList; vector<int>::iterator listIt; int i; intList.push_back(1); intList.push_back(5); intList.push_back(10); intList.push_back(15); cout<<"Line 1: List Elements: "; for(i=0; i<4; i++) cout<<intList[i]<<" "; cout<<endl; for(i=0; i<4; i++) intList[i] *=2; cout<<"Line 2: List Elements: "; for(listIt=intList.begin(); listIt != intList.end(); ++listIt) cout<<*listIt<<" "; cout<<endl; listIt=intList.begin(); ++listIt; ++listIt; intList.insert(listIt,8); cout<<"Line 3: List Elements: "; for(listIt = intList.begin(); listIt != intList.end(); ++listIt) cout<<*listIt<<" "; cout<<endl; return 0;}
知识点总结:
所谓序列式容器,当中的元素都可序(ordered),但未必有序(sorted)。数组为C++语言内置的序列容器,STL另外提供vector、list、deque(double-ended queue)。它们的区别在于訪问元素的方式,以及加入或删除元素相关操作的执行代价。
标准库还提供了三种容器适配器(adapter),所谓适配器是依据原始的容器类型所提供的操作,通过定义新的操作接口,来适应基础的容器类型。顺序容器适配器包含stack、queue、priority_queue等序列式容器。当中stack和queue因为仅仅是将deque改头换面而成,技术上被归类为一种配接器(adapter),priority_queue是有优先级管理的队列。
0 0
- 第十四周项目:程序阅读(二)
- 第十四周项目:阅读程序(一)
- 第十四周项目:程序阅读(三)
- 第十四周 阅读程序二
- 第十四周程序阅读例二
- 第十四周项目6-阅读程序(3)
- 第十四周项目六 阅读程序(1、2、3)
- 第十四周项目六 阅读程序(4、5、6)
- 第十四周项目六 阅读程序(7、8、9)
- 第十四周项目六 阅读程序(10、11)
- 第十四周项目六 阅读程序(4)
- 第十四周项目六 阅读程序(5)
- 第十四周项目六 阅读程序(6)
- 第十四周项目六 阅读程序 (10)
- 第十四周上机实践项目1(1):阅读程序
- 第十四周上机实践项目1(2):阅读程序
- 第十四周上机实践项目1(3):阅读程序
- 第十四周项目六:阅读程序
- Mysql 基于 Amoeba 的 水平和垂直 分片
- JDBC1
- Ubuntu 14.04_64bit+Cuda 7.0配置深度学习框架caffe
- poj 1703 Find thme Catch them带权并查集
- ssl certificate
- 第十四周项目:程序阅读(二)
- msvc交叉编译:使用vcvarsall.bat设置命令行编译环境
- android-R.attr(二)
- Android 中的 Service 全面总结
- Web服务器配置
- java生成32位的UUID通用唯一识别码 (Universally Unique Identifier)
- HBase的RowKey设计原则
- 堆排序
- 使用C写Python的模块